![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pepe
Communication.cpp@0:a7324f51348d, 2019-03-13 (annotated)
- Committer:
- PedroMartins96
- Date:
- Wed Mar 13 23:04:14 2019 +0000
- Revision:
- 0:a7324f51348d
- Child:
- 1:2716ea33958b
444
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PedroMartins96 | 0:a7324f51348d | 1 | #include "Communication.h" |
PedroMartins96 | 0:a7324f51348d | 2 | #include "mbed.h" |
PedroMartins96 | 0:a7324f51348d | 3 | #include "MessageBuilder.h" |
PedroMartins96 | 0:a7324f51348d | 4 | |
PedroMartins96 | 0:a7324f51348d | 5 | const char max_len = 30; |
PedroMartins96 | 0:a7324f51348d | 6 | Serial *serial_object; |
PedroMartins96 | 0:a7324f51348d | 7 | MessageBuilder bin_msg; |
PedroMartins96 | 0:a7324f51348d | 8 | |
PedroMartins96 | 0:a7324f51348d | 9 | void init_communication(Serial *serial_in) |
PedroMartins96 | 0:a7324f51348d | 10 | { |
PedroMartins96 | 0:a7324f51348d | 11 | serial_object = serial_in; |
PedroMartins96 | 0:a7324f51348d | 12 | } |
PedroMartins96 | 0:a7324f51348d | 13 | |
PedroMartins96 | 0:a7324f51348d | 14 | void write_bytes(char *ptr, unsigned char len) |
PedroMartins96 | 0:a7324f51348d | 15 | { |
PedroMartins96 | 0:a7324f51348d | 16 | for(int i=0; i<len; i++) |
PedroMartins96 | 0:a7324f51348d | 17 | { |
PedroMartins96 | 0:a7324f51348d | 18 | serial_object->putc(ptr[i]); |
PedroMartins96 | 0:a7324f51348d | 19 | } |
PedroMartins96 | 0:a7324f51348d | 20 | } |
PedroMartins96 | 0:a7324f51348d | 21 | |
PedroMartins96 | 0:a7324f51348d | 22 | void send_odometry(int value1, int value2, int ticks_left, int ticks_right, float x, float y, float theta) |
PedroMartins96 | 0:a7324f51348d | 23 | { |
PedroMartins96 | 0:a7324f51348d | 24 | bin_msg.reset(); |
PedroMartins96 | 0:a7324f51348d | 25 | bin_msg.add('O'); |
PedroMartins96 | 0:a7324f51348d | 26 | bin_msg.add(value1); |
PedroMartins96 | 0:a7324f51348d | 27 | bin_msg.add(value2); |
PedroMartins96 | 0:a7324f51348d | 28 | bin_msg.add(ticks_left); |
PedroMartins96 | 0:a7324f51348d | 29 | bin_msg.add(ticks_right); |
PedroMartins96 | 0:a7324f51348d | 30 | bin_msg.add(x); |
PedroMartins96 | 0:a7324f51348d | 31 | bin_msg.add(y); |
PedroMartins96 | 0:a7324f51348d | 32 | bin_msg.add(theta); |
PedroMartins96 | 0:a7324f51348d | 33 | |
PedroMartins96 | 0:a7324f51348d | 34 | write_bytes(bin_msg.message, bin_msg.length()); |
PedroMartins96 | 0:a7324f51348d | 35 | } |
PedroMartins96 | 0:a7324f51348d | 36 |