From 0026999ed4fbd7a80c63292831ae24a46695e050 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Wed, 12 Apr 2017 12:56:03 -0500 Subject: [PATCH] Adding new module for handling app commands --- Makefile | 2 +- rbc_mesh/include/mesh_aci.h | 2 +- rbc_mesh/include/serial_command.h | 3 +-- rbc_mesh/src/mesh_aci.c | 2 +- src/app_cmd.c | 11 +++++++++++ src/app_cmd.h | 30 ++++++++++++++++++++++++++++++ src/main.c | 8 +------- 7 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 src/app_cmd.c create mode 100644 src/app_cmd.h diff --git a/Makefile b/Makefile index e633d95..b5ebb54 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou # source common to all targets -C_SOURCE_FILES += src/main.c src/leds.c src/config.c src/sensor.c +C_SOURCE_FILES += src/main.c src/leds.c src/config.c src/sensor.c src/app_cmd.c C_SOURCE_FILES += $(COMPONENTS)/libraries/timer/app_timer.c CXX_SOURCE_FILES += $(SIMBLEE_BASE)/libraries/SimbleeBLE/SimbleeBLE.cpp diff --git a/rbc_mesh/include/mesh_aci.h b/rbc_mesh/include/mesh_aci.h index 05d29c8..869b60b 100644 --- a/rbc_mesh/include/mesh_aci.h +++ b/rbc_mesh/include/mesh_aci.h @@ -72,7 +72,7 @@ void mesh_aci_command_check(void); void mesh_aci_rbc_event_handler(rbc_mesh_event_t* p_evt); /** Set app command handler */ -typedef uint16_t (*app_cmd_handler_t) (uint8_t cmd_opcode, uint8_t *data, uint8_t *response, uint16_t *response_length); +typedef uint16_t (*app_cmd_handler_t) (uint8_t *data, uint16_t length, uint8_t *response, uint16_t *response_length); void mesh_aci_app_cmd_handler_set(app_cmd_handler_t app_cmd_handler); #endif /* _MESH_ACI_H__ */ diff --git a/rbc_mesh/include/serial_command.h b/rbc_mesh/include/serial_command.h index 9781345..3e98c40 100644 --- a/rbc_mesh/include/serial_command.h +++ b/rbc_mesh/include/serial_command.h @@ -115,8 +115,7 @@ typedef __packed_armcc struct typedef __packed_armcc struct { - uint8_t app_cmd_opcode; - uint8_t data[28]; + uint8_t data[29]; } __packed_gcc serial_cmd_params_app_cmd_t; typedef __packed_armcc struct diff --git a/rbc_mesh/src/mesh_aci.c b/rbc_mesh/src/mesh_aci.c index 0042df8..c600799 100644 --- a/rbc_mesh/src/mesh_aci.c +++ b/rbc_mesh/src/mesh_aci.c @@ -536,8 +536,8 @@ static void serial_command_handler(serial_cmd_t* p_serial_cmd) if (app_cmd_handler_cb) { error_code = app_cmd_handler_cb( - p_serial_cmd->params.app_cmd.app_cmd_opcode, p_serial_cmd->params.app_cmd.data, + p_serial_cmd->length - SERIAL_PACKET_OVERHEAD, serial_evt.params.cmd_rsp.response.app_cmd.data, (uint16_t*) &serial_evt.length); } else { diff --git a/src/app_cmd.c b/src/app_cmd.c new file mode 100644 index 0000000..059f577 --- /dev/null +++ b/src/app_cmd.c @@ -0,0 +1,11 @@ + +#include "app_cmd.h" +#include "nrf_error.h" +#include "leds.h" + +uint16_t app_cmd_handler(uint8_t *data, uint16_t len, uint8_t *response, uint16_t *response_length) { + toggle_led(LED_RED); + data[0] = 0xfa; + *response_length = 1; + return NRF_SUCCESS; +} diff --git a/src/app_cmd.h b/src/app_cmd.h new file mode 100644 index 0000000..c2953c0 --- /dev/null +++ b/src/app_cmd.h @@ -0,0 +1,30 @@ +#ifndef APP_CMD_H +#define APP_CMD_H + +#include +#include "toolchain.h" + +typedef enum +{ + APP_CMD_OPCODE_SET_TIME = 0x02, +} app_cmd_opcode_t; + +typedef __packed_armcc struct +{ + uint8_t epoch[4]; +} __packed_gcc app_cmd_params_set_time_t; + + +typedef __packed_armcc struct +{ + app_cmd_opcode_t opcode; + __packed_armcc union + { + app_cmd_params_set_time_t set_time; + } __packed_gcc params; +} __packed_gcc app_cmd_t; + + +uint16_t app_cmd_handler(uint8_t *data, uint16_t len, uint8_t *response, uint16_t *response_length); + +#endif // APP_CMD_H diff --git a/src/main.c b/src/main.c index 91a7925..45f235c 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "leds.h" #include "app_timer.h" #include "pstorage_platform.h" +#include "app_cmd.h" #include "config.h" #include "sensor.h" #include @@ -144,13 +145,6 @@ void clock_initialization() } } -uint16_t app_cmd_handler(uint8_t cmd_opcode, uint8_t *data, uint8_t *response, uint16_t *response_length) { - toggle_led(LED_RED); - data[0] = 0xfa; - *response_length = 1; - return NRF_SUCCESS; -} - int main(void) {