RXtoRINEX  V2.1
RXtoRINEX provides tools to collect data from GPS / GNSS receivers in mobile devices, convert them to RINEX or RTK formats, and process RINEX files.
SerialTxRx.h
Go to the documentation of this file.
1 
23 #ifndef SERIALTXRX_H
24 #define SERIALTXRX_H
25 
26 #include <string>
27 #include <forward_list>
28 //specific to access Windows resources
29 #include <windows.h>
30 
31 #include "SerialTxRxErrorMSG.h"
32 
34 #if defined(_DEBUG)
35 #define DBGRPT(format, ...) printf(format,##__VA_ARGS__);
36 #else
37 #define DBGRPT(format, ...)
38 #endif
39 
40 using namespace std;
41 
43 #define DEFAULTBAUDRATE 9600
44 #define MAXBUFFERSIZE 2052
46 //@cond DUMMY
47 #define START1 160 //0xA0 //OSP messages from/to receiver are preceded by the synchro
48 #define START2 162 //0xA2 //sequence of two bytes with values START1, START2
49 #define END1 176 //0XB0 //OSP messages from/to receiver are followed by the end
50 #define END2 179 //0XB3 //sequence of two bytes with values END1, END2
51 #define LF 0x0A //ASCII Line Feed
52 #define CR 0x0D //ASCII Carriage Return
53 #define DOLAR 0x24 //ASCII Dolar sign
54 #define CHK 0x2A //ASCII * (chacksum start: two ASCII hex follow with XOR of chars between $ and *)
55 
56 
57 class CBRrate {
58 friend class SerialTxRx;
59  int baudR;
60  DWORD DCBbaud;
61  CBRrate(int, DWORD);
62 };
63 //@endcond
64 
74 class SerialTxRx {
75 //@cond DUMMY
76  friend class CBRrate;
77 //@endcond
78  HANDLE hSerial; //the Windows handle for the serial port
79  forward_list<CBRrate> CBRrateLst;
80  string baudRate; //the baud rate used
81  string portName; //the port name (like COM35)
82 
83  void addCBRrate(int rate, DWORD CBRrt);
84  DWORD getCBRrate(int);
85  int getBaudRate(DWORD);
86  bool synchOSPmsg(int patience = 500); //skip bytes until start of OSP message is reached
87  bool synchNMEAmsg(int patience); //skip bytes until start of NMEA message is reached
88 
89 public:
90  unsigned char paylenBuff[2];
91  unsigned char payBuff[MAXBUFFERSIZE];
92  unsigned int payloadLen;
93 
94  SerialTxRx(void);
95  ~SerialTxRx(void);
96  void openPort(string portName); //open the serial port with the name given
97  void setPortParams(int baudRate, int timeout = 1); //set port params in the current open port
98  void getPortParams(int& baudRate, int& timeout, bool& rawMode); //get port params in the current open port
99  int readOSPmsg(int patience = MAXBUFFERSIZE*2); //read a OSP message from the serial port
100  int readNMEAmsg(int patience = MAXBUFFERSIZE); //read a NMEA message from the serial port
101  void writeOSPcmd(int mid, string cmdArgs, int base = 16); //generate and send a OSPMessage object containing a command to the receiver
102  void writeNMEAcmd(int mid, string cmdArgs); //generate and send a NMEA message object containing a command to the receiver
103  void closePort(); //close the currently open serial port
104  void sleepTime(int ms); //sleep for the milliseconds stated before resuming execution
105 };
106 #endif
int readOSPmsg(FILE *inFile)
Definition: PacketToOSP.cpp:219
Definition: SerialTxRx.h:74
#define MAXBUFFERSIZE
Maximum payload size (2048) + length (2) + checksum (2)
Definition: SerialTxRx.h:45
bool synchOSPmsg(FILE *inFile)
Definition: PacketToOSP.cpp:181
unsigned int payloadLen
the current payload length, for convenience
Definition: SerialTxRx.h:92