diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2014-12-07 00:06:27 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2014-12-07 00:06:27 +0100 |
commit | 90f5e8958e0f49e2c303abfb9d1f557e28caf78c (patch) | |
tree | af1e110bedb83c4a9c69b81c83d14c6b31b1d3f1 | |
parent | d015c05c7a141f183647fe0cd64c332b7af23800 (diff) | |
download | fiken_status_panel-master.tar.gz fiken_status_panel-master.tar.bz2 fiken_status_panel-master.tar.xz fiken_status_panel-master.zip |
-rw-r--r-- | app.cpp | 52 | ||||
-rw-r--r-- | app.h | 53 | ||||
-rw-r--r-- | fiken_status_panel.ino | 25 | ||||
-rw-r--r-- | services.h | 43 |
4 files changed, 125 insertions, 48 deletions
@@ -1,5 +1,6 @@ #include "app.h" +#include <Arduino.h> #include <HardwareSerial.h> // http://bleaklow.com/2010/09/05/progmem_and_gcc_bug_34734.html @@ -9,8 +10,14 @@ #define GAUGE_COUNT 4 // See http://redbearlab.com/blendmicro/ -int gauge_pins[GAUGE_COUNT] = { - 9, 10, 11, 13 +struct gauge { + uint8_t pin; + uint8_t value; +} gauges[] = { + { 9, 0}, + {10, 0}, + {11, 0}, + {13, 0} }; void on_gauge_data(uint8_t *data, uint8_t len) { @@ -21,21 +28,48 @@ void on_gauge_data(uint8_t *data, uint8_t len) { } void on_gauge_ctrl(uint8_t *data, uint8_t len) { - Serial.print(F("on_gauge_data, data[0]=")); + Serial.print(F("on_gauge_ctrl, data[0]=")); Serial.print(data[0], HEX); Serial.print(F(", data[1]=")); Serial.println(data[1], HEX); - uint8_t res[2]; + struct fsp_req *cmd = (struct fsp_req *) data; + struct fsp_res res; - switch(data[0]) { - case FSP_CMD_GAUGE_COUNT: - res[0] = FSP_CMD_GAUGE_COUNT; - res[1] = GAUGE_COUNT; - send_ctrl(res, 2); + res.code = cmd->code; + + Serial.print("code="); + Serial.println(cmd->code, DEC); + + switch(cmd->code) { + case FSP_CMD_GET_GAUGE_COUNT: + res.len = sizeof(struct fsp_get_gauge_count_res); + res.get_gauge_count.count = GAUGE_COUNT; + break; + case FSP_CMD_SET_GAUGE: + res.len = sizeof(struct fsp_set_gauge_res); + if (cmd->set_gauge.gauge < GAUGE_COUNT) { + analogWrite(gauges[cmd->set_gauge.gauge].pin, cmd->set_gauge.value); + gauges[cmd->set_gauge.gauge].value = cmd->set_gauge.value; + } + + break; + case FSP_CMD_GET_GAUGE: + res.len = sizeof(struct fsp_get_gauge_res); + if (cmd->get_gauge.gauge < GAUGE_COUNT) { + res.get_gauge.gauge = cmd->get_gauge.gauge; + res.get_gauge.value = gauges[cmd->get_gauge.gauge].value; + } else { + res.code = FSP_CMD_FAIL; + res.len = 0; + } break; default: + res.code = FSP_CMD_FAIL; + res.len = 0; break; } + + send_ctrl(&res); } @@ -3,10 +3,57 @@ #include <stdint.h> -#define FSP_CMD_GAUGE_COUNT 1 -#define FSP_CMD_GAUGE_INFO 2 +enum fsp_cmd_code { + FSP_CMD_GET_GAUGE_COUNT = 1, + FSP_CMD_SET_GAUGE = 2, + FSP_CMD_GET_GAUGE = 3, + FSP_CMD_FAIL = 255, +}; -bool send_ctrl(uint8_t *data, uint8_t len); +struct fsp_get_gauge_count_req { +}; + +struct fsp_get_gauge_count_res { + uint8_t count; +}; + +struct fsp_set_gauge_req { + uint8_t gauge; + uint8_t value; +}; + +struct fsp_set_gauge_res { +}; + +struct fsp_get_gauge_req { + uint8_t gauge; +}; + +struct fsp_get_gauge_res { + uint8_t gauge; + uint8_t value; +}; + +struct fsp_req { + uint8_t code; + union { + struct fsp_get_gauge_count_req get_gauge_count; + struct fsp_get_gauge_req get_gauge; + struct fsp_set_gauge_req set_gauge; + }; +}; + +struct fsp_res { + uint8_t len; + uint8_t code; + union { + struct fsp_get_gauge_count_res get_gauge_count; + struct fsp_get_gauge_res get_gauge; + struct fsp_set_gauge_res set_gauge; + }; +}; + +bool send_ctrl(struct fsp_res *res); void on_gauge_data(uint8_t *data, uint8_t len); void on_gauge_ctrl(uint8_t *data, uint8_t len); diff --git a/fiken_status_panel.ino b/fiken_status_panel.ino index 35b3d40..82c4671 100644 --- a/fiken_status_panel.ino +++ b/fiken_status_panel.ino @@ -1,5 +1,4 @@ #include <SPI.h> -#include <Watchdog.h> #include <lib_aci.h> #include <aci_setup.h> @@ -48,8 +47,11 @@ void setup() { delay(1000); #endif - Serial.println(F("setup()")); + setup_rf(); +} +void setup_rf() { + Serial.println(F("setup_rf()")); // Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001 if (NULL != services_pipe_type_mapping) { aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0]; @@ -93,7 +95,7 @@ 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; @@ -302,16 +304,19 @@ void loop() { if (!rf_started) { static int count = 0; count++; + /* if(count == 3) { - Serial.println(F("RF did not start, resetting")); - - asm volatile ("jmp 0"); + Serial.println(F("RF did not start, resetting RF")); + // asm volatile ("jmp 0"); + // lib_aci_pin_reset(); + setup_rf(); count = 0; return; } else { Serial.println(F("waiting for RF to start")); } + */ } else if (!setup_required) { value++; @@ -319,7 +324,7 @@ void loop() { Serial.print(F("value=")); Serial.println(value, HEX); - show_pipes(); + // show_pipes(); } } } @@ -334,7 +339,9 @@ void show_pipes() { } } -bool send_ctrl(uint8_t *data, uint8_t len) { +bool send_ctrl(fsp_res *res) { + uint8_t *data = (uint8_t *)res; + uint8_t len = 2 + res->len; bool status = false; Serial.print(F("send_ctrl, len=")); @@ -343,7 +350,7 @@ bool send_ctrl(uint8_t *data, uint8_t len) { 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); @@ -11,7 +11,7 @@ #define SETUP_ID 1 #define SETUP_FORMAT 3 /** nRF8001 D */ -#define ACI_DYNAMIC_DATA_SIZE 141 +#define ACI_DYNAMIC_DATA_SIZE 143 /* Service: Gap - Characteristic: Device name - Pipe: SET */ #define PIPE_GAP_DEVICE_NAME_SET 1 @@ -25,26 +25,21 @@ #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 PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_TX 4 +#define PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_TX_MAX_SIZE 10 /* 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 PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_RX 5 +#define PIPE_FIKEN_STATUS_PANEL_GAUGE_CONTROL_RX_MAX_SIZE 10 -#define NUMBER_OF_PIPES 6 +#define NUMBER_OF_PIPES 5 #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}, \ } @@ -54,7 +49,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 20 +#define NB_SETUP_MESSAGES 19 #define SETUP_MESSAGES_CONTENT {\ {0x00,\ {\ @@ -63,7 +58,7 @@ },\ {0x00,\ {\ - 0x1f,0x06,0x10,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x06,0x00,0x01,0x00,0x00,0x06,0x00,0x00,\ + 0x1f,0x06,0x10,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x05,0x00,0x01,0x00,0x00,0x06,0x00,0x00,\ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ @@ -123,35 +118,29 @@ {0x00,\ {\ 0x1f,0x06,0x20,0xa8,0x00,0x0b,0x00,0x02,0x02,0x12,0x34,0x04,0x04,0x13,0x13,0x00,0x0c,0x28,0x03,0x01,\ - 0x0a,0x0d,0x00,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,0xc5,\ - },\ - },\ - {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,\ + 0x14,0x0d,0x00,0x3f,0xd8,0x1f,0x4a,0x8e,0xbc,0xd3,0x70,0xc5,\ },\ },\ {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,\ + 0x1f,0x06,0x20,0xc4,0x59,0x5d,0x03,0x04,0x00,0xd0,0x32,0x54,0x10,0x0a,0x00,0x00,0x0d,0x00,0x04,0x02,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,\ },\ },\ {0x00,\ {\ - 0x11,0x06,0x20,0xfc,0x00,0x00,0x46,0x14,0x03,0x02,0x00,0x10,0x29,0x02,0x01,0x00,0x00,0x00,\ + 0x0d,0x06,0x20,0xe0,0x03,0x02,0x00,0x0e,0x29,0x02,0x01,0x00,0x00,0x00,\ },\ },\ {0x00,\ {\ 0x1f,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,0x00,0x02,0x02,0x00,0x90,0x04,\ - 0x00,0x0b,0x00,0x00,0x00,0x03,0x02,0x00,0x10,0x04,0x00,0x0d,\ + 0x00,0x0b,0x00,0x00,0x00,0x04,0x02,0x00,0x0a,0x04,0x00,0x0d,\ },\ },\ {0x00,\ {\ - 0x0f,0x06,0x40,0x1c,0x00,0x00,0x00,0x04,0x02,0x00,0x0a,0x04,0x00,0x0f,0x00,0x10,\ + 0x05,0x06,0x40,0x1c,0x00,0x0e,\ },\ },\ {0x00,\ @@ -161,12 +150,12 @@ },\ {0x00,\ {\ - 0x0f,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x0c,0x06,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ },\ },\ {0x00,\ {\ - 0x06,0x06,0xf0,0x00,0x03,0x9e,0x82,\ + 0x06,0x06,0xf0,0x00,0x03,0x77,0x58,\ },\ },\ } |