test_com_manager.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <deque>
3 #include "../com_manager.h"
4 #include "../ring_buffer.h"
5 #include "../protocol_nmea.h"
6 
7 
8 #if 0
9 extern "C"
10 {
11 #include "../../../libs-int/rtklib/src/rtklib.h"
12  extern gtime_t g_gps_latest_time;
13  extern int decode_rtcm3(rtcm_t *rtcm);
14  extern int decode_ubx(raw_t* raw, int doChecksum);
15 }
16 #endif
17 
18 #define TEST_PROTO_IS 1
19 #define TEST_PROTO_ASCII 1
20 #define TEST_PROTO_UBLOX 1
21 #define TEST_PROTO_RTCM3 1
22 
23 #define TASK_PERIOD_MS 1 // 1 KHz
24 #if 0
25 #define DEBUG_PRINTF printf
26 #else
27 #define DEBUG_PRINTF
28 #endif
29 
30 #define PORT_BUFFER_SIZE 8192
31 
32 typedef struct
33 {
35  com_manager_status_t cmBufStatus[NUM_COM_PORTS] = { 0 };
36  broadcast_msg_t cmBufBcastMsg[MAX_NUM_BCAST_MSGS] = { 0 };
37  struct
38  {
42  } msgs = { 0 };
43 
44  // Used to simulate serial ports
46  uint8_t portRxBuffer[PORT_BUFFER_SIZE];
48  uint8_t portTxBuffer[PORT_BUFFER_SIZE];
49 } test_data_t;
50 
51 typedef struct
52 {
53  protocol_type_t ptype; // Data start byte
54  uint32_t did;
55  union
56  {
57  uint8_t buf[PKT_BUF_SIZE];
58  uDatasets set;
59  } data;
60  uint32_t size; // size of data
61  uint32_t pktSize; // size of encoded packet (pkt header, data header, data, pkt footer)
63 
65 std::deque<data_holder_t> g_testRxDeque;
66 std::deque<data_holder_t> g_testTxDeque;
67 
68 
69 int portRead(CMHANDLE cmHandle, int pHandle, unsigned char* buf, int len)
70 {
71  return ringBufRead(&tcm.portRxBuf, buf, len);
72 }
73 
74 int portWrite(CMHANDLE cmHandle, int pHandle, unsigned char* buf, int len)
75 {
76  if (ringBufWrite(&tcm.portTxBuf, buf, len))
77  { // Buffer overflow
78  DEBUG_PRINTF("tcm.portTxBuf ring buffer overflow: %d !!!\n", ringBufUsed(&tcm.portTxBuf) + len);
79  EXPECT_TRUE(false);
80  }
81  return len;
82 }
83 
84 void postRxRead(CMHANDLE cmHandle, int pHandle, p_data_t* dataRead)
85 {
86  data_holder_t td = g_testRxDeque.front();
87  g_testRxDeque.pop_front();
88 
89  DEBUG_PRINTF("[%2d] postRxRead() DID: %3d, size: %3d\n", (int)g_testRxDeque.size(), td.did, td.size);
90 
91  EXPECT_EQ(td.did, dataRead->hdr.id);
92  EXPECT_EQ(td.size, dataRead->hdr.size);
93  EXPECT_TRUE(memcmp(&td.data, dataRead->buf, td.size)==0);
94 }
95 
96 void disableBroadcasts(CMHANDLE cmHandle, int pHandle)
97 {
98 }
99 
100 int prepDevInfo(CMHANDLE cmHandle, int pHandle)
101 {
102  return 1;
103 }
104 
105 void writeNvrUserpageFlashCfg(CMHANDLE cmHandle, int pHandle, p_data_t* data)
106 {
107 }
108 
109 // return 1 on success, 0 on failure
110 int msgHandlerAscii(CMHANDLE cmHandle, int pHandle, const uint8_t* msg, int msgSize)
111 {
112  int messageIdUInt = ASCII_MESSAGEID_TO_UINT(msg + 1);
113 // comWrite(pHandle, line, lineLength); // echo back
114 // time_delay(50); // give time for the echo to come back
115 
116  if (msgSize == 10)
117  { // 4 character commands (i.e. "$STPB*14\r\n")
118  switch (messageIdUInt)
119  {
120  case ASCII_MSG_ID_ASCB: // query ASCII message broadcast rates
121  // writeAsciiBcastPeriod(cmHandle, pHandle, NULLPTR);
122  break;
123 
124  case ASCII_MSG_ID_STPB: // stop all broadcasts on all ports
125  disableBroadcasts(cmHandle, -1);
126  break;
127 
128  case ASCII_MSG_ID_STPC: // stop all broadcasts on current port
129  disableBroadcasts(cmHandle, pHandle);
130  break;
131 
132  case ASCII_MSG_ID_BLEN: // bootloader enable
133  break;
134 
135  case ASCII_MSG_ID_SRST: // soft reset
136  break;
137 
138  case ASCII_MSG_ID_INFO: // query device version information
139  break;
140 
141  case ASCII_MSG_ID_PERS: // Save persistent messages to flash memory
142  break;
143  }
144  }
145  else
146  { // General ASCII messages
147  switch (messageIdUInt)
148  {
149  case ASCII_MSG_ID_NELB: // SAM bootloader assistant (SAM-BA) enable
150 // if (msgSize == 22 && // 16 character commands (i.e. "$NELB,!!SAM-BA!!\0*58\r\n")
151 // (pHandle == COM0_PORT_NUM || pHandle == USB_PORT_NUM) &&
152 // strncmp((const char*)(msg + 6), "!!SAM-BA!!", 6) == 0)
153 // {
154 // }
155  break;
156  }
157  }
158 
159  data_holder_t td = g_testRxDeque.front();
160  g_testRxDeque.pop_front();
161  uint8_t buf[30] = {};
162  memcpy(buf, msg, (msgSize<29?msgSize:29));
163  DEBUG_PRINTF("[%2d] asciiMessageHandler() size: %3d, %.30s...\n", (int)g_testRxDeque.size(), msgSize, buf);
164 
165  EXPECT_EQ(td.size, msgSize);
166  EXPECT_TRUE(memcmp(&td.data, msg, td.size) == 0);
167 
168  return 0;
169 }
170 
171 
172 int msgHandlerUblox(CMHANDLE cmHandle, int pHandle, const uint8_t* msg, int msgSize)
173 {
174  data_holder_t td = g_testRxDeque.front();
175  g_testRxDeque.pop_front();
176  DEBUG_PRINTF("[%2d] ubloxMessageHandler() size: %3d, (0x%02x 0x%02x)\n", (int)g_testRxDeque.size(), msgSize, msg[2], msg[3]);
177 
178  EXPECT_EQ(td.size, msgSize);
179  EXPECT_TRUE(memcmp(&td.data, msg, td.size) == 0);
180 
181 #if 0
182  raw_t raw = {};
183  obsd_t obsData[100];
184  raw.obs.data = obsData;
185  raw.obs.nmax = raw.obs.n = 100;
186  raw.buff = (unsigned char*)msg;
187  raw.len = msgSize;
188 
189  int j = 0;
190  switch (decode_ubx(&raw, 0))
191  {
192  case DATA_TYPE_OBSERVATION:
193  case DATA_TYPE_EPHEMERIS:
194  case DATA_TYPE_SBS:
195  case DATA_TYPE_ANTENNA_POSITION:
196  case DATA_TYPE_ION_UTC_ALMANAC:
197  j = 2;
198  break;
199 
200  default:
201  case DATA_TYPE_ERROR:
202  j = 5;
203  break;
204  }
205 #endif
206 
207  return 0;
208 }
209 
210 
211 int msgHandlerRtcm3(CMHANDLE cmHandle, int pHandle, const uint8_t* msg, int msgSize)
212 {
213  data_holder_t td = g_testRxDeque.front();
214  g_testRxDeque.pop_front();
215  DEBUG_PRINTF("[%2d] rtcm3MessageHandler() size: %3d, (0x%02x 0x%02x 0x%02x 0x%02x)\n", (int)g_testRxDeque.size(), msgSize, msg[0], msg[1], msg[2], msg[3]);
216 
217  EXPECT_EQ(td.size, msgSize);
218  EXPECT_TRUE(memcmp(&td.data, msg, td.size) == 0);
219 
220 #if 0
221  rtcm_t raw = {};
222  obsd_t obsData[100];
223  raw.obs.data = obsData;
224  raw.obs.nmax = raw.obs.n = 100;
225  raw.buff = (unsigned char*)msg;
226  raw.len = msgSize;
227 
228  int j = 0;
229  switch (decode_rtcm3(&raw))
230  {
231  case DATA_TYPE_OBSERVATION:
232  case DATA_TYPE_EPHEMERIS:
233  case DATA_TYPE_SBS:
234  case DATA_TYPE_ANTENNA_POSITION:
235  case DATA_TYPE_ION_UTC_ALMANAC:
236  j = 2;
237  break;
238 
239  default:
240  case DATA_TYPE_ERROR:
241  j = 5;
242  break;
243  }
244 #endif
245 
246  return 0;
247 }
248 
249 
250 #define NUM_HANDLES 1
252 static uint8_t s_comm_buffer[NUM_HANDLES*PKT_BUF_SIZE] = { 0 };
254 
256 {
257  // Init ComManager
258  com_manager_init_t cmInit = {};
259  cmInit.broadcastMsg = t.cmBufBcastMsg;
260  cmInit.broadcastMsgSize = sizeof(t.cmBufBcastMsg);
261  if (comManagerInitInstance(&(t.cm), NUM_HANDLES, 0, TASK_PERIOD_MS, 0, portRead, portWrite, 0, postRxRead, 0, disableBroadcasts, &cmInit, &s_cmPort))
262  { // Fail to init
263  return false;
264  }
265 
268 
270 
271  // Enable/disable protocols
272  s_cmPort.comm.config.enableISB = TEST_PROTO_IS;
276 
277  return true;
278 }
279 
281 {
282  // Init Port Buffers
283  ringBufInit(&(t.portTxBuf), t.portTxBuffer, sizeof(t.portTxBuffer), 1);
284  ringBufInit(&(t.portRxBuf), t.portRxBuffer, sizeof(t.portRxBuffer), 1);
285 
286  return initComManager(t);
287 }
288 
289 
290 void generateData(std::deque<data_holder_t> &testDeque)
291 {
292  testDeque.clear();
293  int byteSize = 0;
294 
295  DEBUG_PRINTF("=============== generateData() ===============\n");
296 
297  // Generate data and add to test deque
298  for (int i = 0; ; i++)
299  {
300  data_holder_t td = {};
301  ins_1_t ins1 = { 0 };
302  gps_pos_t gps = { 0 };
303 
304  int j = i % 17;
305  switch (j)
306  {
307  case 0:
308  case 1:
309  case 2:
310  case 3:
311  // INS 1
312  ins1.timeOfWeek = (double)i;
313  ins1.week = i;
314  ins1.insStatus = i;
315  ins1.hdwStatus = i;
316  ins1.theta[0] = i * 2.0f;
317  ins1.theta[1] = i * 3.0f;
318  ins1.theta[2] = i * 4.0f;
319  ins1.uvw[0] = i * 5.0f;
320  ins1.uvw[1] = i * 6.0f;
321  ins1.uvw[2] = i * 7.0f;
322  ins1.lla[0] = 40.330565516;
323  ins1.lla[1] = -111.725787806;
324  ins1.lla[2] = 1408.565264;
325  ins1.ned[0] = i * 1.234f;
326  ins1.ned[1] = i * 2.345f;
327  ins1.ned[2] = i * 3.456f;
328 
329  if (j == 3 )
330  { // ASCII
331 #if TEST_PROTO_ASCII
333  td.size = ins1_to_nmea_pins1((char*)td.data.buf, sizeof(td.data.buf), ins1);
334 #endif
335  }
336  else
337  { // Binary
338 #if TEST_PROTO_IS
339  td.did = DID_INS_1;
341  td.data.set.ins1 = ins1;
342  td.size = sizeof(ins_1_t);
343 #endif
344  }
345  break;
346 
347  case 4:
348  case 5: // GPS
349  gps.timeOfWeekMs = i * 1000;
350  gps.week = i * 10;
351  gps.status = i;
352  gps.ecef[0] = (double)i*1.234;
353  gps.ecef[1] = (double)i*2.345;
354  gps.ecef[2] = (double)i*3.456;
355  gps.lla[0] = (double)i*1.234;
356  gps.lla[1] = (double)i*2.345;
357  gps.lla[2] = (double)i*3.456;
358  gps.hAcc = (float)i;
359  gps.cnoMean = (float)i;
360  gps.hMSL = (float)i;
361  gps.pDop = (float)i;
362  gps.towOffset = (double)i*123.4;
363  gps.leapS = (uint8_t)i;
364 
365  if ((j == 5 || TEST_PROTO_IS == 0) && TEST_PROTO_ASCII)
366  { // ASCII
367 #if TEST_PROTO_ASCII
369  td.size = gps_to_nmea_gga((char*)td.data.buf, sizeof(td.data.buf), gps);
370 #endif
371  }
372  else
373  { // Binary
374 #if TEST_PROTO_IS
375  td.did = DID_GPS1_POS;
377  td.data.set.gpsPos = gps;
378  td.size = sizeof(gps_pos_t);
379 #endif
380  }
381  break;
382 
383 #if TEST_PROTO_ASCII
384  case 6: // ASCII command - Stop all broadcasts
386  td.size = snprintf((char*)td.data.buf, PKT_BUF_SIZE, "$STPB*15\r\n");
387  break;
388 
389  case 7: // ASCII command - Stop broadcast on current port
391  td.size = snprintf((char*)td.data.buf, PKT_BUF_SIZE, "$STPC*14\r\n");
392  break;
393 #endif
394 
395 #if TEST_PROTO_UBLOX
396 
397  case 8: // Ublox - UBX-NAV-POSLLH (0x01 0x02)
398  td.ptype = _PTYPE_UBLOX;
399  td.size = 36;
400  {
401  uint8_t buf[] = { 0xb5,0x62,0x1,0x2,0x1c,0x0,0x0,0xa1,0xad,0x10,0x6a,0xff,0x67,0xbd,0xb7,0xf4,0x9,0x18,0x35,0x7e,0x15,0x0,0xe8,0xc5,0x15,0x0,0x4f,0x1,0x0,0x0,0xa8,0x1,0x0,0x0,0x59,0xbc };
402  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
403  }
404  break;
405 
406  case 9: // Ublox - UBX-RXM-RAWX (0x02 0x15)
407  td.ptype = _PTYPE_UBLOX;
408  td.size = 952;
409  {
410  uint8_t buf[] = { 0xb5,0x62,0x2,0x15,0xb0,0x3,0x1b,0x2f,0xdd,0x24,0x1b,0x14,0x11,0x41,0x2b,0x8,0x12,0x1d,0x1,0x1,0x82,0x9,0x5d,0x61,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x25,0xa7,0xcf,0x6f,0x70,0x41,0x4e,0x82,0x95,0x5c,0xc,0x98,0x95,0x41,0x8e,0x1c,0x91,0xc4,0x0,0x2,0x0,0x0,0xf4,0xfb,0x2c,0x5,0x1,0x8,0x7,0x0,0x15,0x97,0x78,0xd7,0x1c,0x13,0x72,0x41,0x93,0xcc,0x58,0x82,0xc9,0x1c,0x98,0x41,0xae,0x75,0xae,0xc4,0x6,0x2,0x0,0x3,0xf4,0xfb,0x2a,0x5,0x1,0x8,0xf,0x0,0x71,0x2d,0xf8,0xb7,0xdd,0x23,0x72,0x41,0xd,0xbb,0xcd,0x6b,0x34,0x40,0x98,0x41,0xe1,0xa1,0x38,0x45,0x6,0x14,0x0,0x9,0xf4,0xfb,0x1e,0x8,0x3,0x8,0xf,0x0,0xba,0x40,0xb0,0xd2,0x7d,0x56,0x76,0x41,0xd7,0x44,0xd7,0xff,0xb7,0x58,0x9d,0x41,0x16,0x2f,0x35,0xc5,0x2,0x1b,0x0,0x0,0xf4,0xfb,0x24,0x5,0x1,0x8,0x7,0x0,0x36,0xb9,0xcd,0x0,0x91,0x19,0x74,0x41,0xf2,0xd,0x57,0x62,0x8,0x68,0x9a,0x41,0x8c,0x29,0xb7,0x44,0x0,0x1f,0x0,0x0,0xf4,0xfb,0x29,0x5,0x1,0x8,0xf,0x0,0xfe,0x54,0xb5,0xd5,0x99,0x2e,0x70,0x41,0xa0,0x27,0x9e,0x1c,0x5e,0x98,0x95,0x41,0x7,0x51,0xe5,0xc4,0x6,0x12,0x0,0x4,0xf4,0xfb,0x2c,0x5,0x1,0x8,0xf,0x0,0xd7,0x76,0x9,0xb8,0xcd,0xe7,0x6e,0x41,0x92,0x38,0xc7,0xe,0x19,0x4d,0x94,0x41,0x50,0x98,0x5a,0xc4,0x0,0xc,0x0,0x0,0xf4,0xfb,0x30,0x5,0x1,0x8,0xf,0x0,0xa7,0xd5 };
411  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
412  }
413  break;
414 
415  case 10: // Ublox - UBX-NAV-POSLLH (0x01 0x02)
416  td.ptype = _PTYPE_UBLOX;
417  td.size = 36;
418  {
419  uint8_t buf[] = { 0xb5,0x62,0x1,0x2,0x1c,0x0,0x90,0xa2,0xad,0x10,0x6a,0xff,0x67,0xbd,0xb7,0xf4,0x9,0x18,0x35,0x7e,0x15,0x0,0xdf,0xc5,0x15,0x0,0x4f,0x1,0x0,0x0,0xa8,0x1,0x0,0x0,0xe1,0x2b };
420  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
421  }
422  break;
423 
424  case 11: // Ublox - UBX-RXM-RAWX (0x02 0x15)
425  td.ptype = _PTYPE_UBLOX;
426  td.size = 952;
427  {
428  uint8_t buf[] = { 0xb5,0x62,0x2,0x15,0xb0,0x3,0x81,0x95,0x43,0x8b,0x19,0x14,0x11,0x41,0x2b,0x8,0x12,0x1d,0x1,0x1,0xf2,0x7,0x6f,0x1f,0x77,0xfd,0xab,0xb,0x80,0x41,0xa0,0xcc,0x14,0x85,0x7d,0x14,0xa5,0x41,0x78,0x85,0x9c,0x43,0x1,0x85,0x0,0x0,0xf4,0xfb,0x2c,0x5,0x1,0x8,0xf,0x0,0x17,0xbd,0xc5,0x8d,0x69,0xc,0x83,0x41,0x12,0x42,0x8c,0xca,0x6d,0x6,0xa9,0x41,0x44,0xfc,0xc,0x44,0x5,0x2,0x0,0x0,0xf4,0xfb,0x25,0x6,0x1,0x8,0x7,0x0,0xae,0xc2,0xb4,0xd1,0x41,0x9f,0x70,0x41,0x2c,0xb7,0xc2,0x5e,0x62,0xd6,0x95,0x41,0x4e,0x22,0x31,0x45,0x0,0x5,0x0,0x0,0xf4,0xfb,0x30,0x5,0x1,0x8,0x7,0x0,0x94,0x60,0x66,0xa8,0xf7,0xa6,0x73,0x41,0x9d,0xff,0x92,0x27,0x7b,0xd1,0x99,0x41,0x8f,0xca,0x25,0xc5,0x0,0x13,0x0,0x0,0xf4,0xfb,0x27,0x5,0x1,0x8,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0,0x7a,0x48,0xde,0xfa,0x97,0x19,0x74,0x41,0xd1,0x34,0xaf,0x8a,0x11,0x68,0x9a,0x41,0xf2,0x33,0xb7,0x44,0x0,0x1f,0x0,0x0,0xf4,0xfb,0x29,0x5,0x1,0x8,0xf,0x0,0xc3,0x4c,0xbf,0x3c,0x91,0x2e,0x70,0x41,0xf1,0x6c,0xab,0xa5,0x52,0x98,0x95,0x41,0x8c,0x45,0xe5,0xc4,0x6,0x12,0x0,0x4,0xf4,0xfb,0x2c,0x5,0x1,0x8,0xf,0x0,0x5e,0xee,0x27,0x65,0xc5,0xe7,0x6e,0x41,0xe8,0xc4,0xd,0x98,0x13,0x4d,0x94,0x41,0x33,0x7d,0x5a,0xc4,0x0,0xc,0x0,0x0,0xf4,0xfb,0x30,0x5,0x1,0x8,0xf,0x0,0x9c,0x9a };
429  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
430  }
431  break;
432 #endif
433 
434 #if TEST_PROTO_RTCM3
435  case 12: // RTCM3 (0x19 0x3e)
436  td.ptype = _PTYPE_RTCM3;
437  td.size = 31;
438  {
439  uint8_t buf[] = { 0xd3,0x0,0x19,0x3e,0xfc,0x2f,0x14,0x41,0x44,0x56,0x4e,0x55,0x4c,0x4c,0x41,0x4e,0x54,0x45,0x4e,0x4e,0x41,0x20,0x20,0x4e,0x4f,0x4e,0x45,0x0,0xc4,0xe,0xe1 };
440  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
441  }
442  break;
443 
444  case 13: // RTCM3 (0x48 0x40)
445  td.ptype = _PTYPE_RTCM3;
446  td.size = 78;
447  {
448  uint8_t buf[] = { 0xd3,0x0,0x48,0x40,0x9c,0x2f,0x14,0x41,0x44,0x56,0x4e,0x55,0x4c,0x4c,0x41,0x4e,0x54,0x45,0x4e,0x4e,0x41,0x20,0x20,0x4e,0x4f,0x4e,0x45,0x0,0x0,0xd,0x54,0x52,0x49,0x4d,0x42,0x4c,0x45,0x20,0x4e,0x45,0x54,0x52,0x39,0x14,0x4e,0x61,0x76,0x20,0x34,0x2e,0x36,0x32,0x20,0x2f,0x20,0x42,0x6f,0x6f,0x74,0x20,0x34,0x2e,0x36,0x32,0xa,0x35,0x33,0x32,0x39,0x4b,0x34,0x34,0x33,0x35,0x32,0xfc,0xca,0x3f };
449  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
450  }
451  break;
452 
453  case 14: // RTCM3 (0x13 0x3e)
454  td.ptype = _PTYPE_RTCM3;
455  td.size = 25;
456  {
457  uint8_t buf[] = { 0xd3,0x0,0x13,0x3e,0xdc,0x2f,0x3,0x7b,0xcd,0x79,0xd5,0x47,0x35,0x77,0x5f,0x93,0x4d,0x49,0x8f,0xf1,0xb3,0x1d,0xff,0x10,0x3d };
458  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
459  }
460  break;
461 
462  case 15: // RTCM3 (0x3a 0x44)
463  td.ptype = _PTYPE_RTCM3;
464  td.size = 320;
465  {
466  uint8_t buf[] = { 0xd3,0x1,0x3a,0x44,0x7c,0x2f,0x52,0x3,0x6c,0x22,0x0,0x20,0x34,0x98,0x0,0xc0,0x0,0x0,0x0,0x0,0x4,0x0,0x88,0x80,0x7f,0xff,0xff,0xff,0xac,0x2a,0xad,0x29,0xa9,0xa7,0xa6,0xa7,0x80,0x0,0x0,0x0,0x6e,0x64,0x72,0xc7,0x4a,0xea,0x56,0xa3,0x32,0xfe,0xc0,0x1,0x0,0x4,0x0,0x10,0x0,0x40,0x1,0x0,0x4,0x0,0x10,0x0,0x3,0xf7,0x8,0x96,0x12,0x90,0x23,0xd7,0x25,0xbe,0x66,0xbc,0xd0,0x79,0xb9,0xc,0xbb,0x1b,0x5e,0x37,0x74,0x6d,0xe2,0x1d,0x94,0x45,0xc8,0xa2,0x51,0x5d,0xe3,0x3a,0xc6,0x81,0x8d,0xbb,0x19,0x8e,0x7b,0x5c,0xf3,0xd9,0xf1,0xf3,0xe0,0x6c,0x46,0xde,0x85,0xbd,0x4f,0x7c,0x1f,0x4,0x9e,0x16,0xfc,0x44,0xb8,0x81,0xff,0xff,0xf5,0xff,0xff,0x8f,0xff,0xeb,0xc0,0x0,0x15,0x7f,0xfe,0xe5,0xff,0xfa,0x28,0x0,0x11,0xdf,0xff,0xde,0x7f,0xfe,0xd8,0x0,0x1,0xcf,0xff,0xeb,0xdf,0xff,0xf1,0xff,0xff,0x8,0x0,0x6,0x10,0x0,0x6,0x3f,0xff,0x9c,0x80,0x0,0x47,0xff,0xfe,0xf0,0x0,0x14,0xff,0xff,0xa6,0x0,0x1,0x29,0xff,0xfc,0x58,0x0,0x9,0x0,0x0,0x56,0xff,0xff,0xe5,0xff,0xfb,0x50,0x0,0x12,0x3f,0xff,0xcc,0xff,0xff,0x2b,0xff,0xfb,0x17,0xff,0xfa,0x3f,0xff,0xf1,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x59,0x5e,0x15,0x61,0x6e,0xb7,0x55,0x66,0x35,0xd5,0x56,0x36,0xd9,0x5e,0x36,0x59,0x56,0x15,0xe3,0x7e,0xf8,0x65,0x87,0x19,0x40,0x0,0x80,0x1,0x0,0x2,0x0,0x4,0x0,0x8,0x0,0x10,0x0,0x20,0x0,0x40,0x0,0x80,0x1,0x0,0x2,0x0,0x4,0x0,0x8,0x0,0x10,0x0,0x20,0x0,0x40,0x0,0x80,0x1,0x0,0x2,0x0,0x4,0x0,0x8,0x0,0x10,0x0,0x20,0x0,0x40,0x0,0x80,0x1,0x0,0x2,0x0,0x4,0x0,0x8,0x0,0x10,0x0,0x20,0x0,0x0,0x1d,0x23,0x6c };
467  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
468  }
469  break;
470 
471  case 16: // RTCM3 (0xcc 0x43)
472  td.ptype = _PTYPE_RTCM3;
473  td.size = 210;
474  {
475  uint8_t buf[] = { 0xd3,0x0,0xcc,0x43,0xdc,0x2f,0x82,0x2f,0xc0,0xe2,0x0,0x20,0x4,0x3,0x41,0x0,0x0,0x0,0x0,0x0,0x30,0xc0,0x0,0x0,0x7f,0xff,0xfa,0x4a,0x1a,0x22,0x2a,0x54,0x3,0xdd,0x28,0xec,0x62,0x15,0xe,0xbb,0x90,0x0,0x40,0x1,0x0,0x4,0x0,0x10,0x0,0x75,0x28,0xea,0x45,0xd6,0x33,0xac,0x20,0x91,0x41,0x1d,0xa2,0x6b,0x84,0xcc,0xed,0x28,0xda,0xb,0xb5,0xc3,0x6b,0x87,0x2f,0x3e,0x57,0x1c,0xe3,0x79,0xd9,0x10,0xec,0x21,0xaa,0x47,0xa0,0x90,0xdf,0xff,0xfb,0x5f,0xff,0xee,0x7f,0xff,0xaf,0xff,0xfe,0xaf,0xff,0xfa,0xdf,0xff,0xea,0x0,0x1,0xa2,0x0,0x6,0x68,0x0,0xf,0x40,0x0,0x41,0x0,0x0,0x5c,0x0,0x1,0x68,0x0,0x14,0x9f,0xff,0xaf,0x0,0x1,0x2e,0x0,0x4,0xc0,0x0,0x13,0xe0,0x0,0x52,0x0,0x1,0x8a,0x0,0x6,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5f,0x75,0x96,0x67,0x96,0x38,0x65,0x8d,0xd7,0x5f,0x75,0x95,0xd9,0x64,0xd2,0xc0,0x0,0x80,0x1,0x0,0x2,0x0,0x4,0x0,0x8,0x0,0x10,0x0,0x20,0x0,0x40,0x0,0x80,0x1,0x0,0x2,0x0,0x4,0x0,0x8,0x0,0x10,0x0,0x20,0x0,0x40,0x0,0x80,0x1,0x0,0x2,0x0,0x0,0x9d,0xc4,0x6a };
476  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
477  }
478  break;
479 #endif
480  }
481 
482  if (td.size)
483  {
484  DEBUG_PRINTF("[%2d] ", (int)testDeque.size());
485  switch (td.ptype)
486  {
487  case PSC_START_BYTE:
488  DEBUG_PRINTF("DID: %3d, size: %3d\n", td.did, td.size);
489  break;
490  case _PTYPE_ASCII_NMEA:
491  DEBUG_PRINTF("NMEA: %.30s...\n", td.data.buf);
492  break;
493  case _PTYPE_UBLOX:
494  DEBUG_PRINTF("UBLOX: size %d, (0x%02x 0x%02x)\n", td.size, td.data.buf[2], td.data.buf[3]);
495  break;
496  case _PTYPE_RTCM3:
497  DEBUG_PRINTF("RTCM3: size %d, (%02x %02x %02x %02x)\n", td.size, td.data.buf[0], td.data.buf[1], td.data.buf[2], td.data.buf[3]);
498  break;
499  }
500 
501  if (byteSize + td.size < (PORT_BUFFER_SIZE*3)/4) // Allow room for packet headers
502  {
503  byteSize += td.size;
504 
505  // Add data to deque
506  testDeque.push_back(td);
507  }
508  else
509  { // Buffer is full
510  return;
511  }
512  }
513  }
514 }
515 
516 
517 void addDequeToRingBuf(std::deque<data_holder_t> &testDeque, ring_buf_t *rbuf)
518 {
519  is_comm_instance_t comm;
520  uint8_t comm_buffer[2048] = { 0 };
521  is_comm_init(&comm, comm_buffer, sizeof(comm_buffer));
522 
523  int k=0;
524 
525  for (int i = 0; i < testDeque.size(); i++)
526  {
527  data_holder_t &td = testDeque[i];
528  int n = 0;
529 
530  // Add packetized data to ring buffer
531  switch (td.ptype)
532  {
534  // Packetize data
535  n = is_comm_data(&comm, td.did, 0, td.size, (void*)&(td.data));
536  td.pktSize = n;
537  EXPECT_FALSE(ringBufWrite(rbuf, comm.buf.start, n));
538  break;
539 
540  case _PTYPE_ASCII_NMEA:
541  case _PTYPE_UBLOX:
542  case _PTYPE_RTCM3:
543  td.pktSize = td.size;
544  EXPECT_FALSE(ringBufWrite(rbuf, td.data.buf, td.size));
545  break;
546  }
547  }
548 
549  // Buffer overflow not allowed for test
550  ASSERT_TRUE(ringBufFree(rbuf));
551 }
552 
553 
554 void parseDataPortTxBuf(std::deque<data_holder_t> &testDeque, test_data_t &t)
555 {
556  is_comm_instance_t comm;
557  uint8_t comm_buffer[2048] = { 0 };
558  is_comm_init(&comm, comm_buffer, sizeof(comm_buffer));
559  unsigned char c;
560  protocol_type_t ptype;
561  uDatasets dataWritten;
562 
563  while (ringBufUsed(&t.portTxBuf)>0)
564  {
565  ringBufRead(&t.portTxBuf, &c, 1);
566 
567  if((ptype = is_comm_parse_byte(&comm, c)) != _PTYPE_NONE)
568  {
569  data_holder_t td = testDeque.front();
570  testDeque.pop_front();
571 
572  switch (ptype)
573  {
575  // Found data
576  DEBUG_PRINTF("Found data: did %3d, size %3d\n", comm.dataHdr.id, comm.dataHdr.size);
577 
578  is_comm_copy_to_struct(&dataWritten, &comm, sizeof(uDatasets));
579 
580  EXPECT_EQ(td.did, comm.dataHdr.id);
581  break;
582 
583  case _PTYPE_UBLOX:
584  case _PTYPE_RTCM3:
585  break;
586 
587  case _PTYPE_ASCII_NMEA:
588  DEBUG_PRINTF("Found data: %.30s...\n", comm.dataPtr);
589  break;
590  }
591 
592  EXPECT_EQ(td.size, comm.dataHdr.size);
593  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, td.size) == 0);
594  }
595  }
596 }
597 
598 
599 void ringBuftoRingBufWrite(ring_buf_t *dst, ring_buf_t *src, int len)
600 {
601  uint8_t *buf = new uint8_t[len];
602 
603  len = ringBufRead(src, buf, len);
604  EXPECT_FALSE(ringBufWrite(dst, buf, len));
605 }
606 
607 
608 #if 1
609 TEST(ComManager, BasicTxTest)
610 {
611  // Initialize Com Manager
612  init(tcm);
613 
614  // Generate and add data to deque
616 
617  // Use Com Manager to send deque data to Tx port ring buffer
618  for(int i=0; i<g_testTxDeque.size(); i++)
619  {
621 
622  // Send data - writes data to tcm.txBuf
623  switch (td.ptype)
624  {
625  default: // IS binary
626  comManagerSendDataNoAckInstance(&tcm.cm, 0, td.did, &td.data, td.size, 0);
627  break;
628 
629  case _PTYPE_ASCII_NMEA:
630  case _PTYPE_UBLOX:
631  case _PTYPE_RTCM3:
632  portWrite(&(tcm.cm), 0, td.data.buf, td.size);
633  break;
634  }
635 
636  }
637 
638  // Test that data parsed from Tx port matches deque data
640 
641  // Check that we got all data
642  EXPECT_TRUE(g_testTxDeque.empty());
643  EXPECT_TRUE(ringBufUsed(&tcm.portTxBuf) == 0);
644 }
645 #endif
646 
647 
648 #if 1
649 TEST(ComManager, BasicRxTest)
650 {
651  // Initialize Com Manager
652  init(tcm);
653 
654  // Generate and add data to deque
656 
657  // Add deque data to Rx port ring buffer
659 
660  DEBUG_PRINTF("=============== Checking Data. Size: %d ===============\n", ringBufUsed(&tcm.portRxBuf));
661 
662  while (!ringBufEmpty(&tcm.portRxBuf))
663  {
664  // Step Com Manager and check that was received correctly inside postRxRead()
665  comManagerStepInstance(&tcm.cm); // 2048 byte limit each step
666  }
667 
668  // Check that no data was left behind
669  EXPECT_TRUE(g_testRxDeque.empty());
670  EXPECT_TRUE(ringBufUsed(&tcm.portRxBuf) == 0);
671 }
672 #endif
673 
674 
675 #if 1
676 // Tests that ComManager handles segmented serial data properly
677 TEST(ComManager, SegmentedRxTest)
678 {
679  ring_buf_t tmpRBuf;
680  uint8_t buffer[8192];
681 
682  // Initialize temporary ring buffer
683  ringBufInit(&tmpRBuf, buffer, sizeof(buffer), 1);
684 
685  // Initialize Com Manager
686  init(tcm);
687 
688  // Generate and add data to deque
690 
691  // Add deque data to temporary ring buffer
692  addDequeToRingBuf(g_testRxDeque, &tmpRBuf);
693 
694  DEBUG_PRINTF("Checking Data:\n");
695 
696  // Divide data written to Com Manager into pieces
697 #define TIMES_TO_DIVIDE_DATA 10
698  int bytesToWrite = ringBufUsed(&tmpRBuf) / TIMES_TO_DIVIDE_DATA;
699  while (!ringBufEmpty(&tmpRBuf) && !g_testRxDeque.empty())
700  {
701  // Partial write of data
702  ringBuftoRingBufWrite(&tcm.portRxBuf, &tmpRBuf, bytesToWrite);
703 
704  while (!ringBufEmpty(&tcm.portRxBuf))
705  {
706  // Step Com Manager and check that was received correctly inside postRxRead()
709  }
710  }
711 
712  // Check that no data was left behind
713  EXPECT_TRUE(g_testRxDeque.empty());
714  EXPECT_TRUE(ringBufEmpty(&tcm.portRxBuf));
715 }
716 #endif
717 
718 
719 #if 1
720 TEST(ComManager, RxWithGarbageTest)
721 {
722  // Initialize Com Manager
723  init(tcm);
724 
725  // Generate and add data to deque
727 
728  // Insert garbage
729  std::deque<data_holder_t> testRxDequeWithGarbage;
730  data_holder_t td = {};
731  td.size = 24;
732  td.data.buf[1] = 128;
733  td.data.buf[19] = 128;
734  td.data.buf[23] = 128;
735 
736  for (int i = 0; i < g_testRxDeque.size(); i++)
737  {
738  if (i % 5 == 0)
739  {
740  // Insert garbage data
741  testRxDequeWithGarbage.push_back(td);
742  }
743 
744  // Copy good data
745  testRxDequeWithGarbage.push_back(g_testRxDeque[i]);
746  }
747 
748  // Add deque data to Rx port ring buffer
749  addDequeToRingBuf(testRxDequeWithGarbage, &tcm.portRxBuf);
750 
751  DEBUG_PRINTF("=============== Checking Data. Size: %d ===============\n", ringBufUsed(&tcm.portRxBuf));
752 
753  while (!ringBufEmpty(&tcm.portRxBuf))
754  {
755  // Step Com Manager and check that was received correctly inside postRxRead()
756  comManagerStepInstance(&tcm.cm); // 2048 byte limit each step
757  }
758 
759  // Check that no data was left behind
760  EXPECT_TRUE(g_testRxDeque.empty());
761  EXPECT_TRUE(ringBufUsed(&tcm.portRxBuf) == 0);
762 }
763 #endif
764 
765 
766 #if 1
767 TEST(ComManager, Evb2AltDecodeBufferTest)
768 {
769  // This test ensures that packets can be read and decoded to the alternate buffer (not in the default comm.buf.start buffer).
770 
771  // Init Port Buffers
772  ringBufInit(&(tcm.portTxBuf), tcm.portTxBuffer, sizeof(tcm.portTxBuffer), 1);
773  ringBufInit(&(tcm.portRxBuf), tcm.portRxBuffer, sizeof(tcm.portRxBuffer), 1);
774  initComManager(tcm);
775 
776  is_comm_instance_t &comm = (tcm.cm.ports[0].comm);
777  uint8_t altDecodBuf[PKT_BUF_SIZE] = {};
778  comm.altDecodeBuf = altDecodBuf;
779 
780  // Generate and add data to deque
782 
783  // Add deque data to Rx port ring buffer
785 
786  DEBUG_PRINTF("=============== Checking Data. Size: %d ===============\n", ringBufUsed(&tcm.portRxBuf));
787 
788  while (!ringBufEmpty(&tcm.portRxBuf))
789  {
790  // Get available size of comm buffer
791  int n = is_comm_free(&comm);
792 
793  // Read 5 bytes at a time
794  n = _MIN(n, 5);
795 
796  // Read data directly into comm buffer
797  if ((n = ringBufRead(&tcm.portRxBuf, comm.buf.tail, n)))
798  {
799  // Update comm buffer tail pointer
800  comm.buf.tail += n;
801 
803  uDatasets dataWritten;
804 
805  // Search comm buffer for valid packets
806  while ((ptype = is_comm_parse(&comm)) != _PTYPE_NONE)
807  {
808  uint8_t error = 0;
809  uint8_t *dataPtr = comm.dataPtr + comm.dataHdr.offset;
810  uint32_t dataSize = comm.dataHdr.size;
811 
812  data_holder_t td = g_testRxDeque.front();
813  g_testRxDeque.pop_front();
814 
815  switch (ptype)
816  {
818  // Found data
819  DEBUG_PRINTF("Found data: did %3d, size %3d\n", comm.dataHdr.id, comm.dataHdr.size);
820 
821  is_comm_copy_to_struct(&dataWritten, &comm, sizeof(uDatasets));
822 
823  EXPECT_EQ(td.did, comm.dataHdr.id);
824  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size)==0);
825  break;
826 
827  case _PTYPE_UBLOX:
828  case _PTYPE_RTCM3:
829  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
830  break;
831 
832  case _PTYPE_ASCII_NMEA:
833  DEBUG_PRINTF("Found data: %.30s...\n", comm.dataPtr);
834  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
835  break;
836 
837  default:
838  EXPECT_TRUE(false);
839  break;
840  }
841  }
842  }
843 
844  }
845 
846  // Check that no data was left behind
847  EXPECT_TRUE(g_testRxDeque.empty());
848  EXPECT_TRUE(ringBufUsed(&tcm.portRxBuf) == 0);
849 }
850 #endif
851 
852 
853 
854 #if 1
855 TEST(ComManager, Evb2DataForwardTest)
856 {
857  // This test ensures that packets can be read, decoded, and forwarded for EVB-2 com_bridge without corrupting the data.
858 
859  // Init Port Buffers
860  ringBufInit(&(tcm.portTxBuf), tcm.portTxBuffer, sizeof(tcm.portTxBuffer), 1);
861  ringBufInit(&(tcm.portRxBuf), tcm.portRxBuffer, sizeof(tcm.portRxBuffer), 1);
862  initComManager(tcm);
863 
864  is_comm_instance_t &comm = (tcm.cm.ports[0].comm);
865  uint8_t altDecodBuf[PKT_BUF_SIZE] = {};
866  comm.altDecodeBuf = altDecodBuf;
867 
868  // Generate and add data to deque
870 
871  ring_buf_t evbRbuf;
872  uint8_t evbRBuffer[PORT_BUFFER_SIZE] = {};
873  ringBufInit(&evbRbuf, evbRBuffer, PORT_BUFFER_SIZE, 1);
874 
875  // Add deque data to EVB port ring buffer
876  addDequeToRingBuf(g_testRxDeque, &evbRbuf);
877 
878 
879  DEBUG_PRINTF("=============== EVB input Data. Size: %d ===============\n", ringBufUsed(&evbRbuf));
880 
881  int originalRingBufferUsed = ringBufUsed(&evbRbuf);
882 
883  std::deque<data_holder_t> testRxDequeCopy = g_testRxDeque;
884 
885  while (!ringBufEmpty(&evbRbuf))
886  {
887  // Get available size of comm buffer
888  int n = is_comm_free(&comm);
889 
890  // Read 5 bytes at a time
891  n = _MIN(n, 5);
892 
893  // Read data directly into comm buffer
894  if ((n = ringBufRead(&evbRbuf, comm.buf.tail, n)))
895  {
896  // Update comm buffer tail pointer
897  comm.buf.tail += n;
898 
900 
901  // Search comm buffer for valid packets
902  while ((ptype = is_comm_parse(&comm)) != _PTYPE_NONE)
903  {
904  uint8_t error = 0;
905  uint8_t *dataPtr = comm.dataPtr + comm.dataHdr.offset;
906  uint32_t dataSize = comm.dataHdr.size;
907 
908  data_holder_t td = testRxDequeCopy.front();
909  testRxDequeCopy.pop_front();
910 
911  switch (ptype)
912  {
914  case _PTYPE_ASCII_NMEA:
915  case _PTYPE_UBLOX:
916  case _PTYPE_RTCM3:
917  {
918  uint32_t pktSize = (uint32_t)_MIN(comm.buf.scan - comm.pktPtr, PKT_BUF_SIZE);
919  ringBufWrite(&tcm.portRxBuf, comm.pktPtr, pktSize);
920 
921  if (td.pktSize != pktSize)
922  {
923  ASSERT_TRUE(false);
924  }
925  }
926  break;
927 
928  default:
929  ASSERT_TRUE(false);
930  }
931  }
932  }
933  }
934 
935  int forwardRingBufferUsed = ringBufUsed(&tcm.portRxBuf);
936  ASSERT_TRUE(forwardRingBufferUsed == originalRingBufferUsed);
937 
938 
939  DEBUG_PRINTF("=============== Checking Data. Size: %d ===============\n", ringBufUsed(&tcm.portRxBuf));
940 
941  while (!ringBufEmpty(&tcm.portRxBuf))
942  {
943  // Get available size of comm buffer
944  int n = is_comm_free(&comm);
945 
946  // Read 5 bytes at a time
947  n = _MIN(n, 5);
948 
949  // Read data directly into comm buffer
950  if ((n = ringBufRead(&tcm.portRxBuf, comm.buf.tail, n)))
951  {
952  // Update comm buffer tail pointer
953  comm.buf.tail += n;
954 
956  uDatasets dataWritten;
957 
958  // Search comm buffer for valid packets
959  while ((ptype = is_comm_parse(&comm)) != _PTYPE_NONE)
960  {
961  uint8_t error = 0;
962  uint8_t *dataPtr = comm.dataPtr + comm.dataHdr.offset;
963  uint32_t dataSize = comm.dataHdr.size;
964 
965  data_holder_t td = g_testRxDeque.front();
966  g_testRxDeque.pop_front();
967 
968  switch (ptype)
969  {
971  // Found data
972  DEBUG_PRINTF("Found data: did %3d, size %3d\n", comm.dataHdr.id, comm.dataHdr.size);
973 
974  is_comm_copy_to_struct(&dataWritten, &comm, sizeof(uDatasets));
975 
976  EXPECT_EQ(td.did, comm.dataHdr.id);
977  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
978  break;
979 
980  case _PTYPE_UBLOX:
981  case _PTYPE_RTCM3:
982  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
983  break;
984 
985  case _PTYPE_ASCII_NMEA:
986  DEBUG_PRINTF("Found data: %.30s...\n", comm.dataPtr);
987  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
988  break;
989 
990  default:
991  EXPECT_TRUE(false);
992  break;
993  }
994  }
995  }
996 
997  }
998 
999  // Check that no data was left behind
1000  EXPECT_TRUE(g_testRxDeque.empty());
1001  EXPECT_TRUE(ringBufUsed(&tcm.portRxBuf) == 0);
1002 }
1003 #endif
1004 
std::deque< data_holder_t > g_testRxDeque
void parseDataPortTxBuf(std::deque< data_holder_t > &testDeque, test_data_t &t)
#define _MIN(a, b)
Definition: ISConstants.h:298
gps_pos_t gpsPos
Definition: data_sets.h:3540
uint8_t enableISB
Definition: ISComm.h:470
void postRxRead(CMHANDLE cmHandle, int pHandle, p_data_t *dataRead)
void comManagerSetCallbacksInstance(CMHANDLE cmInstance, pfnComManagerAsapMsg handlerRmc, pfnComManagerGenMsgHandler handlerAscii, pfnComManagerGenMsgHandler handlerUblox, pfnComManagerGenMsgHandler handlerRtcm3)
Definition: com_manager.c:462
double towOffset
Definition: data_sets.h:787
int ringBufUsed(const ring_buf_t *rbuf)
This function returns the number of bytes currently in ring buffer.
Definition: ring_buffer.c:43
struct PACKED gps_pos_t
f_t f[DEBUG_F_ARRAY_SIZE]
Definition: data_sets.h:2106
static com_manager_port_t s_cmPort
uint8_t leapS
Definition: data_sets.h:790
ins_1_t ins1
Definition: data_sets.h:3528
uint32_t id
Definition: ISComm.h:376
is_can_uvw uvw
Definition: CAN_comm.h:257
#define DID_INS_1
Definition: data_sets.h:38
uint32_t size
Definition: ISComm.h:379
is_comm_config_t config
Definition: ISComm.h:492
uint8_t enableASCII
Definition: ISComm.h:473
bool initComManager(test_data_t &t)
broadcast_msg_t * broadcastMsg
Definition: com_manager.h:102
protocol_type_t ptype
obsd_t obs[MAX_OBSERVATION_COUNT_IN_RTK_MESSAGE]
Definition: data_sets.h:2883
uGpsRawData data
Definition: data_sets.h:2920
bool init(test_data_t &t)
uint8_t enableRTCM3
Definition: ISComm.h:479
void comManagerRegisterInstance(CMHANDLE cmInstance_, uint32_t dataId, pfnComManagerPreSend txFnc, pfnComManagerPostRead pstRxFnc, const void *txDataPtr, void *rxDataPtr, int dataSize, uint8_t pktFlags)
Definition: com_manager.c:252
uint8_t enableUblox
Definition: ISComm.h:476
#define TEST_PROTO_RTCM3
float timeOfWeekMs
Definition: CAN_comm.h:29
#define PKT_BUF_SIZE
Definition: ISComm.h:98
struct PACKED ins_1_t
#define DID_DEV_INFO
Definition: data_sets.h:35
union data_holder_t::@45 data
void addDequeToRingBuf(std::deque< data_holder_t > &testDeque, ring_buf_t *rbuf)
protocol_type_t is_comm_parse_byte(is_comm_instance_t *instance, uint8_t byte)
Definition: ISComm.c:499
#define NULL
Definition: nm_bsp.h:52
char is_comm_copy_to_struct(void *sptr, const is_comm_instance_t *instance, const unsigned int maxsize)
Definition: ISComm.c:1008
#define DEBUG_PRINTF
ascii_msgs_t asciiMsgs
uint8_t portTxBuffer[PORT_BUFFER_SIZE]
uint32_t week
Definition: CAN_comm.h:26
int msgHandlerAscii(CMHANDLE cmHandle, int pHandle, const uint8_t *msg, int msgSize)
int portRead(CMHANDLE cmHandle, int pHandle, unsigned char *buf, int len)
com_manager_port_t * ports
Definition: com_manager.h:215
int comManagerInitInstance(CMHANDLE cmHandle, int numHandles, int maxEnsuredPackets, int stepPeriodMilliseconds, int retryCount, pfnComManagerRead readFnc, pfnComManagerSend sendFnc, pfnComManagerSendBufferAvailableBytes txFreeFnc, pfnComManagerPostRead pstRxFnc, pfnComManagerPostAck pstAckFnc, pfnComManagerDisableBroadcasts disableBcastFnc, com_manager_init_t *buffers, com_manager_port_t *cmPorts)
Definition: com_manager.c:111
ring_buf_t portTxBuf
void ringBufInit(ring_buf_t *rbuf, unsigned char *buf, int bufSize, int wordByteSize)
Initialize ring buffer pointers.
Definition: ring_buffer.c:29
int portWrite(CMHANDLE cmHandle, int pHandle, unsigned char *buf, int len)
double timeOfWeek
Definition: data_sets.h:417
float hMSL
Definition: data_sets.h:772
#define TEST_PROTO_UBLOX
is_comm_buffer_t buf
Definition: ISComm.h:489
void ringBuftoRingBufWrite(ring_buf_t *dst, ring_buf_t *src, int len)
void disableBroadcasts(CMHANDLE cmHandle, int pHandle)
int ins1_to_nmea_pins1(char a[], const int aSize, ins_1_t &ins1)
float pDop
Definition: data_sets.h:781
int is_comm_free(is_comm_instance_t *instance)
Definition: ISComm.c:462
#define NUM_COM_PORTS
Definition: data_sets.h:1256
uint8_t * pktPtr
Definition: ISComm.h:513
int msgHandlerRtcm3(CMHANDLE cmHandle, int pHandle, const uint8_t *msg, int msgSize)
uint32_t hdwStatus
Definition: CAN_comm.h:40
uint32_t cnoMean
Definition: CAN_comm.h:226
#define TEST_PROTO_ASCII
static is_comm_instance_t s_comm[NUM_HANDLES]
void * CMHANDLE
Definition: com_manager.h:119
#define DID_FLASH_CONFIG
Definition: data_sets.h:46
uint32_t broadcastMsgSize
Definition: com_manager.h:103
uint8_t * start
Definition: ISComm.h:448
is_comm_instance_t comm
Definition: com_manager.h:174
uint8_t portRxBuffer[PORT_BUFFER_SIZE]
dev_info_t devInfo
#define PORT_BUFFER_SIZE
double lla[3]
Definition: data_sets.h:511
struct test_data_t::@44 msgs
std::deque< data_holder_t > g_testTxDeque
p_data_hdr_t hdr
Definition: ISComm.h:389
uint32_t status
Definition: CAN_comm.h:114
uint8_t * tail
Definition: ISComm.h:460
USBInterfaceDescriptor data
uint8_t * scan
Definition: ISComm.h:463
int ringBufRead(ring_buf_t *rbuf, unsigned char *buf, int len)
This function reads data from the ring buffer.
Definition: ring_buffer.c:136
int ringBufWrite(ring_buf_t *rb, unsigned char *buf, int numBytes)
This function writes data to the ring buffer.
Definition: ring_buffer.c:76
#define TEST_PROTO_IS
int comManagerSendDataNoAckInstance(CMHANDLE cmInstance, int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
Definition: com_manager.c:582
void is_comm_init(is_comm_instance_t *instance, uint8_t *buffer, int bufferSize)
Definition: ISComm.c:185
uint32_t insStatus
Definition: CAN_comm.h:37
#define DID_GPS1_POS
Definition: data_sets.h:47
float theta[3]
Definition: data_sets.h:505
TEST(ComManager, BasicTxTest)
#define MAX_NUM_BCAST_MSGS
Definition: com_manager.h:112
broadcast_msg_t cmBufBcastMsg[MAX_NUM_BCAST_MSGS]
int ringBufEmpty(const ring_buf_t *rbuf)
This function returns 1 if the buffer is empty, 0 if not empty.
Definition: ring_buffer.c:481
#define snprintf
Definition: test_suite.cpp:86
p_data_hdr_t dataHdr
Definition: ISComm.h:507
float ned[3]
Definition: data_sets.h:514
int gps_to_nmea_gga(char a[], const int aSize, gps_pos_t &pos)
#define ASCII_MESSAGEID_TO_UINT(c4)
Definition: ISComm.h:242
double ecef[3]
Definition: data_sets.h:420
#define TIMES_TO_DIVIDE_DATA
#define TASK_PERIOD_MS
protocol_type_t
Definition: ISComm.h:75
uint8_t * altDecodeBuf
Definition: ISComm.h:516
float hAcc
Definition: data_sets.h:775
int msgHandlerUblox(CMHANDLE cmHandle, int pHandle, const uint8_t *msg, int msgSize)
protocol_type_t is_comm_parse(is_comm_instance_t *instance)
Definition: ISComm.c:514
int is_comm_data(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, void *data)
Definition: ISComm.c:639
uint8_t buf[MAX_DATASET_SIZE]
Definition: ISComm.h:392
void generateData(std::deque< data_holder_t > &testDeque)
void writeNvrUserpageFlashCfg(CMHANDLE cmHandle, int pHandle, p_data_t *data)
nvm_flash_cfg_t nvmFlashCfg
static uint8_t s_comm_buffer[NUM_HANDLES *PKT_BUF_SIZE]
uint32_t offset
Definition: ISComm.h:382
com_manager_t cm
uint8_t buf[PKT_BUF_SIZE]
int ringBufFree(const ring_buf_t *rbuf)
This function returns the number of bytes free in UART Rx buffer. Important: Buffer size is one less ...
Definition: ring_buffer.c:61
test_data_t tcm
#define NUM_HANDLES
void comManagerStepInstance(CMHANDLE cmInstance_)
Definition: com_manager.c:287
ring_buf_t portRxBuf
int prepDevInfo(CMHANDLE cmHandle, int pHandle)
uint8_t * dataPtr
Definition: ISComm.h:510


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58