aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md19
-rw-r--r--app.cpp22
-rw-r--r--config.h1
-rw-r--r--trygvisio_soil_moisture.ino15
4 files changed, 33 insertions, 24 deletions
diff --git a/README.md b/README.md
index 0acd4b6..e4031d5 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,21 @@
Build instructions
------------------
-Check out this repository under your sketchbook (normally ~/sketchbook).
+I try to keep up with the latest Arduino IDE releases. These notes was updated when 1.6.5 was current.
-Check out the BLE library from Nordic under $SKETCHBOOK/libraries:
+Check out this repository under your sketchbook (normally ~/Arduino).
- cd ~/sketchbook/libraries
- git clone https://github.com/NordicSemiconductor/ble-sdk-arduino BLE
+Check out the BLE library from Nordic:
-I've mainly used revision `a5c325c329e134fa26fc6d0e3fe484b1a9488567` to build.
+ cd ~/sketchbook
+ git clone https://github.com/cheong2k/ble-sdk-arduino libraries/BLE
- cd ~/sketchbook/hardware
+HEAD was revision `577a652c4250b0494a826d7b2c0a2d165e2f5d42` at the time of writing.
+
+Check out the RedBearLab hardware library
+
+ cd ~/sketchbook
git clone https://github.com/RedBearLab/Blend
+ ln -s Blend/Arduino/hardware/blend hardware/blend
-I've mainly used revision `09c7d3e702aa5899de80412a707a44dfcd616a89` to build.
+HEAD was revision `1f06450c95dc4ddb4499a07d84618f8362d5a74b` at the time of writing.
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) {
diff --git a/config.h b/config.h
index e8b9ef1..6ad7fb6 100644
--- a/config.h
+++ b/config.h
@@ -39,6 +39,7 @@ values are commented out, but some have default values
//
// Default: not set, you have to set it
// #define SM_BOARD_VERSION ...
+#define SM_BOARD_VERSION 2
// If enabled the code won't start until you open the serial port
// monitor or otherwise connect to the serial port.
diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino
index 621a64d..e524f71 100644
--- a/trygvisio_soil_moisture.ino
+++ b/trygvisio_soil_moisture.ino
@@ -2,26 +2,27 @@
#include <SPI.h>
#include <lib_aci.h>
#include <aci_setup.h>
+#include <avr/sleep.h>
// See config.h on how to configure the sketch
#include "config.h"
#include "services.h"
#include "app.h"
-static services_pipe_type_mapping_t services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
-static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] PROGMEM = SETUP_MESSAGES_CONTENT;
+static void setup_rf();
+static void show_pipes();
-static struct aci_state_t aci_state;
-static hal_aci_evt_t aci_data;
-static boolean timing_change_done = false;
+static services_pipe_type_mapping_t services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
+static const hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] PROGMEM = SETUP_MESSAGES_CONTENT;
static const uint8_t pipe_set = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_SET;
static const uint8_t pipe_tx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_TX;
static const uint8_t pipe_rx = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO;
static const uint8_t pipe_rx_max_size = PIPE_SOIL_MOISTURE_SOIL_MOISTURE_CONTROL_RX_ACK_AUTO_MAX_SIZE;
-static void setup_rf();
-static void show_pipes();
+static struct aci_state_t aci_state;
+static hal_aci_evt_t aci_data;
+static boolean timing_change_done = false;
void __ble_assert(const char *file, uint16_t line)
{