AURobotServers  4
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
UResGps Class Reference

#include <uresgps.h>

Inheritance diagram for UResGps:
Inheritance graph

Public Member Functions

void closePort ()
 
virtual bool decodeReplayLine (char *line)
 
const char * getDevice ()
 
const char * getDeviceName ()
 
int getDeviceSpeed ()
 
const char * getLastLatLongSentance ()
 
UTime getLastPositionTime ()
 
const char * getLastSentance ()
 
const char * getLastStatusSentance ()
 
const char * getLastUtmSentance ()
 
int getSpeed ()
 
UResBasegetUtmHist ()
 
bool isConnected ()
 
bool isLogGpsOpen ()
 
void openLogfile (bool open)
 
void openPort ()
 
virtual const char * print (const char *preString, char *buff, int buffCnt)
 
void run ()
 
void setDevice (const char *value)
 
bool setResource (UResBase *resource, bool remove)
 
void setSpeed (int value)
 
 UResGps ()
 
void UResGpsInit ()
 
virtual ~UResGps ()
 
- Public Member Functions inherited from UResVarPool
int addMethod (const char *formalName, const char *paramTypes, const char *comment)
 
int addMethodV (const char *formalName, const char *paramTypes, const char *comment)
 
UVarPooladdStruct (const char *name, const char *comment, bool copy=false)
 
UVariableaddVar (const char *name, const double initialValue, const char *type, const char *comment)
 
UVariableaddVar (const char *name, const char *initialValue, const char *type, const char *comment)
 
UVariableaddVarA (const char *name, const char *initialValue, const char *type, const char *comment)
 
bool callGlobal (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct, int *returnStructCnt)
 
bool callGlobalV (const char *name, const char *paramOrder, UVariable **params, UDataBase **returnStruct, int *returnStructCnt)
 Call a method from the root var pool scope It may be in the structure direct (no '.') or in any sub-structure that the 'name.subname' indicate. More...
 
bool callLocal (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct, int *returnStructCnt)
 
bool callVS (const char *function, const char *stringParam)
 
int callVSCD (const char *function, const char *strPar, UDataBase *data, int cooSys)
 
void createBaseVar ()
 
virtual bool createVarSpace (const int varCnt, const int structCnt, const int methCnt, const char *note, bool copy=false)
 
bool getGlobalString (const char *name, const char **value)
 
bool getGlobalValue (const char *name, double *value)
 
bool getGlobalValue (const char *name, const char **value)
 
bool getGlobalValue (const char *name, bool *value)
 
bool getGlobalValue (const char *name, UTime *value)
 
bool getLocalValue (const char *name, double *value)
 get a value in this variable tree More...
 
bool getLocalValue (const char *name, bool *value)
 
bool getLocalValue (const char *name, UTime *value)
 
double getLocalValue (int idx)
 
UPosition getLocalValue3D (int idx)
 
UPosRot getLocalValue6D (int idx)
 
bool getLocalValueBool (int idx)
 
int getLocalValueInt (int idx)
 
UTime getLocalValueTime (int idx)
 
const char * getLogFileName ()
 
const char * getVarDescription (int idx)
 
UVarCalcgetVarPool ()
 
virtual bool gotAllResources (char *missingThese, int missingTheseCnt)
 
bool isLogFileOpen ()
 
bool isLogFileOpen (const char *structName)
 
bool isVarPoolUpdated (int lastCnt, int *newCnt)
 
void logFileClose ()
 
bool logFileOpen ()
 
void logFileStart (const char *structName, bool open)
 
virtual bool methodCall (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct=NULL, int *returnStructCnt=NULL)
 
bool setGlobalVar (const char *name, const double value, bool mayAdd)
 Assigns a value to a variable. The variable may be a part of a structure. More...
 
bool setLocalVar (int idx, double value, const int element)
 
bool setLocalVar (const char *name, const double value, bool mayAdd)
 Assigns a value to a variable. The variable may be a part of a structure. More...
 
bool setLocalVar3D (int idx, UPosition *value)
 
bool setLocalVar6D (int idx, UPosRot *value)
 
bool setLocalVarAdd (int idx, double value, const int element)
 
bool setLocalVarPose (int idx, UPose *value)
 
void setVarPool (UVarCalc *sharedVarPool)
 
int updateQTvars (int structIdx)
 
 UResVarPool ()
 
virtual ~UResVarPool ()
 
- Public Member Functions inherited from UResBase
void createReplayVar (UVarPool *pool)
 
virtual void createResources ()
 
UCmdExegetCorePointer ()
 
char * getLogFileName (char *fn, const int fnCnt)
 
int getResFuncIdx ()
 
const char * getResID ()
 
int getResVersion ()
 
bool isA (const char *idStr)
 
bool isAlsoA (const char *id)
 
virtual void print (const char *preString)
 
virtual void saveSettings ()
 
void setCorePointer (UCmdExe *serverCore)
 
void setResFuncIdx (int idx)
 
virtual void setResID (const char *id, const int version)
 
virtual void stop (bool)
 
virtual void updateReplayStatus ()
 
 UResBase ()
 
virtual ~UResBase ()
 
- Public Member Functions inherited from UReplay
void addChild (UReplay *child)
 
char * getLogFileName (char *fn, const int fnCnt)
 
char * getReplayFileName (char *fn, const int fnCnt)
 
int getReplayLogLine ()
 
bool isReplay ()
 
bool isReplayFileOpen ()
 
void removeChild (UReplay *child)
 
virtual void replayAdvanceTime (UTime untilTime)
 
void replaySetBaseFileName (const char *name, const char *preName="")
 
void replaySetFileName (const char *name)
 
virtual bool replayStep ()
 
int replayStep (int steps)
 
virtual bool replayToTime (UTime untilTime)
 
void setParent (UReplay *parent)
 
bool setReplay (bool value)
 
 UReplay ()
 
virtual ~UReplay ()
 
- Public Member Functions inherited from ULock
bool lock ()
 
void lockInit ()
 
void post ()
 
bool tryLock ()
 
bool tryWait ()
 
 ULock ()
 
void unlock ()
 
bool wait ()
 
 ~ULock ()
 
- Public Member Functions inherited from UVarMethodImplement
virtual bool methodCallV (const char *name, const char *paramOrder, UVariable *params[], UDataBase **returnStruct, int *returnStructCnt)
 
virtual ~UVarMethodImplement ()
 

Static Public Member Functions

static const char * getResClassID ()
 
- Static Public Member Functions inherited from UResVarPool
static const char * getResClassID ()
 

Public Attributes

ULogFile logGps
 
- Public Attributes inherited from UReplay
bool replayTimeAdvancePending
 
UTime replayTimeNow
 

Protected Member Functions

char ascii2hex (char input)
 Implementation of a ASCII to HEX coverter. More...
 
void createBaseVar ()
 
int receiveFromDevice (FILE *device, char *buff, int buffCnt, const double timeoutSec)
 
bool start ()
 
void stop ()
 
void toLog (const char *message)
 
void updateVars ()
 
bool validateNMEA (char *in_buf)
 
- Protected Member Functions inherited from UResVarPool
void setDescription (const char *note, bool copy=false)
 
- Protected Member Functions inherited from UResBase
UResBasegetStaticResource (const char *resName, bool mayCreate, bool staticOnly=true)
 get a pointer to a static resource. More...
 

Protected Attributes

int dataRxMsgCnt
 
UTime dataRxTime
 
char logGpsName [MAX_FILENAME_LENGTH]
 
UResPoseHistmapPose
 
UResPoseHistodoPose
 
pthread_t threadHandle
 
bool threadRunning
 
bool threadStop
 
UResPoseHistutmPose
 
- Protected Attributes inherited from UResBase
int resFuncIdx
 
char resID [MAX_RESOURCE_ID_LENGTH]
 
char resIsAlso [MAX_RESOURCE_ISALSO_LENGTH]
 
int resVersion
 
- Protected Attributes inherited from UReplay
bool replay
 
FILE * replayFile
 
char replayFileName [REPLAY_FILE_NAME_LENGTH]
 replay filename More...
 
char replayLine [MAX_LOG_LINE_LENGTH]
 
int replayLogLine
 
UReplayreplayParent
 
UTime replayTimeNext
 

Private Member Functions

int advanceNmeaMessage (char *rxBuff, int rxBuffCnt, char *pEnd)
 
void clear ()
 
UTime getTimeLocal ()
 
bool hasNmeaMessage (char *rxBuff, int rxBuffCnt, char **pEnd)
 
bool parseNMEA (char *inBuf, UTime tod)
 Function to transform from Lat-Long to UTM in a given zone. More...
 

Private Attributes

UTime lastTime
 
UGpsLatLong latLong
 received Lat-Long position More...
 
bool latLongUpdated
 set when Lat-Long is updated More...
 
ULogFile log2
 debug log More...
 
UTime msgTime
 Local computer time for last message - to be used in UTM pose history. More...
 
char replaySentence [GPS_SENTENCE_MAX_LENGTH]
 replay line in NMEA format to replay More...
 
ULock replaySentenceLock
 lock to protect integrity of sentence More...
 
bool replaySentenceNew
 is new replay data available More...
 
char sentence [GPS_SENTENCE_MAX_LENGTH]
 last message received More...
 
UGpsStatus status
 Status of the GPS reception. More...
 
bool statusUpdated
 set when status is updated More...
 
UGpsUTM utm
 Received UTM position. More...
 
bool utmUpdated
 set when utm is updated More...
 
UVariablevarBaud
 device baudrate More...
 
UVariablevarDevice
 device file name More...
 
UVariablevarDop
 Dilution of position 1 is perfect, 5 is fair, >8 is bad. More...
 
UVariablevarEasting
 index to UTM Easting in current zone in meter More...
 
UVariablevarEgnos
 index to EGNOS variable More...
 
UVariablevarFixRate
 Number of fixes per second. More...
 
UVariablevarGmt
 Last received GMT time. More...
 
UVariablevarGmts
 Last received GMT time. More...
 
UVariablevarGPGGA
 
UVariablevarGPGLL
 
UVariablevarGPGSA
 
UVariablevarGPGSV
 
UVariablevarGPRMC
 
UVariablevarGPVTG
 NMEA strings. More...
 
UVariablevarHeading
 index to Heading received from GPS (compas degrees) More...
 
UVariablevarHeight
 Longitude in decimal degrees, positive is East. More...
 
UVariablevarLat
 Latitude in decimal degrees, positive is North. More...
 
UVariablevarLong
 Longitude in decimal degrees, positive is East. More...
 
UVariablevarMakeUTM
 Do automatic conversion to UTM. More...
 
UVariablevarMapPoseKeep
 Maintain Map-pose with UTM coordinates. More...
 
UVariablevarMapPoseRef
 Map-pose set with UTM coordinates relative to this position [east, north]. More...
 
UVariablevarMode
 index to gps mode (1=noFix 3 = 3D fix) More...
 
UVariablevarNorthing
 UTM northing in current zone in meter. More...
 
UVariablevarOpen
 device file name More...
 
UVariablevarPTNL
 
UVariablevarSatsUsed
 Number of used satelites in calculation. More...
 
UVariablevarSatsVisible
 Number of visible satellites. More...
 
UVariablevarSpeed
 index to Speed received from GPS [m/s] More...
 
UVariablevarTime
 Last fix time. More...
 
UVariablevarTimes
 Last fix time. More...
 
UVariablevarUpdCntLL
 index to number of UTM updates received More...
 
UVariablevarUpdCntUTM
 index to replay flag More...
 
UVariablevarUseOdoHeading
 use odometry history to estimate heading for map and utm pose update More...
 
UVariablevarUtmPoseKeep
 Maintain UTM-pose with raw UTM coordinates. More...
 
UVariablevarUTMZone
 index to variable with UTM zone More...
 

Additional Inherited Members

- Static Protected Attributes inherited from UReplay
static const int MAX_LOG_LINE_LENGTH = 10000
 
static const int REPLAY_FILE_NAME_LENGTH = 264
 max length of replay filename More...
 

Detailed Description

This is the shared resource class. It must enherit from the resource base class (or one of its decendent) as shown.

Author
Christian Andersen

Constructor & Destructor Documentation

UResGps::UResGps ( )
inline

Constructor

UResGps::~UResGps ( )
virtual

Destructor

Member Function Documentation

int UResGps::advanceNmeaMessage ( char *  rxBuff,
int  rxBuffCnt,
char *  pEnd 
)
private

Removes one NMEA message from input buffer, and if there is more than one, then the start of the new message - the '$' is moved to start of buffer, and the new buffer length is returned.If no new measse is found (no '$') then the buffer is returned empty.

Parameters
rxBuffis the buffer to check.
rxBuffCntis the number of bytes in buffer.
pEndis end of massage to be discarded.
Returns
number of bytes in new buffer
char UResGps::ascii2hex ( char  input)
protected

Implementation of a ASCII to HEX coverter.

Takes both upper and lower case ascii values but has no check for non HEX values.

Parameters
[in]inputCharacter input in ascii values
Returns
hex value of the parameter for further processing.
void UResGps::clear ( void  )
private

Clear all structures in this class

void UResGps::closePort ( )
inline

Close serial port

Referenced by UFunctionGps::handleCommand().

void UResGps::createBaseVar ( )
protected

Make the variables that will be available to other plugins

bool UResGps::decodeReplayLine ( char *  line)
virtual

Decode this replay line, that is assumed to be valid.

Parameters
lineis a pointer to the line.
Returns
true if the line is valid and used (step is successfull).
false if line is not a valid step.

Reimplemented from UReplay.

References GPS_SENTENCE_MAX_LENGTH.

const char* UResGps::getDevice ( )
inline

set the serial device filename.

const char* UResGps::getDeviceName ( )
inline

Get serial port name

Referenced by UFunctionGps::handleCommand().

int UResGps::getDeviceSpeed ( )
inline

Get serial port speed (bit/sec) - may not be used if USB device.

Referenced by UFunctionGps::handleCommand().

const char* UResGps::getLastLatLongSentance ( )
inline

Get the latest lat-long received sentence.

UTime UResGps::getLastPositionTime ( )
inline

Get time of laset received sentence position sentence.

References UGpsStatus::clear().

Referenced by UFunctionGps::handleCommand().

const char* UResGps::getLastSentance ( )
inline

Get the latest received sentence - may or may not be used.

References UGpsStatus::sentence.

const char* UResGps::getLastStatusSentance ( )
inline

Get the latest status received sentence.

const char* UResGps::getLastUtmSentance ( )
inline

Get the latest UTM received sentence.

static const char* UResGps::getResClassID ( )
inlinestatic

Fixed name of this resource type

int UResGps::getSpeed ( )
inline

get the serial device speed.

UTime UResGps::getTimeLocal ( )
private

Get time local time for last (lat-long) message

References UTime::getTimeTm(), and UTime::setTime().

UResBase* UResGps::getUtmHist ( )
inline

Get pointer to the UTM pose history structure (or NULL is not available)

bool UResGps::hasNmeaMessage ( char *  rxBuff,
int  rxBuffCnt,
char **  pEnd 
)
private

checks if first character is a '$' and ends with a '*xx' sequence. The CR character after the checksum is replaced by a '\0'

Parameters
rxBuffis the buffer to check.
rxBuffCntis the number of bytes in buffer
pEndwill be set to just after the message (most likely point to LF character after checksum) if there is a message, if no message is found, then pEnd is unchanged. (pEnd may be NULL).
Returns
true if at least one NMEA message is available in buffer
bool UResGps::isConnected ( )

Is the serial port to the GPS open

Referenced by UFunctionGps::handleCommand().

bool UResGps::isLogGpsOpen ( )
inline

Is logfile open

Referenced by UFunctionGps::handleCommand().

void UResGps::openLogfile ( bool  open)
inline

Open (or close) logfile for raw gps data. Nothing happens if trying to open an open file or close a closed file.

Parameters
[in]Setparameter to true to open port and false to close

References ULock::lock(), and ULock::unlock().

Referenced by UFunctionGps::handleCommand().

void UResGps::openPort ( )
inline

Open seial port to GPS

Referenced by UFunctionGps::handleCommand().

bool UResGps::parseNMEA ( char *  inBuf,
UTime  tod 
)
private

Function to transform from Lat-Long to UTM in a given zone.

The algorithm is supplied by Anders Gaasedal and is also used in his truck control project.

Attention
This algorithm is supplied as is. There is no guarantee that is works consistently and without faults. As can be seen from the code there are several unused variables, which there is no use for. This does not give much confidence in the code, but no errors has been seen when parsing messages. Conversion from UTM in a zone to lat-long.
Parameters
[in]eastingin meter relative to central median (+ 500km)
[in]northingin meter from equator
[in]zoneof central meridian
[out]latitudeas calculated (in degrees)
[out]longitudeas calculated (in degrees)
Returns
true. Parser for the contents of the NMEA strings.

Currently GPRMC, GPGGA, GPGSA, GPGSV anf PFST strings are supported.

Parameters
[in]*inBufPointer to the string to be parsed.
[in]*todis the computer time data were received, to be used in utmHistory stack.
Returns
true on validate checksum, else the message is not parsed

References GPS_SENTENCE_MAX_LENGTH, and UGpsStatus::sentence.

const char * UResGps::print ( const char *  preString,
char *  buff,
int  buffCnt 
)
virtual

print status to a string buffer

Reimplemented from UResVarPool.

References bool2str(), and UGpsStatus::sentence.

int UResGps::receiveFromDevice ( FILE *  device,
char *  buff,
int  buffCnt,
const double  timeoutSec 
)
protected

Receive data from device Returns when a newline '
' is received, and there may be more data and possibly more messages. in the received data buffer.

Parameters
[in]'buff'is the buffer place where the received data is stored,
[in]Returnswhen 'buffCnt' is reached - regardless of data
[in]Returnif timeout ('timeoutSec' sec) has passed with no data.
Returns
the number of characters added to the buffer. If a read error occured, then -1 is returned.

References roundi(), and Wait().

void UResGps::run ( )

Run the receice loop for the GPS device. This call do not return until the threadStop flag is set true.

replace with non-blocking - see below

References UTime::Now(), setDeviceSpeed(), UTime::setTimeTod(), UTime::valid, and Wait().

Referenced by threadRunGps().

void UResGps::setDevice ( const char *  value)
inline

set the serial device filename.

Referenced by UFunctionGps::handleCommand().

bool UResGps::setResource ( UResBase resource,
bool  remove 
)
virtual

Set (or remove) ressource (core pointer needed by event handling)

Reimplemented from UResVarPool.

References UResPoseHist::getMapPoseID(), UResPoseHist::getOdoPoseID(), UResPoseHist::getUtmPoseID(), UResBase::isA(), and UResVarPool::setResource().

void UResGps::setSpeed ( int  value)
inline

set the serial device speed.

Referenced by UFunctionGps::handleCommand().

bool UResGps::start ( )
protected

Start read thread

Returns
Returns true if the read thread started.

References threadRunGps().

void UResGps::stop ( )
protected

Stop read thread - and wait for thread join

void UResGps::toLog ( const char *  message)
protected

Save this string to the logfile after a timestamp with current time.

References UTime::getMicrosec(), UTime::getSec(), and UTime::now().

void UResGps::updateVars ( )
protected

Update global variables from received data

References UPose::add(), UPose::h, latlon2UTM(), limitToPi(), UPoseTVQ::set(), utm2latlon(), UPose::x, and UPose::y.

void UResGps::UResGpsInit ( )

Initialize resource

bool UResGps::validateNMEA ( char *  in_buf)
protected

check if this is a valid NMEA message checksum is correct.

Parameters
[in]thesting with the message, of max length GPSSTRINGSIZE.
Returns
true if checksum match

Member Data Documentation

int UResGps::dataRxMsgCnt
protected

Number of full messages received

UTime UResGps::dataRxTime
protected

Timestamp of the letest received data

UTime UResGps::lastTime
private

Last time data was received - including date Used when message holds time but no date, especially needed during replay.

UGpsLatLong UResGps::latLong
private

received Lat-Long position

bool UResGps::latLongUpdated
private

set when Lat-Long is updated

ULogFile UResGps::log2
private

debug log

ULogFile UResGps::logGps

File handle to GPS log

Referenced by UFunctionGps::handleCommand().

char UResGps::logGpsName[MAX_FILENAME_LENGTH]
protected

Name of logfile

UResPoseHist* UResGps::mapPose
protected

Pointer to Map pose history resource

UTime UResGps::msgTime
private

Local computer time for last message - to be used in UTM pose history.

UResPoseHist* UResGps::odoPose
protected

Pointer to odometry pose history resource

char UResGps::replaySentence[GPS_SENTENCE_MAX_LENGTH]
private

replay line in NMEA format to replay

ULock UResGps::replaySentenceLock
private

lock to protect integrity of sentence

bool UResGps::replaySentenceNew
private

is new replay data available

char UResGps::sentence[GPS_SENTENCE_MAX_LENGTH]
private

last message received

UGpsStatus UResGps::status
private

Status of the GPS reception.

bool UResGps::statusUpdated
private

set when status is updated

pthread_t UResGps::threadHandle
protected

Thread handle for frame read thread.

bool UResGps::threadRunning
protected

Is thread actually running

bool UResGps::threadStop
protected

Should thread stop - terminate

UGpsUTM UResGps::utm
private

Received UTM position.

UResPoseHist* UResGps::utmPose
protected

The gps data received from GPS receiver Pointer to UTM pose history resource

bool UResGps::utmUpdated
private

set when utm is updated

UVariable* UResGps::varBaud
private

device baudrate

UVariable* UResGps::varDevice
private

device file name

UVariable* UResGps::varDop
private

Dilution of position 1 is perfect, 5 is fair, >8 is bad.

UVariable* UResGps::varEasting
private

index to UTM Easting in current zone in meter

UVariable* UResGps::varEgnos
private

index to EGNOS variable

UVariable* UResGps::varFixRate
private

Number of fixes per second.

UVariable* UResGps::varGmt
private

Last received GMT time.

UVariable* UResGps::varGmts
private

Last received GMT time.

UVariable* UResGps::varGPGGA
private
UVariable* UResGps::varGPGLL
private
UVariable* UResGps::varGPGSA
private
UVariable* UResGps::varGPGSV
private
UVariable* UResGps::varGPRMC
private
UVariable* UResGps::varGPVTG
private

NMEA strings.

UVariable* UResGps::varHeading
private

index to Heading received from GPS (compas degrees)

UVariable* UResGps::varHeight
private

Longitude in decimal degrees, positive is East.

UVariable* UResGps::varLat
private

Latitude in decimal degrees, positive is North.

UVariable* UResGps::varLong
private

Longitude in decimal degrees, positive is East.

UVariable* UResGps::varMakeUTM
private

Do automatic conversion to UTM.

UVariable* UResGps::varMapPoseKeep
private

Maintain Map-pose with UTM coordinates.

UVariable* UResGps::varMapPoseRef
private

Map-pose set with UTM coordinates relative to this position [east, north].

UVariable* UResGps::varMode
private

index to gps mode (1=noFix 3 = 3D fix)

UVariable* UResGps::varNorthing
private

UTM northing in current zone in meter.

UVariable* UResGps::varOpen
private

device file name

UVariable* UResGps::varPTNL
private
UVariable* UResGps::varSatsUsed
private

Number of used satelites in calculation.

UVariable* UResGps::varSatsVisible
private

Number of visible satellites.

UVariable* UResGps::varSpeed
private

index to Speed received from GPS [m/s]

UVariable* UResGps::varTime
private

Last fix time.

UVariable* UResGps::varTimes
private

Last fix time.

UVariable* UResGps::varUpdCntLL
private

index to number of UTM updates received

UVariable* UResGps::varUpdCntUTM
private

index to replay flag

index to number of UTM updates received

UVariable* UResGps::varUseOdoHeading
private

use odometry history to estimate heading for map and utm pose update

UVariable* UResGps::varUtmPoseKeep
private

Maintain UTM-pose with raw UTM coordinates.

UVariable* UResGps::varUTMZone
private

index to variable with UTM zone


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