From a3c966300ce48b3ba758170238d4a44ba0c7fecb Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 6 Jul 2015 22:38:41 +0200 Subject: o Migrating to Arduino 1.6 --- app.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'app.cpp') 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) { -- cgit v1.2.3