![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Code APP3
Dependencies: mbed EthernetInterface WebSocketClient mbed-rtos BufferedSerial
Fork of APP3_Lab by
Diff: xbee.cpp
- Revision:
- 11:ecf5776b950a
- Parent:
- 8:5955af1ee445
- Child:
- 12:1286b80c68f7
--- a/xbee.cpp Sat Sep 30 20:29:47 2017 +0000 +++ b/xbee.cpp Sat Sep 30 21:09:13 2017 +0000 @@ -24,7 +24,7 @@ wait_ms(5000); - xbee_receive_led = 1; + //xbee_receive_led = 1; } @@ -195,41 +195,45 @@ static int curr_length = 0; static frame_recv_state_t recv_state = wait_delimiter; - static frame_t frame; + frame_t* frame = out_frame; static char checksum = 0xFF; bool finished_frame = false; + xbee_receive_led = !xbee_receive_led; while(xbee.readable() && curr_length < max_length && !finished_frame) { + char current = xbee.getc(); switch(recv_state) { case wait_delimiter: { - if (xbee.getc() == ZIGBEE_DELIMITER) + if (current == ZIGBEE_DELIMITER) { + curr_length = 0; recv_state = read_length_msb; + frame->length = 0; } break; } case read_length_msb: { - frame.length = (xbee.getc() << 8); + frame->length = (current << 8); recv_state = read_length_lsb; break; } case read_length_lsb: - { - frame.length |= xbee.getc(); + { + frame->length |= current; checksum = 0xFF; recv_state = read_frame_specific; break; } case read_frame_specific: { - frame.buffer[curr_length] = xbee.getc(); - checksum -= frame.buffer[curr_length++]; - if (curr_length >= frame.length) + frame->buffer[curr_length++] = current; + checksum -= current; + if (curr_length >= frame->length) { recv_state = read_checksum; } @@ -238,10 +242,8 @@ case read_checksum: { recv_state = wait_delimiter; - xbee_receive_led = !xbee_receive_led; - if (checksum == xbee.getc()) + if (checksum == current) { - out_frame = &frame; finished_frame = true; } break;