Skip to content

Commit

Permalink
Adding new module for handling app commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed Apr 12, 2017
1 parent 4d51861 commit 0026999
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rbc_mesh/include/mesh_aci.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
3 changes: 1 addition & 2 deletions rbc_mesh/include/serial_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rbc_mesh/src/mesh_aci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions src/app_cmd.c
Original file line number Diff line number Diff line change
@@ -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;
}
30 changes: 30 additions & 0 deletions src/app_cmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef APP_CMD_H
#define APP_CMD_H

#include <stdint.h>
#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
8 changes: 1 addition & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdbool.h>
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 0026999

Please sign in to comment.