Skip to content

Commit

Permalink
Send out clock signal immediately when new clock is received via serial
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed May 3, 2017
1 parent 8be911d commit bc923dd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
9 changes: 8 additions & 1 deletion src/heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#include "scheduler.h"
#include "proximity.h"
#include "app_evt.h"
#include "mesh_control.h"

static tc_tx_config_t m_tx_config;

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) {
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions src/mesh_control.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@

#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;
}

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;
}
4 changes: 4 additions & 0 deletions src/mesh_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
1 change: 1 addition & 0 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bc923dd

Please sign in to comment.