Unfinished v0.7, added bearing detection
Fork of Pi_Swarm_Library_v06_alpha by
communications.h@9:7a4fc1d7e484, 2014-02-18 (annotated)
- Committer:
- jah128
- Date:
- Tue Feb 18 17:14:03 2014 +0000
- Revision:
- 9:7a4fc1d7e484
- Parent:
- 4:52b3e4c5a425
- Child:
- 11:5ebcb52726cf
Draft v0.6 Library (unfinished)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 4:52b3e4c5a425 | 1 | /******************************************************************************************* |
jah128 | 4:52b3e4c5a425 | 2 | * |
jah128 | 4:52b3e4c5a425 | 3 | * University of York Robot Lab Pi Swarm Library: Swarm Communications Handler |
jah128 | 0:9ffe8ebd1c40 | 4 | * |
jah128 | 0:9ffe8ebd1c40 | 5 | * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York |
jah128 | 1:b067a08ff54e | 6 | * |
jah128 | 9:7a4fc1d7e484 | 7 | * Version 0.6 February 2014 |
jah128 | 0:9ffe8ebd1c40 | 8 | * |
jah128 | 0:9ffe8ebd1c40 | 9 | * Designed for use with the Pi Swarm Board (enhanced MBED sensor board) v1.2 |
jah128 | 0:9ffe8ebd1c40 | 10 | * |
jah128 | 4:52b3e4c5a425 | 11 | ******************************************************************************************/ |
jah128 | 0:9ffe8ebd1c40 | 12 | |
jah128 | 0:9ffe8ebd1c40 | 13 | #ifndef COMMUNICATIONS_H |
jah128 | 0:9ffe8ebd1c40 | 14 | #define COMMUNICATIONS_H |
jah128 | 1:b067a08ff54e | 15 | |
jah128 | 1:b067a08ff54e | 16 | // The swarm_member struct is used by the communication stack to store the status and results for RF commands and requests |
jah128 | 1:b067a08ff54e | 17 | // that have been sent. An array of [SWARM_SIZE] swarm_members is created. This contains a status flag for all of the |
jah128 | 1:b067a08ff54e | 18 | // standard requests and commands and a set of variables for data which can be collected. |
jah128 | 1:b067a08ff54e | 19 | // |
jah128 | 1:b067a08ff54e | 20 | // The status flags are set to the following values: |
jah128 | 1:b067a08ff54e | 21 | // 0 : "unused" - before any requests are sent |
jah128 | 1:b067a08ff54e | 22 | // 1 : "waiting" - a request or command has been sent and the result is not yet known |
jah128 | 1:b067a08ff54e | 23 | // 2 : "received" - a valid response to a request or command has been received |
jah128 | 1:b067a08ff54e | 24 | // 3 : "invalid" - an invalid response to a request or command has been received |
jah128 | 1:b067a08ff54e | 25 | struct swarm_member { |
jah128 | 1:b067a08ff54e | 26 | char status_rf_request_null; |
jah128 | 1:b067a08ff54e | 27 | char status_rf_request_left_motor_speed; |
jah128 | 1:b067a08ff54e | 28 | char status_rf_request_right_motor_speed; |
jah128 | 1:b067a08ff54e | 29 | char status_rf_request_button_state; |
jah128 | 1:b067a08ff54e | 30 | char status_rf_request_led_colour; |
jah128 | 1:b067a08ff54e | 31 | char status_rf_request_led_states; |
jah128 | 1:b067a08ff54e | 32 | char status_rf_request_battery; |
jah128 | 1:b067a08ff54e | 33 | char status_rf_request_light_sensor; |
jah128 | 1:b067a08ff54e | 34 | char status_rf_request_accelerometer; |
jah128 | 1:b067a08ff54e | 35 | char status_rf_request_gyroscope; |
jah128 | 1:b067a08ff54e | 36 | char status_rf_request_background_ir; |
jah128 | 1:b067a08ff54e | 37 | char status_rf_request_reflected_ir; |
jah128 | 1:b067a08ff54e | 38 | char status_rf_request_distance_ir; |
jah128 | 1:b067a08ff54e | 39 | char status_rf_request_line_following_ir; |
jah128 | 1:b067a08ff54e | 40 | char status_rf_request_uptime; |
jah128 | 1:b067a08ff54e | 41 | char status_rf_command_stop; |
jah128 | 1:b067a08ff54e | 42 | char status_rf_command_forward; |
jah128 | 1:b067a08ff54e | 43 | char status_rf_command_backward; |
jah128 | 1:b067a08ff54e | 44 | char status_rf_command_left; |
jah128 | 1:b067a08ff54e | 45 | char status_rf_command_right; |
jah128 | 1:b067a08ff54e | 46 | char status_rf_command_left_motor; |
jah128 | 1:b067a08ff54e | 47 | char status_rf_command_right_motor; |
jah128 | 1:b067a08ff54e | 48 | char status_rf_command_oled_colour; |
jah128 | 1:b067a08ff54e | 49 | char status_rf_command_cled_colour; |
jah128 | 1:b067a08ff54e | 50 | char status_rf_command_oled_state; |
jah128 | 1:b067a08ff54e | 51 | char status_rf_command_cled_state; |
jah128 | 1:b067a08ff54e | 52 | char status_rf_command_set_oled; |
jah128 | 1:b067a08ff54e | 53 | char status_rf_command_play_tune; |
jah128 | 1:b067a08ff54e | 54 | char status_rf_command_sync_time; |
jah128 | 1:b067a08ff54e | 55 | float left_motor_speed; |
jah128 | 1:b067a08ff54e | 56 | float right_motor_speed; |
jah128 | 1:b067a08ff54e | 57 | char button_state; |
jah128 | 1:b067a08ff54e | 58 | char outer_led_colour [3]; |
jah128 | 1:b067a08ff54e | 59 | char center_led_colour [3]; |
jah128 | 1:b067a08ff54e | 60 | char led_states[2]; |
jah128 | 1:b067a08ff54e | 61 | float battery; |
jah128 | 1:b067a08ff54e | 62 | float light_sensor; |
jah128 | 1:b067a08ff54e | 63 | float accelerometer[3]; |
jah128 | 1:b067a08ff54e | 64 | float gyro; |
jah128 | 3:4c0f2f3de33e | 65 | unsigned short background_ir[8]; |
jah128 | 3:4c0f2f3de33e | 66 | unsigned short reflected_ir[8]; |
jah128 | 3:4c0f2f3de33e | 67 | float distance_ir[8]; |
jah128 | 1:b067a08ff54e | 68 | }; |
jah128 | 1:b067a08ff54e | 69 | |
jah128 | 1:b067a08ff54e | 70 | void send_rf_message(char target, char command, char * data, char length); |
jah128 | 1:b067a08ff54e | 71 | void setup_communications(void); |
jah128 | 0:9ffe8ebd1c40 | 72 | void decodeMessage(char sender, char target, char id, char command, char * data, char length); |
jah128 | 0:9ffe8ebd1c40 | 73 | void send_response(char target, char is_broadcast, char success, char id, char is_command, char function, char * data, char length); |
jah128 | 0:9ffe8ebd1c40 | 74 | void tdma_response(); |
jah128 | 0:9ffe8ebd1c40 | 75 | void handle_command(char sender, char is_broadcast, char request_response, char id, char function, char * data, char length); |
jah128 | 0:9ffe8ebd1c40 | 76 | void handle_request(char sender, char is_broadcast, char request_response, char id, char function); |
jah128 | 0:9ffe8ebd1c40 | 77 | void processRadioData(char * data, char length); |
jah128 | 0:9ffe8ebd1c40 | 78 | void errormessage(int index); |
jah128 | 1:b067a08ff54e | 79 | void handle_response(char sender, char is_broadcast, char success, char id, char is_command, char function, char * data, char length); |
jah128 | 4:52b3e4c5a425 | 80 | |
jah128 | 1:b067a08ff54e | 81 | void send_rf_request_null ( char target ); |
jah128 | 1:b067a08ff54e | 82 | void send_rf_request_left_motor_speed ( char target ); |
jah128 | 1:b067a08ff54e | 83 | void send_rf_request_right_motor_speed ( char target ); |
jah128 | 1:b067a08ff54e | 84 | void send_rf_request_button_state ( char target ); |
jah128 | 1:b067a08ff54e | 85 | void send_rf_request_led_colour ( char target ); |
jah128 | 1:b067a08ff54e | 86 | void send_rf_request_led_states ( char target ); |
jah128 | 1:b067a08ff54e | 87 | void send_rf_request_battery ( char target ); |
jah128 | 1:b067a08ff54e | 88 | void send_rf_request_light_sensor ( char target ); |
jah128 | 1:b067a08ff54e | 89 | void send_rf_request_accelerometer ( char target ); |
jah128 | 1:b067a08ff54e | 90 | void send_rf_request_gyroscope ( char target ); |
jah128 | 1:b067a08ff54e | 91 | void send_rf_request_background_ir ( char target ); |
jah128 | 1:b067a08ff54e | 92 | void send_rf_request_reflected_ir ( char target ); |
jah128 | 1:b067a08ff54e | 93 | void send_rf_request_distance_ir ( char target ); |
jah128 | 1:b067a08ff54e | 94 | void send_rf_request_line_following_ir ( char target ); |
jah128 | 1:b067a08ff54e | 95 | void send_rf_request_uptime ( char target ); |
jah128 | 1:b067a08ff54e | 96 | void send_rf_command_stop ( char target, char request_response ); |
jah128 | 1:b067a08ff54e | 97 | void send_rf_command_forward ( char target, char request_response, float speed ); |
jah128 | 1:b067a08ff54e | 98 | void send_rf_command_backward ( char target, char request_response, float speed ); |
jah128 | 1:b067a08ff54e | 99 | void send_rf_command_left ( char target, char request_response, float speed ); |
jah128 | 1:b067a08ff54e | 100 | void send_rf_command_right ( char target, char request_response, float speed ); |
jah128 | 1:b067a08ff54e | 101 | void send_rf_command_left_motor ( char target, char request_response, float speed ); |
jah128 | 1:b067a08ff54e | 102 | void send_rf_command_right_motor ( char target, char request_response, float speed ); |
jah128 | 1:b067a08ff54e | 103 | void send_rf_command_oled_colour ( char target, char request_response, char red, char green, char blue ); |
jah128 | 1:b067a08ff54e | 104 | void send_rf_command_cled_colour ( char target, char request_response, char red, char green, char blue ); |
jah128 | 1:b067a08ff54e | 105 | 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 ); |
jah128 | 1:b067a08ff54e | 106 | void send_rf_command_cled_state ( char target, char request_response, char enable ); |
jah128 | 1:b067a08ff54e | 107 | void send_rf_command_set_oled ( char target, char request_response, char oled, char enable ); |
jah128 | 1:b067a08ff54e | 108 | void send_rf_command_play_tune ( char target, char request_response, char * data, char length ); |
jah128 | 1:b067a08ff54e | 109 | void send_rf_command_sync_time ( char target, char request_response ); |
jah128 | 1:b067a08ff54e | 110 | |
jah128 | 1:b067a08ff54e | 111 | |
jah128 | 1:b067a08ff54e | 112 | 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.???"}; |
jah128 | 1:b067a08ff54e | 113 | 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.???"}; |
jah128 | 1:b067a08ff54e | 114 | |
jah128 | 0:9ffe8ebd1c40 | 115 | #endif //COMMUNICATIONS_H |