ISAsciiExample.c
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2021 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 #include <stdio.h>
14 
15 // STEP 1: Add Includes
16 // Change these include paths to the correct paths for your project
17 #include "../../src/serialPortPlatform.h"
18 #include "../../src/ISComm.h"
19 
20 static int running = 1;
21 
22 int main(int argc, char* argv[])
23 {
24  if (argc < 2)
25  {
26  printf("Please pass the com port as the only argument\r\n");
27  // In Visual Studio IDE, this can be done through "Project Properties -> Debugging -> Command Arguments: COM3"
28  return -1;
29  }
30 
31  // STEP 2: Initialize and open serial port
32  serial_port_t serialPort;
33 
34  // Initialize the serial port (Windows, MAC or Linux) - if using an embedded system like Arduino,
35  // you will need to handle the serial port creation, open and reads yourself. In this
36  // case, you do not need to include serialPort.h/.c and serialPortPlatform.h/.c in your project.
37  serialPortPlatformInit(&serialPort);
38 
39  // Open serial, last parameter is a 1 which means a blocking read, you can set as 0 for non-blocking
40  // you can change the baudrate to a supported baud rate (IS_BAUDRATE_*), make sure to reboot the uINS
41  // if you are changing baud rates, you only need to do this when you are changing baud rates.
42  if (!serialPortOpen(&serialPort, argv[1], IS_BAUDRATE_921600, 1))
43  {
44  printf("Failed to open serial port on com port %s\r\n", argv[1]);
45  return -2;
46  }
47 
48 
49  // STEP 3: Enable prior message broadcasting
50  // Stop all broadcasts on the device on all ports. We don't want binary message coming through while we are doing ASCII
51  if (!serialPortWriteAscii(&serialPort, "STPB", 4))
52  {
53  printf("Failed to encode stop broadcasts message\r\n");
54  return -3;
55  }
56 #if 0
57  // Query device version information
58  if (!serialPortWriteAscii(&serialPort, "INFO", 4))
59  {
60  printf("Failed to encode stop broadcasts message\r\n");
61  return -3;
62  }
63 #endif
64  // STEP 4: Enable message broadcasting
65 
66  // ASCII protocol is based on NMEA protocol https://en.wikipedia.org/wiki/NMEA_0183
67  // turn on the INS message at a period of 100 milliseconds (10 hz)
68  // serialPortWriteAscii takes care of the leading $ character, checksum and ending \r\n newline
69  // ASCB message enables ASCII broadcasts
70  // ASCB fields: 1:options, 2:PIMU, 3:PPIMU, 4:PINS1, 5:PINS2, 6:PGPSP, 7:reserved, 8:GPGGA, 9:GPGLL, 10:GPGSA, 11:GPRMC
71  // options can be 0 for current serial port, 1 for serial 0, 2 for serial 1 or 3 for both serial ports
72  // Instead of a 0 for a message, it can be left blank (,,) to not modify the period for that message
73  // please see the user manual for additional updates and notes
74 
75  // Get PINS1 @ 10Hz on the connected serial port, leave all other broadcasts the same, and save persistent messages.
76  const char* asciiMessage = "ASCB,512,,,1000,,,,,,,";
77 
78  // Get PINS1 @ 50Hz and PGPSP @ 5Hz on the connected serial port, leave all other broadcasts the same
79 // const char* asciiMessage = "ASCB,,,,20,,200,,,,,";
80 
81  // Get PIMU @ 50Hz, GPGGA @ 5Hz, both serial ports, set all other periods to 0
82 // const char* asciiMessage = "ASCB,3,20,0,0,0,0,0,100,0,0,0";
83 
84  if (!serialPortWriteAscii(&serialPort, asciiMessage, (int)strnlen(asciiMessage, 128)))
85  {
86  printf("Failed to encode ASCII get INS message\r\n");
87  return -4;
88  }
89 
90 
91 #if 0
92  // STEP 5: (optional) Save Persistent Messages. This remembers the current communications and automatically streams data following reboot.
93  if (!serialPortWriteAscii(&serialPort, "PERS", 4))
94  {
95  printf("Failed to encode ASCII save persistent message\r\n");
96  return -4;
97  }
98 #endif
99 
100 
101  // STEP 6: Handle received data
102  unsigned char* asciiData;
103  unsigned char asciiLine[512];
104 
105  // You can set running to false with some other piece of code to break out of the loop and end the program
106  while (running)
107  {
108  if (serialPortReadAscii(&serialPort, asciiLine, sizeof(asciiLine), &asciiData) > 0)
109  {
110  printf("%s\n", asciiData);
111  }
112  }
113 }
114 
int serialPortOpen(serial_port_t *serialPort, const char *port, int baudRate, int blocking)
Definition: serialPort.c:28
static int running
int main(int argc, char *argv[])
int serialPortPlatformInit(serial_port_t *serialPort)
#define printf(...)
Definition: evb_tasks.h:36
int serialPortReadAscii(serial_port_t *serialPort, unsigned char *buffer, int bufferLength, unsigned char **asciiData)
Definition: serialPort.c:145
int serialPortWriteAscii(serial_port_t *serialPort, const char *buffer, int bufferLength)
Definition: serialPort.c:230


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