ISComm.h
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2020 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #ifndef IS_SIMPLE_INTERFACE_H
14 #define IS_SIMPLE_INTERFACE_H
15 
16 #include "data_sets.h"
17 #include "stddef.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
37 // -------------------------------------------------------------------------------------------------------------------------------
38 // Inertial Sense simple communications interface --------------------------------------------------------------------------------
39 // -------------------------------------------------------------------------------------------------------------------------------
40 // The simple comm interface does not require any of the com manager APIs and is designed for simple or lightweight scenarios, tiny embedded platforms, etc.
41 // *****************************************************************************
42 // ****** Binary messages ******
43 // *****************************************************************************
44 
46 #define _DID_INS_ECEF_QE2B DID_INS_4
47 #define _DID_INS_LLA_EULER_NED DID_INS_1
48 #define _DID_INS_LLA_QN2B DID_INS_3
51 #define _DID_IMU_DUAL DID_DUAL_IMU
52 #define _DID_IMU_PREINTEGRATED_IMU DID_PREINTEGRATED_IMU
55 #define _DID_GPS1_POS DID_GPS1_POS
58 #define _DID_MAG_CAL DID_MAG_CAL
59 #define _DID_MAGNETOMETER_1 DID_MAGNETOMETER_1
60 #define _DID_MAGNETOMETER_2 DID_MAGNETOMETER_2
61 #define _DID_BAROMETER DID_BAROMETER
62 #define _DID_WHEEL_ENCODER DID_WHEEL_ENCODER
63 #define _DID_POS_MEASUREMENT DID_POSITION_MEASUREMENT
66 #define _DID_DEV_INFO DID_DEV_INFO
67 #define _DID_BIT DID_BIT
68 #define _DID_STROBE_IN_TIME DID_STROBE_IN_TIME
71 #define _DID_FLASH_CONFIG DID_FLASH_CONFIG
72 #define _DID_RMC DID_RMC
75 typedef enum
76 {
78  _PTYPE_PARSE_ERROR = 0xFFFFFFFF,
82  _PTYPE_ASCII_NMEA = 0xBFFFFFFF,
83  _PTYPE_UBLOX = 0xAFFFFFFF,
84  _PTYPE_RTCM3 = 0x9FFFFFFF,
86 
88 #define IS_COM_BAUDRATE_DEFAULT IS_BAUDRATE_921600
89 
91 #define MAX_DATASET_SIZE 1024
92 
94 #define PKT_OVERHEAD_SIZE 8 // = START_BYTE + INFO_BYTE + COUNTER_BYTE + FLAGS_BYTE + CHECKSUM_BYTE_1 + CHECKSUM_BYTE_2 + CHECKSUM_BYTE_3 + END_BYTE
95 
97 #ifndef PKT_BUF_SIZE
98 #define PKT_BUF_SIZE 2048
99 #endif
100 
102 #define MAX_PKT_OVERHEAD_SIZE (PKT_OVERHEAD_SIZE + PKT_OVERHEAD_SIZE - 2) // worst case for packet encoding header / footer
103 
105 #define MAX_PKT_BODY_SIZE (((PKT_BUF_SIZE - MAX_PKT_OVERHEAD_SIZE) / 2) & 0xFFFFFFFE) // worst case for packet encoding body, rounded down to even number
106 
108 #define MAX_P_DATA_BODY_SIZE (MAX_PKT_BODY_SIZE-sizeof(p_data_hdr_t)) // Data size limit
109 
111 #define MAX_P_ACK_BODY_SIZE (MAX_PKT_BODY_SIZE-sizeof(p_ack_hdr_t)) // Ack data size
112 
114 #define CHECKSUM_SEED 0x00AAAAAA
115 
118 // Major (in com_manager.h)
119 #define PROTOCOL_VERSION_CHAR0 (1)
120 
121 // version 1: initial release
122 // version 2: 24 bit checksum support
123 #define PROTOCOL_VERSION_CHAR1 (2)
124 
125 // Minor (in data_sets.h)
126 // #define PROTOCOL_VERSION_CHAR2 0
127 // #define PROTOCOL_VERSION_CHAR3 0
128 
129 #define UBLOX_HEADER_SIZE 6
130 #define RTCM3_HEADER_SIZE 3
131 
134 
136 typedef enum
137 {
146 
148 } baud_rate_t;
149 
151 extern const unsigned int g_validBaudRates[IS_BAUDRATE_COUNT];
152 
153 /*
154 Packet Overview
155 
156 Byte
157 0 Packet start byte
158 1 Packet indo: ID (mask 0x1F) | reserved bits (mask 0xE)
159 2 Packet counter (for ACK and retry)
160 3 Packet flags
161 
162 // packet body, may or may not exist depending on packet id - packet body is made up of 4 byte or 8 byte values.
163 4-7 Data identifier
164 8-11 Data length
165 12-15 Data offset
166 16-19 Data start
167 (n-8)-(n-5) Last piece of data
168 // end data
169 
170 n-4 Reserved
171 n-3 Checksum high byte
172 n-2 Checksum low byte
173 n-1 Packet end byte
174 */
175 
176 // Packet IDs
177 typedef uint32_t ePacketIDs;
178 
179 #define PID_INVALID (ePacketIDs)0
180 #define PID_ACK (ePacketIDs)1
181 #define PID_NACK (ePacketIDs)2
182 #define PID_GET_DATA (ePacketIDs)3
183 #define PID_DATA (ePacketIDs)4
184 #define PID_SET_DATA (ePacketIDs)5
185 #define PID_STOP_BROADCASTS_ALL_PORTS (ePacketIDs)6
186 #define PID_STOP_DID_BROADCAST (ePacketIDs)7
187 #define PID_STOP_BROADCASTS_CURRENT_PORT (ePacketIDs)8
188 #define PID_COUNT (ePacketIDs)9
189 #define PID_MAX_COUNT (ePacketIDs)32
192 typedef struct
193 {
195  uint32_t size;
196 
198  uint8_t buf[PKT_BUF_SIZE];
199 } buffer_t;
200 
202 typedef struct
203 {
205  uint8_t *ptr;
206 
208  uint32_t size;
209 } bufPtr_t;
210 
212 typedef struct
213 {
215  uint8_t *txPtr;
216 
218  uint8_t *rxPtr;
219 
221  uint32_t size;
222 } bufTxRxPtr_t;
223 
225 typedef enum
226 {
229 
232 
235 
238 } asciiDataType;
239 
241 #define ASCII_MESSAGEID_TO_UINT(c4) ((uint32_t)(c4)[0] << 24 | ((uint32_t)(c4)[1] << 16) | ((uint32_t)(c4)[2] << 8) | ((uint32_t)(c4)[3]))
242 
244 {
245  // bit set for little endian, bit cleared for big endian
248 
249  // has any valid packet been received
251 
252  // multi-packet data set
254 
255  // Allow for arbitrary length in bytes of data, not necessarily multiple of 4. Don't auto-swap bytes for endianness
257 
258  // Checksum is the new 24 bit algorithm instead of the old 16 bit algorithm
260 };
261 
270 {
273 
276 
279 
281  PSC_END_BYTE = 0xFE,
282 
285 
288 
291 
294 };
295 
297 typedef struct
298 {
300  unsigned char messageId[4];
301 
303  uint8_t* ptr;
304 
306  int ptrSize;
307 
310 
312  uint16_t* fieldsAndOffsets;
314 
316 typedef struct
317 {
319  uint8_t startByte;
320 
322  uint8_t pid;
323 
325  uint8_t counter;
326 
334  uint8_t flags;
335 } packet_hdr_t;
336 
338 typedef struct
339 {
341  uint8_t cksum3;
342 
344  uint8_t cksum2;
345 
347  uint8_t cksum1;
348 
350  uint8_t stopByte;
351 } packet_ftr_t;
352 
354 typedef struct
355 {
358 
361 } packet_t;
362 
364 typedef struct
365 {
366  packet_hdr_t hdr; // Packet header
367  bufPtr_t bodyHdr; // Body header
368  bufPtr_t txData; // Pointer and size of data to send
369 } pkt_info_t;
370 
372 typedef struct
373 {
375  uint32_t id;
376 
378  uint32_t size;
379 
381  uint32_t offset;
382 } p_data_hdr_t;
383 
385 typedef struct
386 {
389 
391  uint8_t buf[MAX_DATASET_SIZE];
393 
395 typedef struct
396 {
398  uint32_t id;
399 
401  uint32_t size;
402 
404  uint32_t offset;
405 
411 } p_data_get_t;
412 
414 typedef struct
415 {
417  uint32_t id;
419 
421 typedef struct
422 {
424  uint32_t pktInfo;
425 
427  uint32_t pktCounter;
428 } p_ack_hdr_t;
429 
431 typedef struct
432 {
435 
437  union
438  {
439  uint8_t buf[sizeof(p_data_hdr_t)];
441  } body;
442 } p_ack_t, p_nack_t;
443 
444 typedef struct
445 {
447  uint8_t* start;
448 
450  uint8_t* end;
451 
453  uint32_t size;
454 
456  uint8_t* head;
457 
459  uint8_t* tail;
460 
462  uint8_t* scan;
463 
465 
466 typedef struct
467 {
469  uint8_t enableISB;
470 
472  uint8_t enableASCII;
473 
475  uint8_t enableUblox;
476 
478  uint8_t enableRTCM3;
480 
482 typedef struct
483 {
489 
492 
494  uint32_t txPktCount;
495 
497  uint32_t rxErrorCount;
498 
500  uint32_t hasStartByte;
501 
503  int32_t parseState;
504 
507 
509  uint8_t* dataPtr;
510 
512  uint8_t* pktPtr;
513 
515  uint8_t* altDecodeBuf;
516 
518  uint32_t ackNeeded;
519 
522 
524 
526 POP_PACK
527 
532 void is_comm_init(is_comm_instance_t* instance, uint8_t *buffer, int bufferSize);
533 
566 protocol_type_t is_comm_parse_byte(is_comm_instance_t* instance, uint8_t byte);
567 
607 
613 int is_comm_free(is_comm_instance_t* instance);
614 
625 int is_comm_get_data(is_comm_instance_t* instance, uint32_t dataId, uint32_t offset, uint32_t size, uint32_t periodMultiple);
626 
634 int is_comm_get_data_rmc(is_comm_instance_t* instance, uint64_t rmcBits);
635 
646 int is_comm_set_data(is_comm_instance_t* instance, uint32_t dataId, uint32_t offset, uint32_t size, void* data);
647 
651 int is_comm_data(is_comm_instance_t* instance, uint32_t dataId, uint32_t offset, uint32_t size, void* data);
652 
659 
666 
667 
668 // -------------------------------------------------------------------------------------------------------------------------------
669 // Common packet encode / decode functions
670 // -------------------------------------------------------------------------------------------------------------------------------
671 // common encode / decode for com manager and simple interface
672 int is_encode_binary_packet(void* srcBuffer, unsigned int srcBufferLength, packet_hdr_t* hdr, uint8_t additionalPktFlags, void* encodedPacket, int encodedPacketLength);
673 int is_decode_binary_packet(packet_t *pkt, unsigned char* pbuf, int pbufSize);
674 int is_decode_binary_packet_byte(uint8_t** _ptrSrc, uint8_t** _ptrDest, uint32_t* checksum, uint32_t shift);
675 void is_decode_binary_packet_footer(packet_ftr_t* ftr, uint8_t* ptrSrc, uint8_t** ptrSrcEnd, uint32_t* checksum);
676 void is_enable_packet_encoding(int enabled); // default is enabled
677 
678 unsigned int calculate24BitCRCQ(unsigned char* buffer, unsigned int len);
679 unsigned int getBitsAsUInt32(const unsigned char* buffer, unsigned int pos, unsigned int len);
680 
682 char copyDataPToStructP(void *sptr, const p_data_t *data, const unsigned int maxsize);
683 
685 char copyDataPToStructP2(void *sptr, const p_data_hdr_t *dataHdr, const uint8_t *dataBuf, const unsigned int maxsize);
686 
688 char is_comm_copy_to_struct(void *sptr, const is_comm_instance_t *com, const unsigned int maxsize);
689 
690 #ifdef __cplusplus
691 }
692 #endif
693 
694 #endif // IS_SIMPLE_INTERFACE_H
uint8_t enableISB
Definition: ISComm.h:469
char copyDataPToStructP2(void *sptr, const p_data_hdr_t *dataHdr, const uint8_t *dataBuf, const unsigned int maxsize)
Definition: ISComm.c:989
bufPtr_t body
Definition: ISComm.h:360
int is_comm_stop_broadcasts_current_port(is_comm_instance_t *instance)
Definition: ISComm.c:654
packet_hdr_t hdr
Definition: ISComm.h:366
uint8_t startByte
Definition: ISComm.h:319
uint8_t * txPtr
Definition: ISComm.h:215
void is_enable_packet_encoding(int enabled)
Definition: ISComm.c:1002
unsigned int calculate24BitCRCQ(unsigned char *buffer, unsigned int len)
Definition: ISComm.c:21
uint8_t * ptr
Definition: ISComm.h:303
uint8_t * end
Definition: ISComm.h:450
asciiDataType
Definition: ISComm.h:225
uint32_t id
Definition: ISComm.h:375
uint32_t size
Definition: ISComm.h:378
is_comm_config_t config
Definition: ISComm.h:491
uint8_t enableASCII
Definition: ISComm.h:472
int is_comm_free(is_comm_instance_t *instance)
Definition: ISComm.c:462
uint8_t cksum1
Definition: ISComm.h:347
uint32_t size
Definition: ISComm.h:208
int is_comm_stop_broadcasts_all_ports(is_comm_instance_t *instance)
Definition: ISComm.c:644
int is_decode_binary_packet(packet_t *pkt, unsigned char *pbuf, int pbufSize)
Definition: ISComm.c:900
uint8_t enableRTCM3
Definition: ISComm.h:478
uint8_t enableUblox
Definition: ISComm.h:475
#define PKT_BUF_SIZE
Definition: ISComm.h:98
int32_t parseState
Definition: ISComm.h:503
packet_hdr_t hdr
Definition: ISComm.h:357
#define PUSH_PACK_1
Definition: ISConstants.h:231
bufPtr_t bodyHdr
Definition: ISComm.h:367
uint32_t pktInfo
Definition: ISComm.h:424
bufPtr_t txData
Definition: ISComm.h:368
unsigned int getBitsAsUInt32(const unsigned char *buffer, unsigned int pos, unsigned int len)
Definition: ISComm.c:74
uint8_t stopByte
Definition: ISComm.h:350
uint32_t offset
Definition: ISComm.h:404
char is_comm_copy_to_struct(void *sptr, const is_comm_instance_t *com, const unsigned int maxsize)
Definition: ISComm.c:1008
int is_comm_data(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, void *data)
Definition: ISComm.c:639
uint32_t pktCounter
Definition: ISComm.h:427
p_ack_hdr_t hdr
Definition: ISComm.h:434
protocol_type_t is_comm_parse_byte(is_comm_instance_t *instance, uint8_t byte)
Definition: ISComm.c:499
p_data_hdr_t dataHdr
Definition: ISComm.h:440
is_comm_buffer_t buf
Definition: ISComm.h:488
uint32_t size
Definition: ISComm.h:453
POP_PACK void is_comm_init(is_comm_instance_t *instance, uint8_t *buffer, int bufferSize)
Definition: ISComm.c:185
int is_comm_get_data_rmc(is_comm_instance_t *instance, uint64_t rmcBits)
Definition: ISComm.c:605
ePktHdrFlags
Definition: ISComm.h:243
uint32_t size
Definition: ISComm.h:221
uint8_t * pktPtr
Definition: ISComm.h:512
const unsigned int g_validBaudRates[IS_BAUDRATE_COUNT]
Definition: ISComm.c:84
uint8_t cksum2
Definition: ISComm.h:344
ePktSpecialChars
Definition: ISComm.h:269
uint32_t id
Definition: ISComm.h:417
uint8_t * rxPtr
Definition: ISComm.h:218
uint8_t * start
Definition: ISComm.h:447
struct p_data_t p_data_set_t
uint32_t hasStartByte
Definition: ISComm.h:500
int is_comm_get_data(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, uint32_t periodMultiple)
Definition: ISComm.c:588
int is_encode_binary_packet(void *srcBuffer, unsigned int srcBufferLength, packet_hdr_t *hdr, uint8_t additionalPktFlags, void *encodedPacket, int encodedPacketLength)
Definition: ISComm.c:791
char copyDataPToStructP(void *sptr, const p_data_t *data, const unsigned int maxsize)
Definition: ISComm.c:975
p_data_hdr_t hdr
Definition: ISComm.h:388
uint32_t ackNeeded
Definition: ISComm.h:518
uint32_t rxErrorCount
Definition: ISComm.h:497
uint8_t * tail
Definition: ISComm.h:459
uint16_t * fieldsAndOffsets
Definition: ISComm.h:312
uint32_t id
Definition: ISComm.h:398
USBInterfaceDescriptor data
uint8_t * scan
Definition: ISComm.h:462
uint8_t pid
Definition: ISComm.h:322
int is_decode_binary_packet_byte(uint8_t **_ptrSrc, uint8_t **_ptrDest, uint32_t *checksum, uint32_t shift)
Definition: ISComm.c:761
baud_rate_t
Definition: ISComm.h:136
uint32_t size
Definition: ISComm.h:195
uint32_t ePacketIDs
Definition: ISComm.h:177
struct p_ack_t p_nack_t
void is_decode_binary_packet_footer(packet_ftr_t *ftr, uint8_t *ptrSrc, uint8_t **ptrSrcEnd, uint32_t *checksum)
Definition: ISComm.c:704
uint32_t txPktCount
Definition: ISComm.h:494
p_data_hdr_t dataHdr
Definition: ISComm.h:506
uint8_t cksum3
Definition: ISComm.h:341
#define POP_PACK
Definition: ISConstants.h:234
uint8_t * head
Definition: ISComm.h:456
protocol_type_t
Definition: ISComm.h:75
uint8_t * ptr
Definition: ISComm.h:205
uint8_t * altDecodeBuf
Definition: ISComm.h:515
packet_t pkt
Definition: ISComm.h:521
uint8_t flags
Definition: ISComm.h:334
protocol_type_t is_comm_parse(is_comm_instance_t *instance)
Definition: ISComm.c:514
uint32_t bc_period_multiple
Definition: ISComm.h:410
uint32_t offset
Definition: ISComm.h:381
#define MAX_DATASET_SIZE
Definition: ISComm.h:91
uint8_t counter
Definition: ISComm.h:325
int is_comm_set_data(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, void *data)
Definition: ISComm.c:634
uint32_t size
Definition: ISComm.h:401
uint8_t * dataPtr
Definition: ISComm.h:509


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:04