Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NerfUS-Coord NerfUSTarget
Fork of APP3_xbee by
Diff: xbee.cpp
- Revision:
- 9:04063c29ab43
- Parent:
- 8:b9c096965c00
- Child:
- 11:d3811e37d89c
--- a/xbee.cpp Tue Feb 14 02:38:18 2017 +0000
+++ b/xbee.cpp Tue Feb 14 05:02:45 2017 +0000
@@ -7,6 +7,10 @@
Mail<ingoing_value_t, 30> parsed_frames;
RawSerial xbee(p13, p14);
Mutex mutex;
+DigitalOut error_led(p6);
+Thread error_led_thread;
+
+
const int FRAME_SPECIFIC_DATA_BEGIN[14] = {0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x00};
const int AT_COMMAND_LED_FRAME_SPECIFIC_DATA_BEGIN[15] = {0x17, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFE, 0x02, 0x50, 0x32};
const char LED_COMMAND_POWER_ON = 0x05;
@@ -155,6 +159,42 @@
return relevant_content;
}
+vector<char> parse_remote_command_response(const vector<char>& frame)
+{
+ vector<char> relevant_content;
+
+ const char command_status = frame.at(17);
+ relevant_content.push_back(command_status);
+
+ return relevant_content;
+}
+
+void manage_error_led()
+{
+ while(true)
+ {
+ osSignalWait(0x1, osWaitForever);
+ error_led = 1;
+ wait_ms(1000);
+ error_led = 0;
+ }
+}
+
+void send_blink_led_at_command(const bool toggle_current_command)
+{
+ static bool is_current_command_turn_on = false;
+ if(toggle_current_command)
+ {
+ is_current_command_turn_on = !is_current_command_turn_on;
+ }
+
+ const vector<char> led_command = generate_led_command(is_current_command_turn_on);
+ for(int i=0; i<led_command.size(); i++)
+ {
+ xbee.putc(led_command[i]);
+ }
+}
+
void handle_parsed_frames_from_mailbox()
{
while(true)
@@ -173,21 +213,21 @@
printf("Handling receive packet: %s\r\n", parsed_frame_string);
break;
+
+ case FRAME_TYPE_REMOTE_COMMAND_RESPONSE:
+ const bool is_status_ok = (parsed_frame->content[1] == 0);
+ if(!is_status_ok)
+ {
+ error_led_thread.signal_set(0x1);
+ send_blink_led_at_command(false);
+ }
+ break;
default:
+ printf("Unsupported. Type: %d\r\n", parsed_frame_type);
break;
}
- /*
- printf("Handling parsed frame. Type: %d\r\n", parsed_frame_type);
-
- printf("Relevant content: ");
- for(int i=1; i<value->size; i++)
- {
- printf("%d\r\n", value->content[i]);
- }
- */
-
parsed_frames.free(parsed_frame);
}
}
@@ -242,7 +282,17 @@
parsed_frame_relevant_content = parse_at_command_response(frame);
break;
}
- default: assert(false && "Unsupported frame type");
+ case FRAME_TYPE_REMOTE_COMMAND_RESPONSE:
+ {
+ parsed_frame_relevant_content = parse_remote_command_response(frame);
+ break;
+ }
+ default:
+ printf("Unsupported frame:\r\n");
+ for(int i=0; i<frame.size(); i++)
+ {
+ printf("Bit #%d: %d\r\n", i, frame.at(i));
+ }
}
for(vector<char>::iterator it = parsed_frame_relevant_content.begin(); it < parsed_frame_relevant_content.end(); it++)
