Signals | |
void | newPosition (void) |
Signal emmited when a valid position is received. | |
Public Member Functions | |
TGeoposition (void) | |
Class constructor and no more. | |
bool | openConnection (const char *port_name) |
Opens a serial port where it is supossed that the GPS is attached. | |
void | closeConnection (void) |
Closes the serial port ... if it is open. | |
void | sendStr (const char *cad) |
Sends strings of text to the device. | |
void | sendData (const char *dat, int len) |
Sends a given number of to the device. | |
int | receiveData (char *destination, int max_data) |
Receives the data that the devices sends to the host. | |
void | processReceivedData (void) |
Handles the received data from the device. | |
bool | findMessage (const char *data, unsigned int size, unsigned int *start, unsigned int *length) |
Finds messages in the stream of data received from the device. | |
bool | parseMessage (const char *start, unsigned int length) |
Parses the content of the messages. | |
void | getLastPosition (double *utc_t, double *longit, Tcardinaleixos *c_longitude, double *latit, Tcardinaleixos *c_latitude) |
Returns the last valid GPS position received. | |
~TGeoposition (void) | |
Class destructor. |
TGeoposition::~TGeoposition | ( | void | ) |
Class destructor.
It is important to call it in order to free locked resources.
void TGeoposition::closeConnection | ( | void | ) |
Closes the serial port ... if it is open.
Example:
geo->closeConnection();
bool TGeoposition::findMessage | ( | const char * | data, | |
unsigned int | size, | |||
unsigned int * | start, | |||
unsigned int * | length | |||
) |
Finds messages in the stream of data received from the device.
This functions is responsible for finding message items in the strem of data.
data | data buffer to be explored | |
size | number of bytes to be considered | |
[out] | start | index of the start of the found message |
[out] | length | length of found the message |
Example:
Altre dia sera.
void TGeoposition::getLastPosition | ( | double * | utc_t, | |
double * | longit, | |||
Tcardinaleixos * | c_longitude, | |||
double * | latit, | |||
Tcardinaleixos * | c_latitude | |||
) |
Returns the last valid GPS position received.
[out] | utc_t | UTC time |
[out] | longit | longitude |
[out] | c_longitude | EAST or WEST |
[out] | latit | latitude |
[out] | c_latitude | NOTH or SOUTH |
bool TGeoposition::openConnection | ( | const char * | port_name | ) |
Opens a serial port where it is supossed that the GPS is attached.
port_name | name of the device that provides access to a given serial port |
true | if port succesfully openned | |
false | if port can not be openned |
Example:
TGeoposition geo = new TGeoposition(); if (geo->openConnection("COM1")) { printf("Port openned."); } else { printf("Error openning the port"); }
bool TGeoposition::parseMessage | ( | const char * | data, | |
unsigned int | length | |||
) |
Parses the content of the messages.
In this case, this function analyses this NMEA-0183 command $GPGGA (Global Positioning System Fix Data) i.e. $GPGGA,170834,4124.8963,N,08151.6838,W,1,05,1.5,280.2,M,-34.0,M,,,*75 see http://home.mira.net/~gnb/gps/nmea.html#gpgga
data | pointer to data | |
length | length of the message |
Example:
Altre dia sera.
void TGeoposition::processReceivedData | ( | void | ) |
Handles the received data from the device.
This functions is responsible of managing an input buffer for data from the device and calling functions for analyse data It should be called periodically of using some event-driven mechanism in order to process data.
Example:
timer = new QTimer(); connect(timer,SIGNAL(timeout),geo,SLOT(processReceivedData()); timer->setInterval(1000); timer->start();
int TGeoposition::receiveData | ( | char * | destination, | |
int | max_data | |||
) |
Receives the data that the devices sends to the host.
This functions is non-blocking, so it returns inmediately and no waits if data is not available
destination | pointer where data buyes will be put | |
max_data | maximum number of bytes that can be received, remaing data is keept in device's buffer |
Example:
unsigned char buffer[10000]; int num_bytes; num_bytes = geo->receiveData(buffer, 10000); if (num_bytes > 0) { printf("Received %d byes\n", num_bytes); }
void TGeoposition::sendData | ( | const char * | dat, | |
int | len | |||
) |
Sends a given number of to the device.
This functions is non-blocking, so it returns inmediately and no waits until data is sent to the device
dat | pointer to data | |
len | number of bytes to be sent |
Example:
unsigned char dades[] = {35,49,110,69}; geo->sendData(dades, 4);
void TGeoposition::sendStr | ( | const char * | cad | ) |
Sends strings of text to the device.
This functions is non-blocking, so it returns inmediately and no waits until data is sent to the device
cad | pointer to a null-terminated standard C string |
Example:
geo->sendStr("Les coques amb tomaca estan molt bones\x0D");