Skip to content

Commit

Permalink
Utilities for programming, get rid of ghost proximity values, more co…
Browse files Browse the repository at this point in the history
…nfig support for channels other than 38, but that is still not working
  • Loading branch information
ps2 committed Apr 27, 2017
1 parent 6e442e3 commit 59f1abb
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ RBC_MESH := rbc_mesh

LINKER_SCRIPT := $(SIMBLEE_BASE)/variants/Simblee/linker_scripts/gcc/Simblee.ld
RFD_LOADER := $(SIMBLEE_BASE)/RFDLoader_osx
#SERIAL_PORT := /dev/cu.usbserial-DN00D34P # left
SERIAL_PORT := /dev/cu.usbserial-DN00CSZ7 # right
SERIAL_PORT := /dev/cu.usbserial-DN00D34P # left
#SERIAL_PORT := /dev/cu.usbserial-DN00CSZ7 # right
#SERIAL_PORT := /dev/cu.usbserial-A105RB12
#SERIAL_PORT := /dev/cu.usbserial-FTZ86FTC # tag-connect
#SERIAL_PORT := /dev/cu.usbserial-DO00C2G2 # Breadboard setup
Expand Down
34 changes: 34 additions & 0 deletions pyaci/configure_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3

from argparse import ArgumentParser
from aci import AciCommand
from aci_serial import AciUart
import time
import sensei_cmd

def configure_sensor(serial_device, sensor_id, serial_enabled, channel, sleep_enabled):
aci = AciUart.AciUart(port=serial_device, baudrate=115200)
# Wait for serial connection to be ready
time.sleep(2)
cmd = sensei_cmd.SetConfig(sensor_id, serial_enabled, channel, sleep_enabled)
data = cmd.serialize()
aci.write_aci_cmd(AciCommand.AciAppCommand(data=data,length=len(data)+1))

# Wait for flash to be written
time.sleep(2)
aci.write_aci_cmd(AciCommand.AciRadioReset())

aci.stop()

if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("-d", "--device", dest="device", required=True, help="Serial device, e.g. /dev/cu.usbserial-DO00C2G2")
parser.add_argument('id', type=int, help='the id to assign this sensor')
parser.add_argument('--no-sleeping', dest='sleep_enabled', action='store_false')
parser.set_defaults(sleep_enabled=True)
parser.add_argument('--no-serial', dest='serial_enabled', action='store_false')
parser.set_defaults(serial_enabled=True)
parser.add_argument('--channel', type=int, help='bluetooth channel of sensei network: should be 1-39 (one of 37,38,39 usually best)')
parser.set_defaults(channel=38)
options = parser.parse_args()
configure_sensor(options.device, options.id, options.serial_enabled, options.channel, options.sleep_enabled)
2 changes: 2 additions & 0 deletions pyaci/interactive_console.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import logging
import IPython
from argparse import ArgumentParser
Expand Down
23 changes: 23 additions & 0 deletions pyaci/listen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3

from argparse import ArgumentParser
from aci import AciCommand
from aci_serial import AciUart
import time
import sensei_cmd

def listen(serial_device):
aci = AciUart.AciUart(port=serial_device, baudrate=115200)
# Wait for serial connection to be ready
time.sleep(2)
while True:
try:
print(aci.events_queue.popleft())
except IndexError:
break

if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("-d", "--device", dest="device", required=True, help="Serial device, e.g. /dev/cu.usbserial-DO00C2G2")
options = parser.parse_args()
listen(options.device)
22 changes: 22 additions & 0 deletions pyaci/set_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3

from argparse import ArgumentParser
from aci import AciCommand
from aci_serial import AciUart
import time
import sensei_cmd

def set_time(serial_device):
aci = AciUart.AciUart(port=serial_device, baudrate=115200)
# Wait for serial connection to be ready
time.sleep(2)
cmd = sensei_cmd.SetTime()
data = cmd.serialize()
aci.write_aci_cmd(AciCommand.AciAppCommand(data=data,length=len(data)+1))
aci.stop()

if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("-d", "--device", dest="device", required=True, help="Serial device, e.g. /dev/cu.usbserial-DO00C2G2")
options = parser.parse_args()
set_time(options.device)
1 change: 0 additions & 1 deletion rbc_mesh/src/rbc_mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "mesh_gatt.h"
#include "dfu_app.h"
#include "fifo.h"
#include "leds.h"

#include "app_error.h"
#include "nrf_sdm.h"
Expand Down
1 change: 0 additions & 1 deletion rbc_mesh/src/timeslot.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "transport_control.h"
#include "event_handler.h"
#include "rbc_mesh_common.h"
#include "leds.h"

#ifdef MESH_DFU
#include "dfu_app.h"
Expand Down
15 changes: 15 additions & 0 deletions reprog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

CHANNEL=38

make || exit -1

(make install SERIAL_PORT=/dev/cu.usbserial-DN00D34P && ./pyaci/configure_sensor.py --channel $CHANNEL -d /dev/cu.usbserial-DN00D34P 1) &

(make install SERIAL_PORT=/dev/cu.usbserial-DN00CSZ7 && ./pyaci/configure_sensor.py --channel $CHANNEL -d /dev/cu.usbserial-DN00CSZ7 2) &

(make install SERIAL_PORT=/dev/cu.usbserial-DO00C2G2 && ./pyaci/configure_sensor.py --channel $CHANNEL --no-sleeping -d /dev/cu.usbserial-DO00C2G2 3) &

wait

./pyaci/set_time.py -d /dev/cu.usbserial-DO00C2G2
6 changes: 3 additions & 3 deletions src/heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

static tc_tx_config_t m_tx_config;

void heartbeat_init() {
void heartbeat_init(uint8_t channel) {
m_tx_config.alt_access_address = false;
m_tx_config.first_channel = 38;
m_tx_config.first_channel = channel;
m_tx_config.channel_map = 1;
m_tx_config.tx_power = RBC_MESH_TXPOWER_0dBm;
}

void send_heartbeat_packet(uint8_t sensor_id, uint32_t epoch_seconds, uint16_t epoch_ms, uint16_t clock_version) {
// Send out time sync packet
//TOGGLE_PIN(LED_RED + LED_START);

mesh_packet_t *p_packet;
if (mesh_packet_acquire(&p_packet)) {
Expand Down Expand Up @@ -51,7 +52,6 @@ void send_heartbeat_packet(uint8_t sensor_id, uint32_t epoch_seconds, uint16_t e

void received_heartbeat(heartbeat_ad_t *p_heartbeat_ad, uint8_t rssi) {
app_evt_t event;
TOGGLE_PIN(6);
set_clock_time(p_heartbeat_ad->epoch_seconds, p_heartbeat_ad->epoch_ms, CLOCK_SOURCE_RF, p_heartbeat_ad->clock_version);
proximity_add_entry(p_heartbeat_ad->sensor_id, rssi);

Expand Down
2 changes: 1 addition & 1 deletion src/heartbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef __packed_armcc struct
} __packed_gcc heartbeat_ad_t;


void heartbeat_init();
void heartbeat_init(uint8_t channel);
void send_heartbeat_packet(uint8_t sensor_id, uint32_t epoch_seconds, uint16_t current_ms, uint16_t clock_version);
void received_heartbeat(heartbeat_ad_t *p_heartbeat_ad, uint8_t rssi);

Expand Down
4 changes: 2 additions & 2 deletions src/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#define CLEAR_PIN(x) NRF_GPIO->OUTCLR = (1 << (x))

#define TOGGLE_PIN(x) do { uint32_t gpio_state = NRF_GPIO->OUT; \
NRF_GPIO->OUTSET = ((1<<x) & ~gpio_state); \
NRF_GPIO->OUTCLR = ((1<<x) & gpio_state); } while (0)
NRF_GPIO->OUTSET = ((1<<(x)) & ~gpio_state); \
NRF_GPIO->OUTCLR = ((1<<(x)) & gpio_state); } while (0)


#ifdef __cplusplus
Expand Down
14 changes: 7 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#define MESH_ACCESS_ADDR (0xA555410C)
#define MESH_INTERVAL_MIN_MS (100)
#define MESH_CHANNEL (38)
#define DEFAULT_MESH_CHANNEL (38)
#define MESH_CLOCK_SRC (NRF_CLOCK_LFCLKSRC_XTAL_75_PPM)

/** @brief General error handler. */
Expand Down Expand Up @@ -70,7 +70,7 @@ static void rbc_mesh_event_handler(rbc_mesh_event_t* p_evt)
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]);
//led_config(LED_BLUE, p_evt->params.rx.p_data[0]);
}
break;
case RBC_MESH_EVENT_TYPE_TX:
Expand Down Expand Up @@ -142,14 +142,14 @@ int main(void)
rbc_mesh_init_params_t init_params;
init_params.access_addr = MESH_ACCESS_ADDR;
init_params.interval_min_ms = MESH_INTERVAL_MIN_MS;
init_params.channel = MESH_CHANNEL;
init_params.channel = DEFAULT_MESH_CHANNEL;
init_params.lfclksrc = MESH_CLOCK_SRC;
init_params.tx_power = RBC_MESH_TXPOWER_0dBm;

uint32_t error_code;
error_code = rbc_mesh_init(init_params);
APP_ERROR_CHECK(error_code);
led_config(LED_GREEN, 1);
//led_config(LED_GREEN, 1);

// Setup handler for watching for heartbeat messages
rbc_mesh_packet_peek_cb_set(packet_peek_cb);
Expand All @@ -161,13 +161,13 @@ int main(void)
get_config(&app_config);

// Change channel if needed
if (app_config.mesh_channel != 38) {
if (app_config.mesh_channel != DEFAULT_MESH_CHANNEL) {
tc_radio_params_set(MESH_ACCESS_ADDR, app_config.mesh_channel);
}

scheduler_init(app_config.sleep_enabled); // Initializes, but does not start, clock

heartbeat_init(); // Inits structures for sending heartbeat
heartbeat_init(app_config.mesh_channel); // Inits structures for sending heartbeat

/* Initialize serial ACI */
if (app_config.serial_enabled) {
Expand Down Expand Up @@ -200,7 +200,7 @@ int main(void)
uint32_t led_status = !!((pin - BUTTON_START) & 0x01); /* even buttons are OFF, odd buttons are ON */

mesh_data[0] = led_status;
led_config(LED_BLUE, led_status);
//led_config(LED_BLUE, led_status);
error_code = rbc_mesh_value_set(TEST_LED_HANDLE, mesh_data, 1);
APP_ERROR_CHECK(error_code);
}
Expand Down
7 changes: 3 additions & 4 deletions src/proximity.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "proximity.h"
#include <string.h>
#include "leds.h"

static uint8_t rssi_sorted[MAX_PROXIMITY_TRACKING_COUNT];
static uint8_t sensor_ids_sorted[MAX_PROXIMITY_TRACKING_COUNT];
Expand All @@ -24,13 +25,11 @@ void proximity_add_entry(uint8_t sensor_id, uint8_t rssi) {
void proximity_values_reset() {
memset(rssi_sorted, 0, sizeof(uint8_t) * MAX_PROXIMITY_TRACKING_COUNT);
memset(sensor_ids_sorted, 0, sizeof(uint8_t) * MAX_PROXIMITY_TRACKING_COUNT);
rssi_sorted[4] = sizeof(uint8_t) * MAX_PROXIMITY_TRACKING_COUNT;
}

uint8_t proximity_get_strongest_signals(uint8_t *sensor_ids, uint8_t *rssi_values, uint8_t output_array_size) {
uint8_t n = 0;
while(n<MAX_PROXIMITY_TRACKING_COUNT && n<output_array_size && rssi_sorted[n] > 0) {
n++;
}
uint8_t n = MAX_PROXIMITY_TRACKING_COUNT > output_array_size ? output_array_size : MAX_PROXIMITY_TRACKING_COUNT;
memcpy(sensor_ids, sensor_ids_sorted, sizeof(uint8_t) * n);
memcpy(rssi_values, rssi_sorted, sizeof(uint8_t) * n);
return n;
Expand Down
1 change: 1 addition & 0 deletions src/proximity.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ void proximity_values_reset();
// count = length of sensor_ids and rssi_values arrays
uint8_t proximity_get_strongest_signals(uint8_t *sensor_ids, uint8_t *rssi_values, uint8_t output_array_size);


#endif //PROXIMITY_H
11 changes: 6 additions & 5 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ static void periodic_timer_cb(void * p_context)
DBG_TICK_PIN(6);


if (m_current_time % 10 == 0) {
if (1 /*m_current_time % 10 == 0*/) {
//report_debug_register();
led_config(LED_GREEN, 1);
//led_config(LED_GREEN, 1);
app_timer_cnt_get(&m_clock_second_start_counter_value);
m_scheduler_state = SCHEDULER_STATE_BEFORE_HB;
rbc_mesh_start();

toggle_led(LED_RED);
delay_to_heartbeat();
}
}
Expand All @@ -78,7 +77,7 @@ static void delay_to_heartbeat() {
}

static void do_heartbeat() {
toggle_led(LED_RED);
//led_config(LED_GREEN, 0);
uint32_t current_counter;
app_timer_cnt_get(&current_counter);
// Modulo wraparound makes this ok
Expand All @@ -95,6 +94,7 @@ static void delay_to_reporting() {
}

static void do_reporting() {
//led_config(LED_GREEN, 1);
report_sensor_data();
}

Expand All @@ -112,7 +112,7 @@ static void delay_to_sleep() {

static void do_sleep() {
rbc_mesh_stop();
led_config(LED_GREEN, 0);
//led_config(LED_GREEN, 0);
}

static void offset_timer_cb(void * p_context) {
Expand Down Expand Up @@ -184,6 +184,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++;
}
TOGGLE_PIN(LED_BLUE + LED_START);
m_boot_time += epoch - m_current_time;
m_last_sync = m_current_time = epoch;
uint16_t start_delay = (1000 - ms) % 1000;
Expand Down
1 change: 1 addition & 0 deletions src/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void sensor_warmup_event() {
void gather_sensor_data() {
m_value.uptime = get_uptime();
m_value.battery = get_battery_adc();
//m_value.status = ??

read_shoe_accel(&m_value.accel_x, &m_value.accel_y, &m_value.accel_z);

Expand Down

0 comments on commit 59f1abb

Please sign in to comment.