summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.cpp41
-rw-r--r--app.h15
-rw-r--r--fiken_status_panel.ino111
-rw-r--r--fiken_status_panel.xml18
-rw-r--r--services.h51
5 files changed, 190 insertions, 46 deletions
diff --git a/app.cpp b/app.cpp
new file mode 100644
index 0000000..8163ad8
--- /dev/null
+++ b/app.cpp
@@ -0,0 +1,41 @@
+#include "app.h"
+
+#include <HardwareSerial.h>
+
+// http://bleaklow.com/2010/09/05/progmem_and_gcc_bug_34734.html
+#undef PROGMEM
+#define PROGMEM __attribute__((section(".progmem.data")))
+
+#define GAUGE_COUNT 4
+
+// See http://redbearlab.com/blendmicro/
+int gauge_pins[GAUGE_COUNT] = {
+ 9, 10, 11, 13
+};
+
+void on_gauge_data(uint8_t *data, uint8_t len) {
+ Serial.print(F("on_gauge_data, channel="));
+ Serial.print(data[0], HEX);
+ Serial.print(F(", data[1]="));
+ Serial.println(data[1], HEX);
+}
+
+void on_gauge_ctrl(uint8_t *data, uint8_t len) {
+ Serial.print(F("on_gauge_data, data[0]="));
+ Serial.print(data[0], HEX);
+ Serial.print(F(", data[1]="));
+ Serial.println(data[1], HEX);
+
+ uint8_t res[2];
+
+ switch(data[0]) {
+ case FSP_CMD_GAUGE_COUNT:
+ res[0] = FSP_CMD_GAUGE_COUNT;
+ res[1] = GAUGE_COUNT;
+ send_ctrl(res, 2);
+ break;
+ default:
+ break;
+ }
+}
+
diff --git a/app.h b/app.h
new file mode 100644
index 0000000..e892a42
--- /dev/null
+++ b/app.h
@@ -0,0 +1,15 @@
+#ifndef APP_H
+#define APP_H
+
+#include <stdint.h>
+
+#define FSP_CMD_GAUGE_COUNT 1
+#define FSP_CMD_GAUGE_INFO 2
+
+bool send_ctrl(uint8_t *data, uint8_t len);
+
+void on_gauge_data(uint8_t *data, uint8_t len);
+void on_gauge_ctrl(uint8_t *data, uint8_t len);
+
+#endif
+
diff --git a/fiken_status_panel.ino b/fiken_status_panel.ino
index 22f7f4a..35b3d40 100644
--- a/fiken_status_panel.ino
+++ b/fiken_status_panel.ino
@@ -1,8 +1,10 @@
#include <SPI.h>
+#include <Watchdog.h>
#include <lib_aci.h>
#include <aci_setup.h>
#include "services.h"
+#include "app.h"
static services_pipe_type_mapping_t services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] PROGMEM = SETUP_MESSAGES_CONTENT;
@@ -40,6 +42,8 @@ void setup() {
#if defined (__AVR_ATmega32U4__)
while(!Serial) {
}
+
+ delay(1000);
#elif defined(__PIC32MX__)
delay(1000);
#endif
@@ -84,9 +88,12 @@ void setup() {
Serial.println(F("lib_aci_init done"));
}
+static bool rf_started = false;
static bool setup_required = false;
static void aci_loop() {
+ uint8_t pipe_number;
+
// We enter the if statement only when there is a ACI event available to be processed
if (lib_aci_event_get(&aci_state, &aci_data)) {
aci_evt_t * aci_evt;
@@ -96,9 +103,14 @@ static void aci_loop() {
case ACI_EVT_DEVICE_STARTED:
Serial.println(F("ACI_EVT_DEVICE_STARTED"));
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
+
+ Serial.print(F("aci_state.data_credit_total="));
+ Serial.println(aci_state.data_credit_total, DEC);
+
switch(aci_evt->params.device_started.device_mode) {
case ACI_DEVICE_SETUP:
Serial.println(F("ACI_DEVICE_SETUP"));
+ rf_started = true;
setup_required = true;
break;
@@ -149,6 +161,8 @@ static void aci_loop() {
Serial.println(F("ACI_EVT_CONNECTED"));
timing_change_done = false;
aci_state.data_credit_available = aci_state.data_credit_total;
+ Serial.print(F("aci_state.data_credit_available="));
+ Serial.println(aci_state.data_credit_available, DEC);
// Get the device version of the nRF8001 and store it in the Hardware Revision String.
// This will trigger a ACI_CMD_GET_DEVICE_VERSION.
@@ -157,6 +171,7 @@ static void aci_loop() {
case ACI_EVT_PIPE_STATUS:
Serial.println(F("ACI_EVT_PIPE_STATUS"));
+ show_pipes();
break;
case ACI_EVT_TIMING:
@@ -170,20 +185,34 @@ static void aci_loop() {
break;
case ACI_EVT_DATA_RECEIVED:
+ pipe_number = aci_evt->params.data_received.rx_data.pipe_number;
+
Serial.print(F("ACI_EVT_DATA_RECEIVED: pipe_number="));
- Serial.println(aci_evt->params.data_received.rx_data.pipe_number, DEC);
- if (aci_evt->params.data_received.rx_data.pipe_number == PIPE_FIKEN_STATUS_PANEL_GAUGE_RX_ACK) {
- if (aci_evt->len != PIPE_FIKEN_STATUS_PANEL_GAUGE_RX_ACK_MAX_SIZE) {
+ Serial.println(pipe_number, DEC);
+
+ if (pipe_number == PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_RX_ACK) {
+ if (aci_evt->len != PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_RX_ACK_MAX_SIZE) {
break;
}
- set_gauge_req(aci_evt->params.data_received.rx_data.aci_data);
- lib_aci_send_ack(&aci_state, PIPE_FIKEN_STATUS_PANEL_GAUGE_RX_ACK);
+ on_gauge_data(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len - 2);
+ lib_aci_send_ack(&aci_state, PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_RX_ACK);
+ }
+
+ if (pipe_number == PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_RX) {
+ uint8_t len = aci_evt->len - 2;
+ // if (aci_evt->len != PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_RX_MAX_SIZE) {
+ // break;
+ // }
+
+ on_gauge_ctrl(aci_evt->params.data_received.rx_data.aci_data, len);
}
break;
case ACI_EVT_DATA_CREDIT:
Serial.println(F("ACI_EVT_DATA_CREDIT"));
aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit;
+ Serial.print(F("aci_state.data_credit_available="));
+ Serial.println(aci_state.data_credit_available, DEC);
break;
case ACI_EVT_PIPE_ERROR:
@@ -197,8 +226,7 @@ static void aci_loop() {
// Increment the credit available as the data packet was not sent.
// The pipe error also represents the Attribute protocol Error Response sent from the peer and that should not be counted
// for the credit.
- if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code)
- {
+ if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code) {
aci_state.data_credit_available++;
}
break;
@@ -208,8 +236,7 @@ static void aci_loop() {
Serial.print(F("HW error: "));
Serial.println(aci_evt->params.hw_error.line_num, DEC);
- for(uint8_t counter = 0; counter <= (aci_evt->len - 3); counter++)
- {
+ for(uint8_t counter = 0; counter <= (aci_evt->len - 3); counter++) {
Serial.write(aci_evt->params.hw_error.file_name[counter]); //uint8_t file_name[20];
}
Serial.println();
@@ -258,13 +285,6 @@ static void aci_loop() {
}
}
-void set_gauge_req(uint8_t *data) {
- Serial.print(F("set_gauge_req, channel="));
- Serial.print(data[0], DEC);
- Serial.print(F(", value="));
- Serial.println(data[1], DEC);
-}
-
static uint8_t value = 0;
void loop() {
static unsigned long last = 0, now;
@@ -275,15 +295,62 @@ void loop() {
Serial.write(Serial.read());
}
- if (!setup_required) {
- now = millis();
- if (now - last > 3000) {
+ now = millis();
+ if (now - last > 3000) {
+ last = now;
+
+ if (!rf_started) {
+ static int count = 0;
+ count++;
+ if(count == 3) {
+ Serial.println(F("RF did not start, resetting"));
+
+ asm volatile ("jmp 0");
+
+ count = 0;
+ return;
+ } else {
+ Serial.println(F("waiting for RF to start"));
+ }
+ }
+ else if (!setup_required) {
value++;
- lib_aci_set_local_data(&aci_state, PIPE_FIKEN_STATUS_PANEL_GAUGE_SET, &value, 1);
- last = now;
+ lib_aci_set_local_data(&aci_state, PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_SET, &value, 1);
Serial.print(F("value="));
- Serial.println(value, DEC);
+ Serial.println(value, HEX);
+
+ show_pipes();
+ }
+ }
+}
+
+void show_pipes() {
+ for (uint8_t i = 1; i <= NUMBER_OF_PIPES; i++) {
+ uint8_t x = lib_aci_is_pipe_available(&aci_state, i);
+ Serial.print(F("pipe #"));
+ Serial.print(i, DEC);
+ Serial.print(F(", available=?"));
+ Serial.println(x, DEC);
+ }
+}
+
+bool send_ctrl(uint8_t *data, uint8_t len) {
+ bool status = false;
+
+ Serial.print(F("send_ctrl, len="));
+ Serial.println(len, DEC);
+ Serial.print(F("aci_state.data_credit_available="));
+ Serial.println(aci_state.data_credit_available, DEC);
+ Serial.print(F("available="));
+ Serial.println(lib_aci_is_pipe_available(&aci_state, PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_TX), DEC);
+
+ if (lib_aci_is_pipe_available(&aci_state, PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_TX) &&
+ aci_state.data_credit_available >= 1) {
+ status = lib_aci_send_data(PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_TX, data, len);
+ if (status) {
+ aci_state.data_credit_available--;
}
}
+ return status;
}
diff --git a/fiken_status_panel.xml b/fiken_status_panel.xml
index 0506a5a..56e7c14 100644
--- a/fiken_status_panel.xml
+++ b/fiken_status_panel.xml
@@ -7,7 +7,7 @@
<Name>Fiken Status Panel</Name>
<Uuid BaseUUID="32D00000035D59C570D3BC8E4A1FD83F" BaseUUIDName="trygvis.io">0001</Uuid>
<Characteristic>
- <Name>Gauge</Name>
+ <Name>Gauge Data</Name>
<Uuid BaseUUID="32D00000035D59C570D3BC8E4A1FD83F" BaseUUIDName="trygvis.io">0002</Uuid>
<DefaultValue>1234</DefaultValue>
<UsePresentationFormat>0</UsePresentationFormat>
@@ -29,24 +29,24 @@
<PeriodForProperties/>
</Characteristic>
<Characteristic>
- <Name>Led</Name>
- <Uuid BaseUUID="32D00000035D59C570D3BC8E4A1FD83F" BaseUUIDName="trygvis.io">0003</Uuid>
- <DefaultValue>0</DefaultValue>
+ <Name>Gauge Control</Name>
+ <Uuid BaseUUID="32D00000035D59C570D3BC8E4A1FD83F" BaseUUIDName="trygvis.io">0004</Uuid>
+ <DefaultValue></DefaultValue>
<UsePresentationFormat>0</UsePresentationFormat>
- <MaxDataLength>3</MaxDataLength>
+ <MaxDataLength>2</MaxDataLength>
<AttributeLenType>1</AttributeLenType>
<ForceOpen>false</ForceOpen>
<ForceEncryption>false</ForceEncryption>
<Properties>
- <WriteWithoutResponse>false</WriteWithoutResponse>
- <Write>true</Write>
- <Notify>false</Notify>
+ <WriteWithoutResponse>true</WriteWithoutResponse>
+ <Write>false</Write>
+ <Notify>true</Notify>
<Indicate>false</Indicate>
<Broadcast>false</Broadcast>
</Properties>
<SetPipe>false</SetPipe>
<AckIsAuto>false</AckIsAuto>
- <PresentationFormatDescriptor Value="0000" Exponent="0" Format="4" NameSpace="01" Unit="0000"/>
+ <PresentationFormatDescriptor Value="0000" Exponent="0" Format="1" NameSpace="01" Unit="0000"/>
<PeriodForReadingThisCharacteristic>0</PeriodForReadingThisCharacteristic>
<PeriodForProperties/>
</Characteristic>
diff --git a/services.h b/services.h
index 6aff7af..ad217d1 100644
--- a/services.h
+++ b/services.h
@@ -11,32 +11,42 @@
#define SETUP_ID 1
#define SETUP_FORMAT 3 /** nRF8001 D */
-#define ACI_DYNAMIC_DATA_SIZE 130
+#define ACI_DYNAMIC_DATA_SIZE 141
/* Service: Gap - Characteristic: Device name - Pipe: SET */
#define PIPE_GAP_DEVICE_NAME_SET 1
#define PIPE_GAP_DEVICE_NAME_SET_MAX_SIZE 10
-/* Service: Fiken Status Panel - Characteristic: Gauge - Pipe: RX_ACK */
-#define PIPE_FIKEN_STATUS_PANEL_GAUGE_RX_ACK 2
-#define PIPE_FIKEN_STATUS_PANEL_GAUGE_RX_ACK_MAX_SIZE 2
+/* Service: Fiken Status Panel - Characteristic: Gauge Data - Pipe: RX_ACK */
+#define PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_RX_ACK 2
+#define PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_RX_ACK_MAX_SIZE 2
-/* Service: Fiken Status Panel - Characteristic: Gauge - Pipe: SET */
-#define PIPE_FIKEN_STATUS_PANEL_GAUGE_SET 3
-#define PIPE_FIKEN_STATUS_PANEL_GAUGE_SET_MAX_SIZE 2
+/* Service: Fiken Status Panel - Characteristic: Gauge Data - Pipe: SET */
+#define PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_SET 3
+#define PIPE_FIKEN_STATUS_PANEL_GAUGE_DATA_SET_MAX_SIZE 2
/* Service: Fiken Status Panel - Characteristic: Led - Pipe: RX_ACK */
#define PIPE_FIKEN_STATUS_PANEL_LED_RX_ACK 4
#define PIPE_FIKEN_STATUS_PANEL_LED_RX_ACK_MAX_SIZE 3
+/* Service: Fiken Status Panel - Characteristic: Gauge Control - Pipe: TX */
+#define PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_TX 5
+#define PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_TX_MAX_SIZE 2
-#define NUMBER_OF_PIPES 4
+/* Service: Fiken Status Panel - Characteristic: Gauge Control - Pipe: RX */
+#define PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_RX 6
+#define PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_RX_MAX_SIZE 2
+
+
+#define NUMBER_OF_PIPES 6
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
{ACI_STORE_LOCAL, ACI_SET}, \
{ACI_STORE_LOCAL, ACI_RX_ACK}, \
{ACI_STORE_LOCAL, ACI_SET}, \
{ACI_STORE_LOCAL, ACI_RX_ACK}, \
+ {ACI_STORE_LOCAL, ACI_TX}, \
+ {ACI_STORE_LOCAL, ACI_RX}, \
}
#define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
@@ -44,7 +54,7 @@
#define GAP_PPCP_SLAVE_LATENCY 0
#define GAP_PPCP_CONN_TIMEOUT 0xffff /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
-#define NB_SETUP_MESSAGES 18
+#define NB_SETUP_MESSAGES 20
#define SETUP_MESSAGES_CONTENT {\
{0x00,\
{\
@@ -53,7 +63,7 @@
},\
{0x00,\
{\
- 0x1f,0x06,0x10,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x04,0x00,0x01,0x00,0x00,0x06,0x00,0x00,\
+ 0x1f,0x06,0x10,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x06,0x00,0x01,0x00,0x00,0x06,0x00,0x00,\
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
},\
},\
@@ -118,8 +128,19 @@
},\
{0x00,\
{\
- 0x17,0x06,0x20,0xc4,0x59,0x5d,0x03,0x03,0x00,0xd0,0x32,0x46,0x14,0x04,0x03,0x00,0x0d,0x00,0x03,0x02,\
- 0x00,0x00,0x00,0x00,\
+ 0x1f,0x06,0x20,0xc4,0x59,0x5d,0x03,0x03,0x00,0xd0,0x32,0x46,0x14,0x04,0x03,0x00,0x0d,0x00,0x03,0x02,\
+ 0x00,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x0e,0x28,0x03,0x01,\
+ },\
+ },\
+ {0x00,\
+ {\
+ 0x1f,0x06,0x20,0xe0,0x14,0x0f,0x00,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,0xc5,0x59,0x5d,0x03,0x04,\
+ 0x00,0xd0,0x32,0x56,0x10,0x03,0x02,0x00,0x0f,0x00,0x04,0x02,\
+ },\
+ },\
+ {0x00,\
+ {\
+ 0x11,0x06,0x20,0xfc,0x00,0x00,0x46,0x14,0x03,0x02,0x00,0x10,0x29,0x02,0x01,0x00,0x00,0x00,\
},\
},\
{0x00,\
@@ -130,7 +151,7 @@
},\
{0x00,\
{\
- 0x05,0x06,0x40,0x1c,0x00,0x00,\
+ 0x0f,0x06,0x40,0x1c,0x00,0x00,0x00,0x04,0x02,0x00,0x0a,0x04,0x00,0x0f,0x00,0x10,\
},\
},\
{0x00,\
@@ -140,12 +161,12 @@
},\
{0x00,\
{\
- 0x0c,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+ 0x0f,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
},\
},\
{0x00,\
{\
- 0x06,0x06,0xf0,0x00,0x03,0x34,0xaa,\
+ 0x06,0x06,0xf0,0x00,0x03,0x9e,0x82,\
},\
},\
}