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.
communications.h
00001 /******************************************************************************************* 00002 * 00003 * University of York Robot Lab Pi Swarm Library: Swarm Communications Handler 00004 * 00005 * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York 00006 * 00007 * Version 0.5 February 2014 00008 * 00009 * Designed for use with the Pi Swarm Board (enhanced MBED sensor board) v1.2 00010 * 00011 ******************************************************************************************/ 00012 00013 #ifndef COMMUNICATIONS_H 00014 #define COMMUNICATIONS_H 00015 00016 // The swarm_member struct is used by the communication stack to store the status and results for RF commands and requests 00017 // that have been sent. An array of [SWARM_SIZE] swarm_members is created. This contains a status flag for all of the 00018 // standard requests and commands and a set of variables for data which can be collected. 00019 // 00020 // The status flags are set to the following values: 00021 // 0 : "unused" - before any requests are sent 00022 // 1 : "waiting" - a request or command has been sent and the result is not yet known 00023 // 2 : "received" - a valid response to a request or command has been received 00024 // 3 : "invalid" - an invalid response to a request or command has been received 00025 struct swarm_member { 00026 char status_rf_request_null; 00027 char status_rf_request_left_motor_speed; 00028 char status_rf_request_right_motor_speed; 00029 char status_rf_request_button_state; 00030 char status_rf_request_led_colour; 00031 char status_rf_request_led_states; 00032 char status_rf_request_battery; 00033 char status_rf_request_light_sensor; 00034 char status_rf_request_accelerometer; 00035 char status_rf_request_gyroscope; 00036 char status_rf_request_background_ir; 00037 char status_rf_request_reflected_ir; 00038 char status_rf_request_distance_ir; 00039 char status_rf_request_line_following_ir; 00040 char status_rf_request_uptime; 00041 char status_rf_command_stop; 00042 char status_rf_command_forward; 00043 char status_rf_command_backward; 00044 char status_rf_command_left; 00045 char status_rf_command_right; 00046 char status_rf_command_left_motor; 00047 char status_rf_command_right_motor; 00048 char status_rf_command_oled_colour; 00049 char status_rf_command_cled_colour; 00050 char status_rf_command_oled_state; 00051 char status_rf_command_cled_state; 00052 char status_rf_command_set_oled; 00053 char status_rf_command_play_tune; 00054 char status_rf_command_sync_time; 00055 float left_motor_speed; 00056 float right_motor_speed; 00057 char button_state; 00058 char outer_led_colour [3]; 00059 char center_led_colour [3]; 00060 char led_states[2]; 00061 float battery; 00062 float light_sensor; 00063 float accelerometer[3]; 00064 float gyro; 00065 unsigned short background_ir[8]; 00066 unsigned short reflected_ir[8]; 00067 float distance_ir[8]; 00068 }; 00069 00070 void send_rf_message(char target, char command, char * data, char length); 00071 void setup_communications(void); 00072 void decodeMessage(char sender, char target, char id, char command, char * data, char length); 00073 void send_response(char target, char is_broadcast, char success, char id, char is_command, char function, char * data, char length); 00074 void tdma_response(); 00075 void handle_command(char sender, char is_broadcast, char request_response, char id, char function, char * data, char length); 00076 void handle_request(char sender, char is_broadcast, char request_response, char id, char function); 00077 void processRadioData(char * data, char length); 00078 void errormessage(int index); 00079 void handle_response(char sender, char is_broadcast, char success, char id, char is_command, char function, char * data, char length); 00080 00081 void send_rf_request_null ( char target ); 00082 void send_rf_request_left_motor_speed ( char target ); 00083 void send_rf_request_right_motor_speed ( char target ); 00084 void send_rf_request_button_state ( char target ); 00085 void send_rf_request_led_colour ( char target ); 00086 void send_rf_request_led_states ( char target ); 00087 void send_rf_request_battery ( char target ); 00088 void send_rf_request_light_sensor ( char target ); 00089 void send_rf_request_accelerometer ( char target ); 00090 void send_rf_request_gyroscope ( char target ); 00091 void send_rf_request_background_ir ( char target ); 00092 void send_rf_request_reflected_ir ( char target ); 00093 void send_rf_request_distance_ir ( char target ); 00094 void send_rf_request_line_following_ir ( char target ); 00095 void send_rf_request_uptime ( char target ); 00096 void send_rf_command_stop ( char target, char request_response ); 00097 void send_rf_command_forward ( char target, char request_response, float speed ); 00098 void send_rf_command_backward ( char target, char request_response, float speed ); 00099 void send_rf_command_left ( char target, char request_response, float speed ); 00100 void send_rf_command_right ( char target, char request_response, float speed ); 00101 void send_rf_command_left_motor ( char target, char request_response, float speed ); 00102 void send_rf_command_right_motor ( char target, char request_response, float speed ); 00103 void send_rf_command_oled_colour ( char target, char request_response, char red, char green, char blue ); 00104 void send_rf_command_cled_colour ( char target, char request_response, char red, char green, char blue ); 00105 void send_rf_command_oled_state ( char target, char request_response, char led0, char led1, char led2, char led3, char led4, char led5, char led6, char led7, char led8, char led9 ); 00106 void send_rf_command_cled_state ( char target, char request_response, char enable ); 00107 void send_rf_command_set_oled ( char target, char request_response, char oled, char enable ); 00108 void send_rf_command_play_tune ( char target, char request_response, char * data, char length ); 00109 void send_rf_command_sync_time ( char target, char request_response ); 00110 00111 00112 const char * const requests_array[] = { "Req.Ack", "Req.LM", "Req.RM", "Req.But","Req.LEDCol","Req.LED","Req.Lgt","Req.Acc","Req.Gyro","Req.BIR","Req.RIR","Req.DIR","Req.LFS","Req.UpT","Req.???","Req.???"}; 00113 const char * const commands_array[] = { "Cm.Stop","Cm.Fward","Cm.Bward","Cm.Left","Cm.Right","Cm.LMot","Cm.RMot","Cm.OLEDC","Cm.CLEDC","Cm.OLEDS","Cm.CLEDS","Cm.SetLED","Cm.Play","Cm.Sync","Cm.???","Cm.???"}; 00114 00115 #endif //COMMUNICATIONS_H
Generated on Wed Jul 27 2022 21:17:49 by
1.7.2