José Gouveia
/
SRA2020-2021
feito
Communication.cpp@9:d0ef39e209b7, 2021-05-20 (annotated)
- Committer:
- josefg25
- Date:
- Thu May 20 16:18:59 2021 +0000
- Revision:
- 9:d0ef39e209b7
- Parent:
- 0:c25c4b67b6a1
SRA_update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yaaqobhpt | 0:c25c4b67b6a1 | 1 | #include "Communication.h" |
yaaqobhpt | 0:c25c4b67b6a1 | 2 | #include "mbed.h" |
yaaqobhpt | 0:c25c4b67b6a1 | 3 | #include "MessageBuilder.h" |
yaaqobhpt | 0:c25c4b67b6a1 | 4 | |
yaaqobhpt | 0:c25c4b67b6a1 | 5 | const char max_len = 30; |
yaaqobhpt | 0:c25c4b67b6a1 | 6 | Serial *serial_object; |
yaaqobhpt | 0:c25c4b67b6a1 | 7 | MessageBuilder bin_msg; |
yaaqobhpt | 0:c25c4b67b6a1 | 8 | |
yaaqobhpt | 0:c25c4b67b6a1 | 9 | void init_communication(Serial *serial_in) |
yaaqobhpt | 0:c25c4b67b6a1 | 10 | { |
yaaqobhpt | 0:c25c4b67b6a1 | 11 | serial_object = serial_in; |
yaaqobhpt | 0:c25c4b67b6a1 | 12 | } |
yaaqobhpt | 0:c25c4b67b6a1 | 13 | |
yaaqobhpt | 0:c25c4b67b6a1 | 14 | void write_bytes(char *ptr, unsigned char len) |
yaaqobhpt | 0:c25c4b67b6a1 | 15 | { |
yaaqobhpt | 0:c25c4b67b6a1 | 16 | for(int i=0; i<len; i++) |
yaaqobhpt | 0:c25c4b67b6a1 | 17 | { |
yaaqobhpt | 0:c25c4b67b6a1 | 18 | serial_object->putc(ptr[i]); |
yaaqobhpt | 0:c25c4b67b6a1 | 19 | } |
yaaqobhpt | 0:c25c4b67b6a1 | 20 | } |
yaaqobhpt | 0:c25c4b67b6a1 | 21 | |
yaaqobhpt | 0:c25c4b67b6a1 | 22 | void send_odometry(int value1, int value2, int ticks_left, int ticks_right, float x, float y, float theta) |
yaaqobhpt | 0:c25c4b67b6a1 | 23 | { |
yaaqobhpt | 0:c25c4b67b6a1 | 24 | bin_msg.reset(); |
yaaqobhpt | 0:c25c4b67b6a1 | 25 | bin_msg.add('O'); |
yaaqobhpt | 0:c25c4b67b6a1 | 26 | bin_msg.add(value1); |
yaaqobhpt | 0:c25c4b67b6a1 | 27 | bin_msg.add(value2); |
yaaqobhpt | 0:c25c4b67b6a1 | 28 | bin_msg.add(ticks_left); |
yaaqobhpt | 0:c25c4b67b6a1 | 29 | bin_msg.add(ticks_right); |
yaaqobhpt | 0:c25c4b67b6a1 | 30 | bin_msg.add(x); |
yaaqobhpt | 0:c25c4b67b6a1 | 31 | bin_msg.add(y); |
yaaqobhpt | 0:c25c4b67b6a1 | 32 | bin_msg.add(theta); |
yaaqobhpt | 0:c25c4b67b6a1 | 33 | |
yaaqobhpt | 0:c25c4b67b6a1 | 34 | write_bytes(bin_msg.message, bin_msg.length()); |
yaaqobhpt | 0:c25c4b67b6a1 | 35 | } |