MBot Software Library  v1.0
An API documentation to mbot_firmware repository
common.h
1 /*
2 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3  This file contains global IO structs, common definitions, and common functions that much of ROS Serial depends on.
4  Notes:
5  *RPI_IN_MSG --> RPI_IN_LENG?
6  *PICO_IN_MSG --> PICO_IN_LENG?
7 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
8 */
9 
19 #include <stdio.h>
20 #include <stdint.h>
21 // #include <memory.h>
22 #include <string.h>
23 #include <pico/binary_info.h>
24 
25 #ifndef COMMONS_H
26 #define COMMONS_H
27 
28 // definitions
29 #define SYNC_FLAG 0xff //beginning of packet sync flag
30 #define VERSION_FLAG 0xfe //version flag compatible with ROS2
31 
32 #define ROS_HEADER_LENGTH 7
33 #define ROS_FOOTER_LENGTH 1
34 #define ROS_PKG_LENGTH (ROS_HEADER_LENGTH + ROS_FOOTER_LENGTH) //length (in bytes) of ros packaging (header and footer)
35 
36 // specific checksum method as defined by http://wiki.ros.org/rosserial/Overview/Protocol
37 uint8_t checksum(uint8_t* addends, int len);
38 
39 // converts an array of four uint8_t members to an int32_t
40 int32_t bytes_to_int32(uint8_t bytes[4]);
41 
42 // converts an int32_t to an array of four uint8_t members
43 uint8_t* int32_to_bytes(int32_t i32t);
44 
45 // decodes a complete ROS packet into bytes array 'MSG' and uint16 topic as defined by http://wiki.ros.org/rosserial/Overview/Protocol
46 int decode_rospkt(uint8_t* ROSPKT, int rospkt_len, uint16_t* TOPIC, uint8_t* MSG, int msg_len);
47 
48 // encodes a message and topic into a bytes array 'ROSPKT' as defined by http://wiki.ros.org/rosserial/Overview/Protocol
49 int encode_msg(uint8_t* MSG, int msg_len, uint16_t TOPIC, uint8_t* ROSPKT, int rospkt_len);
50 
51 #endif