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.
Public Member Functions | Public Attributes | List of all members
SerialTxRx Class Reference

#include <SerialTxRx.h>

Public Member Functions

 SerialTxRx (void)
 
 ~SerialTxRx (void)
 
void openPort (string portName)
 
void setPortParams (int baudRate, int timeout=1)
 
void getPortParams (int &baudRate, int &timeout, bool &rawMode)
 
int readOSPmsg (int patience=MAXBUFFERSIZE *2)
 
int readNMEAmsg (int patience=MAXBUFFERSIZE)
 
void writeOSPcmd (int mid, string cmdArgs, int base=16)
 
void writeNMEAcmd (int mid, string cmdArgs)
 
void closePort ()
 
void sleepTime (int ms)
 

Public Attributes

unsigned char paylenBuff [2]
 a 2 bytes buffer for the payload length bytes
 
unsigned char payBuff [MAXBUFFERSIZE]
 message payload data buffer of MAXBUFFERSIZE bytes
 
unsigned int payloadLen
 the current payload length, for convenience
 

Detailed Description

SerialTxRx class defines a data and method to manage the serial comm port where a receiver is connected, and allows sending and receiving messages through it. A program using SerialTxRx would perform the following steps after declaring an object of this class:

  1. To open the serial port with the name given
  2. To set or get the port parameters (baud rate, size, parity)
  3. To read or write OSP or NMEA messages
  4. To skip input bytes / chars until appears the start of an OSP or NMEA message
  5. To close the port

Constructor & Destructor Documentation

SerialTxRx::SerialTxRx ( void  )

Constructs an empty SerialTxRx object, without setting comms port parameters.

SerialTxRx::~SerialTxRx ( void  )

Destructs SerialTxRx objects.

Member Function Documentation

void SerialTxRx::closePort ( )

closePort closes the currently open serial port.

void SerialTxRx::getPortParams ( int &  baudRate,
int &  timeout,
bool &  rawMode 
)

getPortParams gets current port parameters: baud rate, byte size and parity.

Parameters
baudRatea variable to place the value of the baud rate
timeouta variable to place the value of the timeout limit when reading input
modea variable to place a true value if raw mode (non canonical) is used, or false otherwise
Exceptions
errorstring with the message explaining it
void SerialTxRx::openPort ( string  portName)

openPort opens the serial port portName to allow reception of messages or sending commands to a SiRF receiver.

Parameters
portNamethe name of the port to be opened
Exceptions
errormessage when the port cannot be open, explaining the reason
int SerialTxRx::readNMEAmsg ( int  patience = MAXBUFFERSIZE)

readNMEAmsg reads a NMEA message from the serial port.

Parameters
patiencethe maximum number of skipped chars or unsuccessful reads before returning
Returns
the exit status according to the following values and meaning:
  • (0) when a correct message has been received;
  • (1) if the received message has incorrect checksum;
  • (2) if message received has less than five chars. Minimum NMEA message is $XXX*SS
  • (3) if the input stream does not contains NMEA messages or an input error occurred or EOF
  • (4) if NMEA start bytes have not been received before "exhaust patience"
int SerialTxRx::readOSPmsg ( int  patience = MAXBUFFERSIZE*2)

readOSPmsg reads a OSP message from the serial port.

Parameters
patienceis the maximum number of bytes to skip or unsuccessful reads from the serial port before returning error
Returns
the exit status according to the following values and meaning:
  • (0) when a correct formatted OSP message has been received;
  • (1) if the message has incorrect checksum;
  • (2) if error occurred when reading payload or not enought bytes were received
  • (3) if the payload length read is out of margin (>MAXBUFFERSIZE)
  • (4) if unable to read the two bytes of the OSP payload length
  • (5) if read error occurred reading OSP payload bytes
  • (6) if OSP start bytes have not been received before "exhaust patience"
void SerialTxRx::setPortParams ( int  baudRate,
int  timeout = 1 
)

setPortParams sets port baud rate. Other relevant port parameters are set to the following values:

  • ByteSize = 8
  • StopBits = ONESTOPBIT;
  • Parity = NOPARITY;
  • fBinary = TRUE;
  • fDtrControl = DTR_CONTROL_DISABLE;
  • fRtsControl = RTS_CONTROL_DISABLE;
Parameters
baudRatethe value of the baud rate to be set
timeoutthe limit for a timer in tenths of a second to wait for input data
Exceptions
errorstring with the message explaining it
void SerialTxRx::sleepTime ( int  ms)

sleepTime stops the process for the milliseconds stated Here it is implemented a version for Windows

void SerialTxRx::writeNMEAcmd ( int  mid,
string  cmdArgs 
)

writeNMEAcmd builds a NMEA message command and sends it to receiver through to the serial port.

Parameters
midthe identification of the command to be generated in the form $PSRF<mid>, ...
cmdArgsthe message parameters: a comma separated list of arguments
Exceptions
errorstring message explaining it
void SerialTxRx::writeOSPcmd ( int  mid,
string  cmdArgs,
int  base = 16 
)

writeOSPcmd builds a OSP message command and sends it to receiver through the serial port.

Parameters
midthe message identification of the OSP command to be generated
cmdArgsthe rest of message payload, as a whitespace-separated sequence of bytes
basethe base used to write the parameters (16, 10, ...)
Exceptions
errorstring when message cannot be send

The documentation for this class was generated from the following files: