aboutsummaryrefslogtreecommitdiff
path: root/app.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-06 22:38:41 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-06 22:38:41 +0200
commita3c966300ce48b3ba758170238d4a44ba0c7fecb (patch)
tree0b7edefe2b6ff7b261b31a2f86376036aff1b22a /app.cpp
parent2f5b20158b811d9ad6e4726d13a7fcc3b7ed961e (diff)
downloadtrygvisio_soil_moisture-a3c966300ce48b3ba758170238d4a44ba0c7fecb.tar.gz
trygvisio_soil_moisture-a3c966300ce48b3ba758170238d4a44ba0c7fecb.tar.bz2
trygvisio_soil_moisture-a3c966300ce48b3ba758170238d4a44ba0c7fecb.tar.xz
trygvisio_soil_moisture-a3c966300ce48b3ba758170238d4a44ba0c7fecb.zip
o Migrating to Arduino 1.6
Diffstat (limited to 'app.cpp')
-rw-r--r--app.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/app.cpp b/app.cpp
index 825b606..cadcc30 100644
--- a/app.cpp
+++ b/app.cpp
@@ -10,10 +10,6 @@
#error "SM_BOARD_VERSION must be set. See config.h"
#endif
-// http://bleaklow.com/2010/09/05/progmem_and_gcc_bug_34734.html
-#undef PROGMEM
-#define PROGMEM __attribute__((section(".progmem.data")))
-
#define LED_PIN 13
#define EEPROM_MAGIC 0xa5
@@ -249,6 +245,10 @@ void write_res(struct sm_res const& res) {
}
#endif // SM_DEBUG
+static inline bool len_ok(uint8_t sizeof_packet, uint8_t sizeof_struct) {
+ return sizeof_packet >= sizeof_struct;
+}
+
void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
struct sm_req *req = (struct sm_req *) data;
struct sm_res res;
@@ -258,9 +258,16 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
write_req(*req);
#endif
+ if (len <= 1) {
+ return;
+ }
+
res.code = req->code;
- uint8_t body_len;
+ uint8_t body_len = 0;
+ res.code = SM_CMD_FAIL;
+
+ // TODO: use len_op(len, sizeof(sm_XX_req)) to check that each request's size is ok.
switch(req->code) {
case SM_CMD_GET_SENSOR_COUNT:
body_len = sizeof(sm_get_sensor_count_res);
@@ -335,11 +342,6 @@ void on_soil_moisture_ctrl(uint8_t *data, uint8_t len) {
res.code = SM_CMD_FAIL;
}
break;
-
- default:
- body_len = 0;
- res.code = SM_CMD_FAIL;
- break;
}
if (res.code == SM_CMD_FAIL) {