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 void prepDevInfo(CMHANDLE cmHandle, int pHandle)
101 {
102 }
103 
104 void writeNvrUserpageFlashCfg(CMHANDLE cmHandle, int pHandle, p_data_t* data)
105 {
106 }
107 
108 // return 1 on success, 0 on failure
109 int msgHandlerAscii(CMHANDLE cmHandle, int pHandle, const uint8_t* msg, int msgSize)
110 {
111  int messageIdUInt = ASCII_MESSAGEID_TO_UINT(msg + 1);
112 // comWrite(pHandle, line, lineLength); // echo back
113 // time_delay(50); // give time for the echo to come back
114 
115  if (msgSize == 10)
116  { // 4 character commands (i.e. "$STPB*14\r\n")
117  switch (messageIdUInt)
118  {
119  case ASCII_MSG_ID_ASCB: // query ASCII message broadcast rates
120  // writeAsciiBcastPeriod(cmHandle, pHandle, NULLPTR);
121  break;
122 
123  case ASCII_MSG_ID_STPB: // stop all broadcasts on all ports
124  disableBroadcasts(cmHandle, -1);
125  break;
126 
127  case ASCII_MSG_ID_STPC: // stop all broadcasts on current port
128  disableBroadcasts(cmHandle, pHandle);
129  break;
130 
131  case ASCII_MSG_ID_BLEN: // bootloader enable
132  break;
133 
134  case ASCII_MSG_ID_SRST: // soft reset
135  break;
136 
137  case ASCII_MSG_ID_INFO: // query device version information
138  break;
139 
140  case ASCII_MSG_ID_PERS: // Save persistent messages to flash memory
141  break;
142  }
143  }
144  else
145  { // General ASCII messages
146  switch (messageIdUInt)
147  {
148  case ASCII_MSG_ID_NELB: // SAM bootloader assistant (SAM-BA) enable
149 // if (msgSize == 22 && // 16 character commands (i.e. "$NELB,!!SAM-BA!!\0*58\r\n")
150 // (pHandle == COM0_PORT_NUM || pHandle == USB_PORT_NUM) &&
151 // strncmp((const char*)(msg + 6), "!!SAM-BA!!", 6) == 0)
152 // {
153 // }
154  break;
155  }
156  }
157 
158  data_holder_t td = g_testRxDeque.front();
159  g_testRxDeque.pop_front();
160  uint8_t buf[30] = {};
161  memcpy(buf, msg, (msgSize<29?msgSize:29));
162  DEBUG_PRINTF("[%2d] asciiMessageHandler() size: %3d, %.30s...\n", (int)g_testRxDeque.size(), msgSize, buf);
163 
164  EXPECT_EQ(td.size, msgSize);
165  EXPECT_TRUE(memcmp(&td.data, msg, td.size) == 0);
166 
167  return 0;
168 }
169 
170 
171 int msgHandlerUblox(CMHANDLE cmHandle, int pHandle, const uint8_t* msg, int msgSize)
172 {
173  data_holder_t td = g_testRxDeque.front();
174  g_testRxDeque.pop_front();
175  DEBUG_PRINTF("[%2d] ubloxMessageHandler() size: %3d, (0x%02x 0x%02x)\n", (int)g_testRxDeque.size(), msgSize, msg[2], msg[3]);
176 
177  EXPECT_EQ(td.size, msgSize);
178  EXPECT_TRUE(memcmp(&td.data, msg, td.size) == 0);
179 
180 #if 0
181  raw_t raw = {};
182  obsd_t obsData[100];
183  raw.obs.data = obsData;
184  raw.obs.nmax = raw.obs.n = 100;
185  raw.buff = (unsigned char*)msg;
186  raw.len = msgSize;
187 
188  int j = 0;
189  switch (decode_ubx(&raw, 0))
190  {
191  case DATA_TYPE_OBSERVATION:
192  case DATA_TYPE_EPHEMERIS:
193  case DATA_TYPE_SBS:
194  case DATA_TYPE_ANTENNA_POSITION:
195  case DATA_TYPE_ION_UTC_ALMANAC:
196  j = 2;
197  break;
198 
199  default:
200  case DATA_TYPE_ERROR:
201  j = 5;
202  break;
203  }
204 #endif
205 
206  return 0;
207 }
208 
209 
210 int msgHandlerRtcm3(CMHANDLE cmHandle, int pHandle, const uint8_t* msg, int msgSize)
211 {
212  data_holder_t td = g_testRxDeque.front();
213  g_testRxDeque.pop_front();
214  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]);
215 
216  EXPECT_EQ(td.size, msgSize);
217  EXPECT_TRUE(memcmp(&td.data, msg, td.size) == 0);
218 
219 #if 0
220  rtcm_t raw = {};
221  obsd_t obsData[100];
222  raw.obs.data = obsData;
223  raw.obs.nmax = raw.obs.n = 100;
224  raw.buff = (unsigned char*)msg;
225  raw.len = msgSize;
226 
227  int j = 0;
228  switch (decode_rtcm3(&raw))
229  {
230  case DATA_TYPE_OBSERVATION:
231  case DATA_TYPE_EPHEMERIS:
232  case DATA_TYPE_SBS:
233  case DATA_TYPE_ANTENNA_POSITION:
234  case DATA_TYPE_ION_UTC_ALMANAC:
235  j = 2;
236  break;
237 
238  default:
239  case DATA_TYPE_ERROR:
240  j = 5;
241  break;
242  }
243 #endif
244 
245  return 0;
246 }
247 
248 
249 #define NUM_HANDLES 1
251 static uint8_t s_comm_buffer[NUM_HANDLES*PKT_BUF_SIZE] = { 0 };
253 
255 {
256  // Init ComManager
257  com_manager_init_t cmInit = {};
258  cmInit.broadcastMsg = t.cmBufBcastMsg;
259  cmInit.broadcastMsgSize = sizeof(t.cmBufBcastMsg);
260  if (comManagerInitInstance(&(t.cm), NUM_HANDLES, 0, TASK_PERIOD_MS, 0, portRead, portWrite, 0, postRxRead, 0, disableBroadcasts, &cmInit, &s_cmPort))
261  { // Fail to init
262  return false;
263  }
264 
267 
269 
270  // Enable/disable protocols
271  s_cmPort.comm.config.enableISB = TEST_PROTO_IS;
275 
276  return true;
277 }
278 
280 {
281  // Init Port Buffers
282  ringBufInit(&(t.portTxBuf), t.portTxBuffer, sizeof(t.portTxBuffer), 1);
283  ringBufInit(&(t.portRxBuf), t.portRxBuffer, sizeof(t.portRxBuffer), 1);
284 
285  return initComManager(t);
286 }
287 
288 
289 void generateData(std::deque<data_holder_t> &testDeque)
290 {
291  testDeque.clear();
292  int byteSize = 0;
293 
294  DEBUG_PRINTF("=============== generateData() ===============\n");
295 
296  // Generate data and add to test deque
297  for (int i = 0; ; i++)
298  {
299  data_holder_t td = {};
300  ins_1_t ins1 = { 0 };
301  gps_pos_t gps = { 0 };
302 
303  int j = i % 17;
304  switch (j)
305  {
306  case 0:
307  case 1:
308  case 2:
309  case 3:
310  // INS 1
311  ins1.timeOfWeek = (double)i;
312  ins1.week = i;
313  ins1.insStatus = i;
314  ins1.hdwStatus = i;
315  ins1.theta[0] = i * 2.0f;
316  ins1.theta[1] = i * 3.0f;
317  ins1.theta[2] = i * 4.0f;
318  ins1.uvw[0] = i * 5.0f;
319  ins1.uvw[1] = i * 6.0f;
320  ins1.uvw[2] = i * 7.0f;
321  ins1.lla[0] = 40.330565516;
322  ins1.lla[1] = -111.725787806;
323  ins1.lla[2] = 1408.565264;
324  ins1.ned[0] = i * 1.234f;
325  ins1.ned[1] = i * 2.345f;
326  ins1.ned[2] = i * 3.456f;
327 
328  if (j == 3 )
329  { // ASCII
330 #if TEST_PROTO_ASCII
332  td.size = ins1_to_nmea_pins1((char*)td.data.buf, sizeof(td.data.buf), ins1);
333 #endif
334  }
335  else
336  { // Binary
337 #if TEST_PROTO_IS
338  td.did = DID_INS_1;
340  td.data.set.ins1 = ins1;
341  td.size = sizeof(ins_1_t);
342 #endif
343  }
344  break;
345 
346  case 4:
347  case 5: // GPS
348  gps.timeOfWeekMs = i * 1000;
349  gps.week = i * 10;
350  gps.status = i;
351  gps.ecef[0] = (double)i*1.234;
352  gps.ecef[1] = (double)i*2.345;
353  gps.ecef[2] = (double)i*3.456;
354  gps.lla[0] = (double)i*1.234;
355  gps.lla[1] = (double)i*2.345;
356  gps.lla[2] = (double)i*3.456;
357  gps.hAcc = (float)i;
358  gps.cnoMean = (float)i;
359  gps.hMSL = (float)i;
360  gps.pDop = (float)i;
361  gps.towOffset = (double)i*123.4;
362  gps.leapS = (uint8_t)i;
363 
364  if ((j == 5 || TEST_PROTO_IS == 0) && TEST_PROTO_ASCII)
365  { // ASCII
366 #if TEST_PROTO_ASCII
368  td.size = gps_to_nmea_gga((char*)td.data.buf, sizeof(td.data.buf), gps);
369 #endif
370  }
371  else
372  { // Binary
373 #if TEST_PROTO_IS
374  td.did = DID_GPS1_POS;
376  td.data.set.gpsPos = gps;
377  td.size = sizeof(gps_pos_t);
378 #endif
379  }
380  break;
381 
382 #if TEST_PROTO_ASCII
383  case 6: // ASCII command - Stop all broadcasts
385  td.size = snprintf((char*)td.data.buf, PKT_BUF_SIZE, "$STPB*15\r\n");
386  break;
387 
388  case 7: // ASCII command - Stop broadcast on current port
390  td.size = snprintf((char*)td.data.buf, PKT_BUF_SIZE, "$STPC*14\r\n");
391  break;
392 #endif
393 
394 #if TEST_PROTO_UBLOX
395 
396  case 8: // Ublox - UBX-NAV-POSLLH (0x01 0x02)
397  td.ptype = _PTYPE_UBLOX;
398  td.size = 36;
399  {
400  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 };
401  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
402  }
403  break;
404 
405  case 9: // Ublox - UBX-RXM-RAWX (0x02 0x15)
406  td.ptype = _PTYPE_UBLOX;
407  td.size = 952;
408  {
409  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,0x9b,0x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,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 };
410  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
411  }
412  break;
413 
414  case 10: // Ublox - UBX-NAV-POSLLH (0x01 0x02)
415  td.ptype = _PTYPE_UBLOX;
416  td.size = 36;
417  {
418  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 };
419  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
420  }
421  break;
422 
423  case 11: // Ublox - UBX-RXM-RAWX (0x02 0x15)
424  td.ptype = _PTYPE_UBLOX;
425  td.size = 952;
426  {
427  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,0x7,0x0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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 };
428  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
429  }
430  break;
431 #endif
432 
433 #if TEST_PROTO_RTCM3
434  case 12: // RTCM3 (0x19 0x3e)
435  td.ptype = _PTYPE_RTCM3;
436  td.size = 31;
437  {
438  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 };
439  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
440  }
441  break;
442 
443  case 13: // RTCM3 (0x48 0x40)
444  td.ptype = _PTYPE_RTCM3;
445  td.size = 78;
446  {
447  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 };
448  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
449  }
450  break;
451 
452  case 14: // RTCM3 (0x13 0x3e)
453  td.ptype = _PTYPE_RTCM3;
454  td.size = 25;
455  {
456  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 };
457  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
458  }
459  break;
460 
461  case 15: // RTCM3 (0x3a 0x44)
462  td.ptype = _PTYPE_RTCM3;
463  td.size = 320;
464  {
465  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 };
466  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
467  }
468  break;
469 
470  case 16: // RTCM3 (0xcc 0x43)
471  td.ptype = _PTYPE_RTCM3;
472  td.size = 210;
473  {
474  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 };
475  memcpy(td.data.buf, buf, td.size); // < PKT_BUF_SIZE (2048)
476  }
477  break;
478 #endif
479  }
480 
481  if (td.size)
482  {
483  DEBUG_PRINTF("[%2d] ", (int)testDeque.size());
484  switch (td.ptype)
485  {
486  case PSC_START_BYTE:
487  DEBUG_PRINTF("DID: %3d, size: %3d\n", td.did, td.size);
488  break;
489  case _PTYPE_ASCII_NMEA:
490  DEBUG_PRINTF("NMEA: %.30s...\n", td.data.buf);
491  break;
492  case _PTYPE_UBLOX:
493  DEBUG_PRINTF("UBLOX: size %d, (0x%02x 0x%02x)\n", td.size, td.data.buf[2], td.data.buf[3]);
494  break;
495  case _PTYPE_RTCM3:
496  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]);
497  break;
498  }
499 
500  if (byteSize + td.size < (PORT_BUFFER_SIZE*3)/4) // Allow room for packet headers
501  {
502  byteSize += td.size;
503 
504  // Add data to deque
505  testDeque.push_back(td);
506  }
507  else
508  { // Buffer is full
509  return;
510  }
511  }
512  }
513 }
514 
515 
516 void addDequeToRingBuf(std::deque<data_holder_t> &testDeque, ring_buf_t *rbuf)
517 {
518  is_comm_instance_t comm;
519  uint8_t comm_buffer[2048] = { 0 };
520  is_comm_init(&comm, comm_buffer, sizeof(comm_buffer));
521 
522  int k=0;
523 
524  for (int i = 0; i < testDeque.size(); i++)
525  {
526  data_holder_t &td = testDeque[i];
527  int n = 0;
528 
529  // Add packetized data to ring buffer
530  switch (td.ptype)
531  {
533  // Packetize data
534  n = is_comm_data(&comm, td.did, 0, td.size, (void*)&(td.data));
535  td.pktSize = n;
536  EXPECT_FALSE(ringBufWrite(rbuf, comm.buf.start, n));
537  break;
538 
539  case _PTYPE_ASCII_NMEA:
540  case _PTYPE_UBLOX:
541  case _PTYPE_RTCM3:
542  td.pktSize = td.size;
543  EXPECT_FALSE(ringBufWrite(rbuf, td.data.buf, td.size));
544  break;
545  }
546  }
547 
548  // Buffer overflow not allowed for test
549  ASSERT_TRUE(ringBufFree(rbuf));
550 }
551 
552 
553 void parseDataPortTxBuf(std::deque<data_holder_t> &testDeque, test_data_t &t)
554 {
555  is_comm_instance_t comm;
556  uint8_t comm_buffer[2048] = { 0 };
557  is_comm_init(&comm, comm_buffer, sizeof(comm_buffer));
558  unsigned char c;
559  protocol_type_t ptype;
560  uDatasets dataWritten;
561 
562  while (ringBufUsed(&t.portTxBuf)>0)
563  {
564  ringBufRead(&t.portTxBuf, &c, 1);
565 
566  if((ptype = is_comm_parse_byte(&comm, c)) != _PTYPE_NONE)
567  {
568  data_holder_t td = testDeque.front();
569  testDeque.pop_front();
570 
571  switch (ptype)
572  {
574  // Found data
575  DEBUG_PRINTF("Found data: did %3d, size %3d\n", comm.dataHdr.id, comm.dataHdr.size);
576 
577  is_comm_copy_to_struct(&dataWritten, &comm, sizeof(uDatasets));
578 
579  EXPECT_EQ(td.did, comm.dataHdr.id);
580  break;
581 
582  case _PTYPE_UBLOX:
583  case _PTYPE_RTCM3:
584  break;
585 
586  case _PTYPE_ASCII_NMEA:
587  DEBUG_PRINTF("Found data: %.30s...\n", comm.dataPtr);
588  break;
589  }
590 
591  EXPECT_EQ(td.size, comm.dataHdr.size);
592  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, td.size) == 0);
593  }
594  }
595 }
596 
597 
598 void ringBuftoRingBufWrite(ring_buf_t *dst, ring_buf_t *src, int len)
599 {
600  uint8_t *buf = new uint8_t[len];
601 
602  len = ringBufRead(src, buf, len);
603  EXPECT_FALSE(ringBufWrite(dst, buf, len));
604 }
605 
606 
607 #if 1
608 TEST(ComManager, BasicTxTest)
609 {
610  // Initialize Com Manager
611  init(tcm);
612 
613  // Generate and add data to deque
615 
616  // Use Com Manager to send deque data to Tx port ring buffer
617  for(int i=0; i<g_testTxDeque.size(); i++)
618  {
620 
621  // Send data - writes data to tcm.txBuf
622  switch (td.ptype)
623  {
624  default: // IS binary
625  comManagerSendDataNoAckInstance(&tcm.cm, 0, td.did, &td.data, td.size, 0);
626  break;
627 
628  case _PTYPE_ASCII_NMEA:
629  case _PTYPE_UBLOX:
630  case _PTYPE_RTCM3:
631  portWrite(&(tcm.cm), 0, td.data.buf, td.size);
632  break;
633  }
634 
635  }
636 
637  // Test that data parsed from Tx port matches deque data
639 
640  // Check that we got all data
641  EXPECT_TRUE(g_testTxDeque.empty());
642  EXPECT_TRUE(ringBufUsed(&tcm.portTxBuf) == 0);
643 }
644 #endif
645 
646 
647 #if 1
648 TEST(ComManager, BasicRxTest)
649 {
650  // Initialize Com Manager
651  init(tcm);
652 
653  // Generate and add data to deque
655 
656  // Add deque data to Rx port ring buffer
658 
659  DEBUG_PRINTF("=============== Checking Data. Size: %d ===============\n", ringBufUsed(&tcm.portRxBuf));
660 
661  while (!ringBufEmpty(&tcm.portRxBuf))
662  {
663  // Step Com Manager and check that was received correctly inside postRxRead()
664  comManagerStepInstance(&tcm.cm); // 2048 byte limit each step
665  }
666 
667  // Check that no data was left behind
668  EXPECT_TRUE(g_testRxDeque.empty());
669  EXPECT_TRUE(ringBufUsed(&tcm.portRxBuf) == 0);
670 }
671 #endif
672 
673 
674 #if 1
675 // Tests that ComManager handles segmented serial data properly
676 TEST(ComManager, SegmentedRxTest)
677 {
678  ring_buf_t tmpRBuf;
679  uint8_t buffer[8192];
680 
681  // Initialize temporary ring buffer
682  ringBufInit(&tmpRBuf, buffer, sizeof(buffer), 1);
683 
684  // Initialize Com Manager
685  init(tcm);
686 
687  // Generate and add data to deque
689 
690  // Add deque data to temporary ring buffer
691  addDequeToRingBuf(g_testRxDeque, &tmpRBuf);
692 
693  DEBUG_PRINTF("Checking Data:\n");
694 
695  // Divide data written to Com Manager into pieces
696 #define TIMES_TO_DIVIDE_DATA 10
697  int bytesToWrite = ringBufUsed(&tmpRBuf) / TIMES_TO_DIVIDE_DATA;
698  while (!ringBufEmpty(&tmpRBuf) && !g_testRxDeque.empty())
699  {
700  // Partial write of data
701  ringBuftoRingBufWrite(&tcm.portRxBuf, &tmpRBuf, bytesToWrite);
702 
703  while (!ringBufEmpty(&tcm.portRxBuf))
704  {
705  // Step Com Manager and check that was received correctly inside postRxRead()
708  }
709  }
710 
711  // Check that no data was left behind
712  EXPECT_TRUE(g_testRxDeque.empty());
713  EXPECT_TRUE(ringBufEmpty(&tcm.portRxBuf));
714 }
715 #endif
716 
717 
718 #if 1
719 TEST(ComManager, RxWithGarbageTest)
720 {
721  // Initialize Com Manager
722  init(tcm);
723 
724  // Generate and add data to deque
726 
727  // Insert garbage
728  std::deque<data_holder_t> testRxDequeWithGarbage;
729  data_holder_t td = {};
730  td.size = 24;
731  td.data.buf[1] = 128;
732  td.data.buf[19] = 128;
733  td.data.buf[23] = 128;
734 
735  for (int i = 0; i < g_testRxDeque.size(); i++)
736  {
737  if (i % 5 == 0)
738  {
739  // Insert garbage data
740  testRxDequeWithGarbage.push_back(td);
741  }
742 
743  // Copy good data
744  testRxDequeWithGarbage.push_back(g_testRxDeque[i]);
745  }
746 
747  // Add deque data to Rx port ring buffer
748  addDequeToRingBuf(testRxDequeWithGarbage, &tcm.portRxBuf);
749 
750  DEBUG_PRINTF("=============== Checking Data. Size: %d ===============\n", ringBufUsed(&tcm.portRxBuf));
751 
752  while (!ringBufEmpty(&tcm.portRxBuf))
753  {
754  // Step Com Manager and check that was received correctly inside postRxRead()
755  comManagerStepInstance(&tcm.cm); // 2048 byte limit each step
756  }
757 
758  // Check that no data was left behind
759  EXPECT_TRUE(g_testRxDeque.empty());
760  EXPECT_TRUE(ringBufUsed(&tcm.portRxBuf) == 0);
761 }
762 #endif
763 
764 
765 #if 1
766 TEST(ComManager, Evb2AltDecodeBufferTest)
767 {
768  // This test ensures that packets can be read and decoded to the alternate buffer (not in the default comm.buf.start buffer).
769 
770  // Init Port Buffers
771  ringBufInit(&(tcm.portTxBuf), tcm.portTxBuffer, sizeof(tcm.portTxBuffer), 1);
772  ringBufInit(&(tcm.portRxBuf), tcm.portRxBuffer, sizeof(tcm.portRxBuffer), 1);
773  initComManager(tcm);
774 
775  is_comm_instance_t &comm = (tcm.cm.ports[0].comm);
776  uint8_t altDecodBuf[PKT_BUF_SIZE] = {};
777  comm.altDecodeBuf = altDecodBuf;
778 
779  // Generate and add data to deque
781 
782  // Add deque data to Rx port ring buffer
784 
785  DEBUG_PRINTF("=============== Checking Data. Size: %d ===============\n", ringBufUsed(&tcm.portRxBuf));
786 
787  while (!ringBufEmpty(&tcm.portRxBuf))
788  {
789  // Get available size of comm buffer
790  int n = is_comm_free(&comm);
791 
792  // Read 5 bytes at a time
793  n = _MIN(n, 5);
794 
795  // Read data directly into comm buffer
796  if ((n = ringBufRead(&tcm.portRxBuf, comm.buf.tail, n)))
797  {
798  // Update comm buffer tail pointer
799  comm.buf.tail += n;
800 
802  uDatasets dataWritten;
803 
804  // Search comm buffer for valid packets
805  while ((ptype = is_comm_parse(&comm)) != _PTYPE_NONE)
806  {
807  uint8_t error = 0;
808  uint8_t *dataPtr = comm.dataPtr + comm.dataHdr.offset;
809  uint32_t dataSize = comm.dataHdr.size;
810 
811  data_holder_t td = g_testRxDeque.front();
812  g_testRxDeque.pop_front();
813 
814  switch (ptype)
815  {
817  // Found data
818  DEBUG_PRINTF("Found data: did %3d, size %3d\n", comm.dataHdr.id, comm.dataHdr.size);
819 
820  is_comm_copy_to_struct(&dataWritten, &comm, sizeof(uDatasets));
821 
822  EXPECT_EQ(td.did, comm.dataHdr.id);
823  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size)==0);
824  break;
825 
826  case _PTYPE_UBLOX:
827  case _PTYPE_RTCM3:
828  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
829  break;
830 
831  case _PTYPE_ASCII_NMEA:
832  DEBUG_PRINTF("Found data: %.30s...\n", comm.dataPtr);
833  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
834  break;
835 
836  default:
837  EXPECT_TRUE(false);
838  break;
839  }
840  }
841  }
842 
843  }
844 
845  // Check that no data was left behind
846  EXPECT_TRUE(g_testRxDeque.empty());
847  EXPECT_TRUE(ringBufUsed(&tcm.portRxBuf) == 0);
848 }
849 #endif
850 
851 
852 
853 #if 1
854 TEST(ComManager, Evb2DataForwardTest)
855 {
856  // This test ensures that packets can be read, decoded, and forwarded for EVB-2 com_bridge without corrupting the data.
857 
858  // Init Port Buffers
859  ringBufInit(&(tcm.portTxBuf), tcm.portTxBuffer, sizeof(tcm.portTxBuffer), 1);
860  ringBufInit(&(tcm.portRxBuf), tcm.portRxBuffer, sizeof(tcm.portRxBuffer), 1);
861  initComManager(tcm);
862 
863  is_comm_instance_t &comm = (tcm.cm.ports[0].comm);
864  uint8_t altDecodBuf[PKT_BUF_SIZE] = {};
865  comm.altDecodeBuf = altDecodBuf;
866 
867  // Generate and add data to deque
869 
870  ring_buf_t evbRbuf;
871  uint8_t evbRBuffer[PORT_BUFFER_SIZE] = {};
872  ringBufInit(&evbRbuf, evbRBuffer, PORT_BUFFER_SIZE, 1);
873 
874  // Add deque data to EVB port ring buffer
875  addDequeToRingBuf(g_testRxDeque, &evbRbuf);
876 
877 
878  DEBUG_PRINTF("=============== EVB input Data. Size: %d ===============\n", ringBufUsed(&evbRbuf));
879 
880  int originalRingBufferUsed = ringBufUsed(&evbRbuf);
881 
882  std::deque<data_holder_t> testRxDequeCopy = g_testRxDeque;
883 
884  while (!ringBufEmpty(&evbRbuf))
885  {
886  // Get available size of comm buffer
887  int n = is_comm_free(&comm);
888 
889  // Read 5 bytes at a time
890  n = _MIN(n, 5);
891 
892  // Read data directly into comm buffer
893  if ((n = ringBufRead(&evbRbuf, comm.buf.tail, n)))
894  {
895  // Update comm buffer tail pointer
896  comm.buf.tail += n;
897 
899 
900  // Search comm buffer for valid packets
901  while ((ptype = is_comm_parse(&comm)) != _PTYPE_NONE)
902  {
903  uint8_t error = 0;
904  uint8_t *dataPtr = comm.dataPtr + comm.dataHdr.offset;
905  uint32_t dataSize = comm.dataHdr.size;
906 
907  data_holder_t td = testRxDequeCopy.front();
908  testRxDequeCopy.pop_front();
909 
910  switch (ptype)
911  {
913  case _PTYPE_ASCII_NMEA:
914  case _PTYPE_UBLOX:
915  case _PTYPE_RTCM3:
916  {
917  uint32_t pktSize = (uint32_t)_MIN(comm.buf.scan - comm.pktPtr, PKT_BUF_SIZE);
918  ringBufWrite(&tcm.portRxBuf, comm.pktPtr, pktSize);
919 
920  if (td.pktSize != pktSize)
921  {
922  ASSERT_TRUE(false);
923  }
924  }
925  break;
926 
927  default:
928  ASSERT_TRUE(false);
929  }
930  }
931  }
932  }
933 
934  int forwardRingBufferUsed = ringBufUsed(&tcm.portRxBuf);
935  ASSERT_TRUE(forwardRingBufferUsed == originalRingBufferUsed);
936 
937 
938  DEBUG_PRINTF("=============== Checking Data. Size: %d ===============\n", ringBufUsed(&tcm.portRxBuf));
939 
940  while (!ringBufEmpty(&tcm.portRxBuf))
941  {
942  // Get available size of comm buffer
943  int n = is_comm_free(&comm);
944 
945  // Read 5 bytes at a time
946  n = _MIN(n, 5);
947 
948  // Read data directly into comm buffer
949  if ((n = ringBufRead(&tcm.portRxBuf, comm.buf.tail, n)))
950  {
951  // Update comm buffer tail pointer
952  comm.buf.tail += n;
953 
955  uDatasets dataWritten;
956 
957  // Search comm buffer for valid packets
958  while ((ptype = is_comm_parse(&comm)) != _PTYPE_NONE)
959  {
960  uint8_t error = 0;
961  uint8_t *dataPtr = comm.dataPtr + comm.dataHdr.offset;
962  uint32_t dataSize = comm.dataHdr.size;
963 
964  data_holder_t td = g_testRxDeque.front();
965  g_testRxDeque.pop_front();
966 
967  switch (ptype)
968  {
970  // Found data
971  DEBUG_PRINTF("Found data: did %3d, size %3d\n", comm.dataHdr.id, comm.dataHdr.size);
972 
973  is_comm_copy_to_struct(&dataWritten, &comm, sizeof(uDatasets));
974 
975  EXPECT_EQ(td.did, comm.dataHdr.id);
976  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
977  break;
978 
979  case _PTYPE_UBLOX:
980  case _PTYPE_RTCM3:
981  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
982  break;
983 
984  case _PTYPE_ASCII_NMEA:
985  DEBUG_PRINTF("Found data: %.30s...\n", comm.dataPtr);
986  EXPECT_TRUE(memcmp(td.data.buf, comm.dataPtr, comm.dataHdr.size) == 0);
987  break;
988 
989  default:
990  EXPECT_TRUE(false);
991  break;
992  }
993  }
994  }
995 
996  }
997 
998  // Check that no data was left behind
999  EXPECT_TRUE(g_testRxDeque.empty());
1000  EXPECT_TRUE(ringBufUsed(&tcm.portRxBuf) == 0);
1001 }
1002 #endif
1003 
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:3418
uint8_t enableISB
Definition: ISComm.h:469
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:457
double towOffset
Definition: data_sets.h:774
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:1989
struct test_data_t::@42 msgs
static com_manager_port_t s_cmPort
uint8_t leapS
Definition: data_sets.h:777
ins_1_t ins1
Definition: data_sets.h:3406
uint32_t id
Definition: ISComm.h:375
is_can_uvw uvw
Definition: CAN_comm.h:257
#define DID_INS_1
Definition: data_sets.h:38
uint32_t size
Definition: ISComm.h:378
is_comm_config_t config
Definition: ISComm.h:491
uint8_t enableASCII
Definition: ISComm.h:472
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:2766
uGpsRawData data
Definition: data_sets.h:2803
bool init(test_data_t &t)
uint8_t enableRTCM3
Definition: ISComm.h:478
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:475
#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
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:759
#define TEST_PROTO_UBLOX
is_comm_buffer_t buf
Definition: ISComm.h:488
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:768
int is_comm_free(is_comm_instance_t *instance)
Definition: ISComm.c:462
#define NUM_COM_PORTS
Definition: data_sets.h:1199
uint8_t * pktPtr
Definition: ISComm.h:512
int msgHandlerRtcm3(CMHANDLE cmHandle, int pHandle, const uint8_t *msg, int msgSize)
uint32_t hdwStatus
Definition: CAN_comm.h:40
union data_holder_t::@43 data
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:447
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
std::deque< data_holder_t > g_testTxDeque
p_data_hdr_t hdr
Definition: ISComm.h:388
uint32_t status
Definition: CAN_comm.h:114
uint8_t * tail
Definition: ISComm.h:459
USBInterfaceDescriptor data
uint8_t * scan
Definition: ISComm.h:462
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:577
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:506
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:241
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:515
float hAcc
Definition: data_sets.h:762
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:391
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:381
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
void prepDevInfo(CMHANDLE cmHandle, int pHandle)
uint8_t * dataPtr
Definition: ISComm.h:509


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