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.
Communication.cpp@2:06b7789c7da0, 2019-11-24 (annotated)
- Committer:
- FJMS
- Date:
- Sun Nov 24 18:37:46 2019 +0000
- Revision:
- 2:06b7789c7da0
- Parent:
- 1:2716ea33958b
pepe;
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 | 1:2716ea33958b | 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 |