Skip to content

Commit

Permalink
Adding mesh_control; new handle to mesh params that may be updated OTA
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed May 2, 2017
1 parent 3c89496 commit 8be911d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou

C_SOURCE_FILES += src/main.c src/config.c src/sensor.c src/app_cmd.c \
src/scheduler.c src/proximity.c src/heartbeat.c src/battery.c src/shoe_accel.c \
src/app_evt.c bsp/bsp.c
src/app_evt.c src/mesh_control.c bsp/bsp.c
C_SOURCE_FILES += $(COMPONENTS)/libraries/timer/app_timer.c

CXX_SOURCE_FILES += $(SIMBLEE_BASE)/libraries/SimbleeBLE/SimbleeBLE.cpp
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Program a shoe sensor with id 1, turning off serial for power savings

`make program SERIAL_PORT=/dev/cu.usbserial-FTZ86FTC SENSOR_CONFIGURATION_OPTIONS="--no-serial" TARGET_BOARD=BOARD_SHOE_SENSOR SENSOR_ID=1`

Program an area sensor with id 3, turning off serial for power savings:

`make program SERIAL_PORT=/dev/cu.usbserial-AI04QL7P SENSOR_CONFIGURATION_OPTIONS="--no-serial" TARGET_BOARD=BOARD_LESSON_TRACKER SENSOR_ID=3`

Program a master listening device that doesn't sleep, and listens all the time.

`make program SERIAL_PORT=/dev/cu.usbserial-DN00CSZ7 SENSOR_CONFIGURATION_OPTIONS="--no-sleep” TARGET_BOARD=BOARD_RFD77201 SENSOR_ID=51`
6 changes: 6 additions & 0 deletions pyaci/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Uploader(object):
# Synchronize once every minute
TIME_SYNC_INTERVAL=60

MESH_HANDLE_MESH_CONTROL = 0x0201

def __init__(self, sensei_config):
api_url = sensei_config["server"]["url"] + 'api/v1/'
self.api = Api(api_url, sensei_config["server"]["username"], sensei_config["server"]["password"])
Expand Down Expand Up @@ -45,6 +47,10 @@ def sync_time(self):
def get_config(self):
return self.run_app_command(sensei_cmd.GetConfig())

def set_mesh_control(self, wake_interval):
data = struct.pack("<HB", wake_interval, 0)
self.aci.ValueSet(MESH_HANDLE_MESH_CONTROL, data)

def radio_obs_from_update(self, update):
if not update.is_valid:
return []
Expand Down
1 change: 1 addition & 0 deletions src/handles.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MESH_HANDLES_H

#define SENSOR_HANDLE (0x0100 + get_sensor_id())
#define MESH_CONTROL_HANDLE (0x0201)
#define TEST_LED_HANDLE (0xfe01)
#define DEBUG_REGISTER_HANDLE (0x1234)

Expand Down
12 changes: 9 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "heartbeat.h"
#include "handles.h"
#include "bsp.h"
#include "mesh_control.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -70,8 +71,8 @@ static void rbc_mesh_event_handler(rbc_mesh_event_t* p_evt)
case RBC_MESH_EVENT_TYPE_CONFLICTING_VAL:
case RBC_MESH_EVENT_TYPE_NEW_VAL:
case RBC_MESH_EVENT_TYPE_UPDATE_VAL:
if (p_evt->params.rx.value_handle == TEST_LED_HANDLE) {
//led_config(LED_BLUE, p_evt->params.rx.p_data[0]);
if (p_evt->params.rx.value_handle == MESH_CONTROL_HANDLE) {
mesh_control_update_config((mesh_control_t*)p_evt->params.rx.p_data);
}
break;
case RBC_MESH_EVENT_TYPE_TX:
Expand Down Expand Up @@ -120,6 +121,8 @@ int main(void)

bsp_init(BSP_INIT_BUTTONS & BSP_INIT_LED, 0, 0);

mesh_control_init();

/* Enable Softdevice (including sd_ble before framework */
SOFTDEVICE_HANDLER_INIT(MESH_CLOCK_SRC, NULL);
softdevice_ble_evt_handler_set(rbc_mesh_ble_evt_handler);
Expand Down Expand Up @@ -189,9 +192,12 @@ int main(void)
sensor_init();
}

error_code = rbc_mesh_value_enable(TEST_LED_HANDLE);
error_code = rbc_mesh_value_enable(MESH_CONTROL_HANDLE);
APP_ERROR_CHECK(error_code);

// error_code = rbc_mesh_value_enable(TEST_LED_HANDLE);
// APP_ERROR_CHECK(error_code);

// Start clock
start_clock(0);

Expand Down
17 changes: 17 additions & 0 deletions src/mesh_control.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#include "mesh_control.h"

static mesh_control_t m_config;

void mesh_control_init() {
m_config.wake_interval = DEFAULT_WAKE_INTERVAL;
m_config.enable_ble = 0;
}

uint16_t mesh_control_get_wake_interval() {
return m_config.wake_interval;
}

void mesh_control_update_config(mesh_control_t *new_config) {
m_config = *new_config;
}
25 changes: 25 additions & 0 deletions src/mesh_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef MESH_CONTROL_H
#define MESH_CONTROL_H

#include <stdint.h>
#include "toolchain.h"

// Default wake interval is 10 seconds
#define DEFAULT_WAKE_INTERVAL (10)

typedef __packed_armcc struct
{
uint16_t wake_interval;
uint8_t enable_ble; // Not used yet...
} __packed_gcc mesh_control_t;


void mesh_control_init();

// Wake interval controls the cycle of waking and sleeping
// current_epoch % wake_interval == 0 indicates the start of a wake period
uint16_t mesh_control_get_wake_interval();

void mesh_control_update_config(mesh_control_t *new_config);

#endif // MESH_CONTROL_H
7 changes: 3 additions & 4 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "sensor.h"
#include "rbc_mesh.h"
#include "handles.h"
#include "mesh_control.h"

// Timer settings
#define APP_TIMER_PRESCALER 15 // divisor value - 1
Expand Down Expand Up @@ -52,8 +53,7 @@ static void periodic_timer_cb(void * p_context)
m_current_time += 1;
DBG_TICK_PIN(6);


if (m_current_time % 10 == 0) {
if (m_current_time % mesh_control_get_wake_interval() == 0) {
//report_debug_register();
SET_LED(LED_GREEN);
app_timer_cnt_get(&m_clock_second_start_counter_value);
Expand Down Expand Up @@ -210,7 +210,6 @@ uint16_t get_clock_version() {
return m_clock_version;
}


bool clock_is_synchronized() {
return m_last_sync > 0 && (m_current_time - m_last_sync) < (60 * 60);
return m_last_sync > 0; // && (m_current_time - m_last_sync) < (60 * 60);
}

0 comments on commit 8be911d

Please sign in to comment.