App1_S5
/
APP4_IRQ
APP4 S5
Diff: radio.cpp
- Revision:
- 4:728322e9e3eb
- Parent:
- 3:6ea97936f6fa
- Child:
- 5:70d338ee3f77
--- a/radio.cpp Wed Oct 11 20:15:23 2017 +0000 +++ b/radio.cpp Wed Oct 11 20:36:04 2017 +0000 @@ -52,6 +52,9 @@ void setup_radio_in() { + in_message_in = 0; + in_message_out = 0; + in_debug_led = 0; input.rise(&in_rise); @@ -90,13 +93,90 @@ } +typedef enum { + preambule = 0, + start, + options, + length, + data, + crc, + end +} out_state_t; + void radio_out(void const *args) { + static byte current_byte_progress = 0; + static byte current_byte = 0; + static byte current_state = 0; + radio_message_t* message = (radio_message_t*)(out_messages + out_message_out); #define OUTPUT_HIGH output = 1; #define OUTPUT_LOW output = 0; + #define SET_VAL_BIT_MASK(val) output = 0x1 & val; + #define SET_VAL_SHIFT(val, shift) SET_VAL_BIT_MASK(val >> (7 - shift)) + + + #define CHECK_NEXT_STATE if (current_byte_progress > 7) \ + { \ + current_state++; \ + current_byte_progress = 0; \ + } + out_debug_led = !out_debug_led; - output = !output; + + switch (current_state) + { + case preambule: // preambule + { + SET_VAL_SHIFT(message->preambule, current_byte_progress++); + CHECK_NEXT_STATE + break; + } + case start: // start + { + SET_VAL_SHIFT(message->start, current_byte_progress++); + CHECK_NEXT_STATE + break; + } + case options: // entete options + { + SET_VAL_SHIFT(message->options, current_byte_progress++); + CHECK_NEXT_STATE + break; + } + case length: // entete lenght + { + SET_VAL_SHIFT(message->length, current_byte_progress++); + CHECK_NEXT_STATE + break; + } + case data: // charge utile + { + //CHECK_NEXT_STATE + break; + } + case crc: // controle + { + CHECK_NEXT_STATE + break; + } + case end: // end + { + CHECK_NEXT_STATE + break; + } + default: + { + current_state = 0; + current_byte = 0; + current_byte_progress = 0; + break; + } + + } + + + //output = !output; }