From bc923ddcbcff03c20b83c93191f9546c8faba827 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Tue, 2 May 2017 20:44:52 -0400 Subject: [PATCH] Send out clock signal immediately when new clock is received via serial --- Makefile | 4 ++++ README.md | 6 +++++- src/heartbeat.c | 9 ++++++++- src/mesh_control.c | 6 ++++++ src/mesh_control.h | 4 ++++ src/scheduler.c | 1 + 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e94607c..e760138 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,10 @@ CFLAGS += -DRBC_MESH_SERIAL=1 -DBSP_SIMPLE C_SOURCE_FILES += $(RBC_MESH)/src/serial_handler_uart.c C_SOURCE_FILES += $(RBC_MESH)/src/mesh_aci.c +ifeq ($(CLOCK_MASTER), "yes") + CFLAGS += -D CLOCK_MASTER=1 +endif + ifeq ($(USE_DFU), "yes") CFLAGS += -D MESH_DFU=1 C_SOURCE_FILES += $(RBC_MESH)/src/dfu_app.c diff --git a/README.md b/README.md index 36f01b8..a790f3d 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,10 @@ 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. +Program a 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` + +Program a master clock device that doesn't sleep, listens all the time, and broadcasts its clock signal at full power. + +`make program SERIAL_PORT=/dev/cu.usbserial-AI04QL7P SENSOR_CONFIGURATION_OPTIONS="--no-sleep” TARGET_BOARD=BOARD_LESSON_TRACKER CLOCK_MASTER=yes SENSOR_ID=61` diff --git a/src/heartbeat.c b/src/heartbeat.c index c65c423..dbc5bac 100644 --- a/src/heartbeat.c +++ b/src/heartbeat.c @@ -6,6 +6,7 @@ #include "scheduler.h" #include "proximity.h" #include "app_evt.h" +#include "mesh_control.h" static tc_tx_config_t m_tx_config; @@ -13,7 +14,7 @@ void heartbeat_init(uint8_t channel) { m_tx_config.alt_access_address = false; m_tx_config.first_channel = channel; m_tx_config.channel_map = 1; - m_tx_config.tx_power = RBC_MESH_TXPOWER_Pos4dBm; + m_tx_config.tx_power = mesh_control_get_hb_tx_power(); } void send_heartbeat_packet(uint8_t sensor_id, uint32_t epoch_seconds, uint16_t epoch_ms, uint16_t clock_version) { @@ -41,6 +42,12 @@ void send_heartbeat_packet(uint8_t sensor_id, uint32_t epoch_seconds, uint16_t e p_heartbeat_ad->epoch_ms = epoch_ms; p_heartbeat_ad->clock_version = clock_version; +#ifdef CLOCK_MASTER + m_tx_config.tx_power = RBC_MESH_TXPOWER_Pos4dBm; +#else + m_tx_config.tx_power = mesh_control_get_hb_tx_power(); +#endif + if (tc_tx(p_packet, &m_tx_config) != NRF_SUCCESS) { TOGGLE_LED(LED_RED); } diff --git a/src/mesh_control.c b/src/mesh_control.c index 7c0db55..b510b81 100644 --- a/src/mesh_control.c +++ b/src/mesh_control.c @@ -1,10 +1,12 @@ #include "mesh_control.h" +#include "transport_control.h" static mesh_control_t m_config; void mesh_control_init() { m_config.wake_interval = DEFAULT_WAKE_INTERVAL; + m_config.hb_tx_power = RBC_MESH_TXPOWER_Neg4dBm; m_config.enable_ble = 0; } @@ -12,6 +14,10 @@ uint16_t mesh_control_get_wake_interval() { return m_config.wake_interval; } +uint8_t mesh_control_get_hb_tx_power() { + return m_config.hb_tx_power; +} + void mesh_control_update_config(mesh_control_t *new_config) { m_config = *new_config; } diff --git a/src/mesh_control.h b/src/mesh_control.h index 7aefa12..e6640cb 100644 --- a/src/mesh_control.h +++ b/src/mesh_control.h @@ -10,6 +10,7 @@ typedef __packed_armcc struct { uint16_t wake_interval; + uint8_t hb_tx_power; uint8_t enable_ble; // Not used yet... } __packed_gcc mesh_control_t; @@ -20,6 +21,9 @@ void mesh_control_init(); // current_epoch % wake_interval == 0 indicates the start of a wake period uint16_t mesh_control_get_wake_interval(); +// Heartbeat tx power controls the tx power level of sent heartbeat packets +uint8_t mesh_control_get_hb_tx_power(); + void mesh_control_update_config(mesh_control_t *new_config); #endif // MESH_CONTROL_H diff --git a/src/scheduler.c b/src/scheduler.c index 300f7de..15639ae 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -182,6 +182,7 @@ void set_clock_time(int32_t epoch, uint16_t ms, clock_source_t clock_source, int } } else if (clock_source == CLOCK_SOURCE_SERIAL) { m_clock_version++; + send_heartbeat_packet(get_sensor_id(), epoch, ms, m_clock_version); } TOGGLE_LED(LED_BLUE); m_boot_time += epoch - m_current_time;