Compiling again
This commit is contained in:
parent
6d52344012
commit
3925e53270
@ -20,7 +20,7 @@
|
|||||||
#define N_OUTPUTS 64
|
#define N_OUTPUTS 64
|
||||||
#define N_ACTIONS 64
|
#define N_ACTIONS 64
|
||||||
|
|
||||||
#define DEBUG 0 // 1 for noisy serial
|
#define DEBUG 1 // 1 for noisy serial
|
||||||
#define LED 17
|
#define LED 17
|
||||||
#define RELAY1 0
|
#define RELAY1 0
|
||||||
#define RELAY2 1
|
#define RELAY2 1
|
||||||
@ -80,6 +80,8 @@ static uint8_t outputs_state[N_OUTPUTS];
|
|||||||
// Type: 0: CMD, 1: FIRST, 2: CONT, 3: LAST
|
// Type: 0: CMD, 1: FIRST, 2: CONT, 3: LAST
|
||||||
// CMD:
|
// CMD:
|
||||||
static event_t tx_events[N_EVENTS] PROGMEM={
|
static event_t tx_events[N_EVENTS] PROGMEM={
|
||||||
|
// | --- ID --- |
|
||||||
|
// tag, prio, dst, cmd, data
|
||||||
{ 1, 0x03, 0xff, 0x03, 0x01},
|
{ 1, 0x03, 0xff, 0x03, 0x01},
|
||||||
{ 2, 0x03, 0xff, 0x03, 0x02},
|
{ 2, 0x03, 0xff, 0x03, 0x02},
|
||||||
{ 3, 0x03, 0xff, 0x03, 0x03},
|
{ 3, 0x03, 0xff, 0x03, 0x03},
|
||||||
@ -103,16 +105,17 @@ static event_t tx_events[N_EVENTS] PROGMEM={
|
|||||||
};
|
};
|
||||||
|
|
||||||
static action_t action_map[N_ACTIONS] PROGMEM={
|
static action_t action_map[N_ACTIONS] PROGMEM={
|
||||||
{1, 0};
|
// tag, output_idx
|
||||||
{2, 1};
|
{1, 0},
|
||||||
{3, 2};
|
{2, 1},
|
||||||
{4, 3};
|
{3, 2},
|
||||||
{5, 4};
|
{4, 3},
|
||||||
{6, 5};
|
{5, 4},
|
||||||
{7, 6};
|
{6, 5},
|
||||||
{8, 7};
|
{7, 6},
|
||||||
{9, 0};{9, 1};{9, 2};{9, 3};{9, 4};{9, 5};{9, 6};{9, 7};
|
{8, 7},
|
||||||
}
|
{9, 0},{9, 1},{9, 2},{9, 3},{9, 4},{9, 5},{9, 6},{9, 7},
|
||||||
|
};
|
||||||
// tx_events[0].id =0x01;
|
// tx_events[0].id =0x01;
|
||||||
// tx_events[0].telegram.id = 0x0102DEAD;
|
// tx_events[0].telegram.id = 0x0102DEAD;
|
||||||
// tx_events[0].telegram.len = 2;
|
// tx_events[0].telegram.len = 2;
|
||||||
@ -128,14 +131,17 @@ static action_t action_map[N_ACTIONS] PROGMEM={
|
|||||||
// Misc
|
// Misc
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define DEBUG_PRINT(a) Serial.print(a)
|
#define DEBUG_PRINT(a) Serial.print(a)
|
||||||
|
#define DEBUG_PRINTLN(a) Serial.println(a)
|
||||||
#define DEBUG_WRITE(a) Serial.write(a)
|
#define DEBUG_WRITE(a) Serial.write(a)
|
||||||
#else
|
#else
|
||||||
#define DEBUG_PRINT(a)
|
#define DEBUG_PRINT(a)
|
||||||
|
#define DEBUG_PRINTLN(a)
|
||||||
#define DEBUG_WRITE(a)
|
#define DEBUG_WRITE(a)
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
uint8_t led = LED;
|
uint8_t led = LED;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
|
uint8_t pin_state;
|
||||||
// Metro
|
// Metro
|
||||||
Metro METRO_CAN = Metro(METRO_CAN_tick);
|
Metro METRO_CAN = Metro(METRO_CAN_tick);
|
||||||
Metro METRO_OW_read = Metro(METRO_OW_read_tick);
|
Metro METRO_OW_read = Metro(METRO_OW_read_tick);
|
||||||
@ -206,31 +212,43 @@ uint32_t forgeid(event_t event){
|
|||||||
return (event.prio<<26)+(event.dst<<16)+(NODE_ID<<8)+event.cmd;
|
return (event.prio<<26)+(event.dst<<16)+(NODE_ID<<8)+event.cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
telegram_comp_t parse_CAN (CAN_telegram_t mesg){
|
telegram_comp_t parse_CAN(CAN_message_t mesg){
|
||||||
telegram_comp_t tmp;
|
telegram_comp_t tmp;
|
||||||
tmp.prio=mesg.id>>26;
|
tmp.prio=mesg.id>>26;
|
||||||
tmp.frametype=(mesg.id>>24) & 0x03;
|
tmp.frametype=(mesg.id>>24) & 0x03;
|
||||||
tmp.dst=(mesg.id>>16) & 0xFF;
|
tmp.dst=(mesg.id>>16) & 0xFF;
|
||||||
tmp.src=(mesg.id>>8) & 0xFF;
|
tmp.src=(mesg.id>>8) & 0xFF;
|
||||||
tmp.cmd=mesg.id & 0xFF;
|
tmp.cmd=mesg.id & 0xFF;
|
||||||
tmp.length=mesg.length;
|
tmp.length=mesg.len;
|
||||||
tmp.buff=mesg.buf;
|
for (uint8_t i = 0; i < mesg.len; i++) { tmp.buf[i] = mesg.buf[i]; }
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void take_action (event_type type, uint8_t tag ){
|
void take_action (action_type type, uint8_t tag ){
|
||||||
for (uint_t i = 0; action_mapaction_map[i].tag != 0 ; i++) {
|
for (uint8_t i = 0; action_map[i].tag != 0 ; i++) {
|
||||||
if ( action_mapaction_map[i].tag == tag ) {
|
if ( action_map[i].tag == tag ) {
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case OFF:
|
case OFF:
|
||||||
digitalWrite(outputs[action_mapaction_map[i].outputs_idx].address,LOW);
|
digitalWrite(outputs[action_map[i].outputs_idx].address,LOW);
|
||||||
|
Serial.print(F("Switching OFF Output: "));
|
||||||
|
Serial.println(action_map[i].outputs_idx);
|
||||||
break;
|
break;
|
||||||
case ON:
|
case ON:
|
||||||
digitalWrite(outputs[action_mapaction_map[i].outputs_idx].address,HIGH);
|
digitalWrite(outputs[action_map[i].outputs_idx].address,HIGH);
|
||||||
|
Serial.print(F("Switching ON Output: "));
|
||||||
|
Serial.println(action_map[i].outputs_idx);
|
||||||
break;
|
break;
|
||||||
case TOGGLE:
|
case TOGGLE:
|
||||||
toggle_Pin(outputs[action_mapaction_map[i].outputs_idx].address);
|
pin_state = toggle_Pin(outputs[action_map[i].outputs_idx].address);
|
||||||
|
Serial.print(F("Toggeling Output: "));
|
||||||
|
Serial.print(action_map[i].outputs_idx);
|
||||||
|
Serial.print(F("to new state: "));
|
||||||
|
Serial.println(pin_state);
|
||||||
break;
|
break;
|
||||||
|
case VALUE:
|
||||||
|
Serial.println(F("TBD"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,7 +335,7 @@ void loop(void)
|
|||||||
if ( tx_events[event_idx].tag == trig_event ) {
|
if ( tx_events[event_idx].tag == trig_event ) {
|
||||||
txmsg.id = forgeid(tx_events[event_idx]);
|
txmsg.id = forgeid(tx_events[event_idx]);
|
||||||
txmsg.len = 1;
|
txmsg.len = 1;
|
||||||
txmsg.buf[0]= tx_events[event_idx].target_id;
|
txmsg.buf[0]= tx_events[event_idx].data;
|
||||||
// for (uint i=0;i<txmsg.len;i++){
|
// for (uint i=0;i<txmsg.len;i++){
|
||||||
// txmsg.buf[i] = tx_events[event_idx].telegram.buf[i];
|
// txmsg.buf[i] = tx_events[event_idx].telegram.buf[i];
|
||||||
// }
|
// }
|
||||||
@ -348,7 +366,7 @@ void loop(void)
|
|||||||
Serial.print(rxmsg.buf[i],HEX);
|
Serial.print(rxmsg.buf[i],HEX);
|
||||||
}
|
}
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
mesg_comp= parse_CAN(rxmesg)
|
mesg_comp= parse_CAN(rxmsg);
|
||||||
if (mesg_comp.dst == 0xFF || mesg_comp.dst == NODE_ID ) {
|
if (mesg_comp.dst == 0xFF || mesg_comp.dst == NODE_ID ) {
|
||||||
|
|
||||||
switch (mesg_comp.cmd) {
|
switch (mesg_comp.cmd) {
|
||||||
|
@ -1,17 +1,27 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
enum out_type { GPIO, PWM, OW, I2C, SPI, WS2811, DMX };
|
enum out_type { GPIO, PWM, OW, I2C, SPI, WS2811, DMX, NOP };
|
||||||
enum event_type { LOCAL, SEND};
|
enum event_type { LOCAL, SEND};
|
||||||
|
|
||||||
enum action_type { OFF, ON, TOGGLE, VALUE };
|
enum action_type { OFF, ON, VALUE, TOGGLE };
|
||||||
enum telegram_type { ALERT, EVENT, NOTIFY, INFO };
|
enum telegram_type { ALERT, EVENT, NOTIFY, INFO };
|
||||||
|
|
||||||
typedef struct CAN_telegram_t {
|
typedef struct CAN_telegram_t {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
uint8_t len;
|
uint8_t length;
|
||||||
uint8_t buf[8];
|
uint8_t buf[8];
|
||||||
} CAN_telegram_t;
|
} CAN_telegram_t;
|
||||||
|
|
||||||
|
typedef struct telegram_comp_t {
|
||||||
|
uint8_t prio;
|
||||||
|
uint8_t frametype;
|
||||||
|
uint8_t dst;
|
||||||
|
uint8_t src;
|
||||||
|
uint8_t cmd;
|
||||||
|
uint8_t length;
|
||||||
|
uint8_t buf[8];
|
||||||
|
} telegram_comp_t;
|
||||||
|
|
||||||
typedef struct OW_switch_t {
|
typedef struct OW_switch_t {
|
||||||
uint8_t nick;
|
uint8_t nick;
|
||||||
uint8_t addr[8];
|
uint8_t addr[8];
|
||||||
@ -23,24 +33,17 @@ typedef struct event_t {
|
|||||||
uint8_t prio;
|
uint8_t prio;
|
||||||
uint8_t dst;
|
uint8_t dst;
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
uint8_t target_id;
|
uint8_t data;
|
||||||
// uint8_t data[2];
|
// uint8_t data[2];
|
||||||
// CAN_telegram_t telegram;
|
// CAN_telegram_t telegram;
|
||||||
} event_t;
|
} event_t;
|
||||||
|
|
||||||
typedef struct telegram_dict_t {
|
|
||||||
CAN_telegram_t telegram;
|
|
||||||
uint8_t tag;
|
|
||||||
} telegram_dict_ttelegram_dict_t;
|
|
||||||
|
|
||||||
typedef struct action_t {
|
typedef struct action_t {
|
||||||
uint8_t id;
|
|
||||||
uint8_t tag;
|
uint8_t tag;
|
||||||
uint8_t outputs_id;
|
uint8_t outputs_idx;
|
||||||
} action_t;
|
} action_t;
|
||||||
|
|
||||||
typedef struct outputs_t {
|
typedef struct outputs_t {
|
||||||
uint8_t id;
|
|
||||||
out_type type;
|
out_type type;
|
||||||
uint8_t address;
|
uint8_t address;
|
||||||
} outputs_t;
|
} outputs_t;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user