Brief description of class still missing. More...
#include <UbxDevice.h>
Public Types | |
| enum | Mode { Off = 0, Track = 1, Stack = 2 } |
| enum | TimeStatus { NoLock, GpsLock, PpsLock, LostPpsLock, LostGpsLock, RecoverLockAfterPpsLost, RecoverLockAfterGpsLost } |
Public Member Functions | |
| bool | isResetGpsDrift () |
| bool | isResetPpsDrift () |
| FILE * | lockFixStream () |
| FILE * | lockRawStream () |
| bool | monitorDriftMode () const |
| unsigned long int | recordingTime () |
| bool | requestNavigation () |
| void | resetGpsDrift () |
| void | resetPpsDrift () |
| void | sendRaw (GpsBuffer *client) |
| void | sendState (GpsBuffer *client) |
| void | setGpsDriftCount (int c) |
| void | setMonitorDriftMode (bool m) |
| void | setPpsDriftCount (int c) |
| void | setSatelliteCount (int c) |
| void | setTimeStatus (TimeStatus s) |
| void | startBroadcast () |
| void | startRecording () |
| void | stopRecording () |
| TimeStatus | timeStatus () |
| UbxDevice (const std::string &stationName, const std::string &basePath, const std::string &devicePath, GpsServer *server) | |
| void | unlockFixStream () |
| void | unlockRawStream () |
| ~UbxDevice () | |
Brief description of class still missing.
Full description of class still missing
| enum UbxDevice::Mode |
| UbxDevice::UbxDevice | ( | const std::string & | stationName, |
| const std::string & | basePath, | ||
| const std::string & | devicePath, | ||
| GpsServer * | server | ||
| ) |
Description of constructor still missing
References NoLock, and GpsServer::setDevice().
: _navigationTimer(this, 300000) // Request ephemeris after 5 minutes after raw start { _stationName=stationName; _basePath=basePath; _server=server; _server->setDevice(this); _serial=new Serial(devicePath, B9600, new UbxBuffer(0, _server, this)); _rawStream=0; _fixStream=0; assert(pthread_mutex_init(&_fixStreamMutex, 0)==0); assert(pthread_mutex_init(&_rawStreamMutex, 0)==0); assert(pthread_mutex_init(&_timeStatusMutex, 0)==0); _timeStatus=NoLock; _resetGpsDrift=false; _resetPpsDrift=false; #ifdef MONITOR_DRIFT_MODE _monitorDriftMode=false; #endif _startRecordingTime=0; _satelliteCount=0; _gpsDriftCount=0; _ppsDriftCount=0; }
Description of destructor still missing
{
closeFixFile();
closeRawFile();
}
| bool UbxDevice::isResetGpsDrift | ( | ) |
Returns true if GPS drift computation needs to be reset. The flag is set back to false.
{
pthread_mutex_lock(&_timeStatusMutex);
bool r=_resetGpsDrift;
_resetGpsDrift=false;
pthread_mutex_unlock(&_timeStatusMutex);
return r;
}
| bool UbxDevice::isResetPpsDrift | ( | ) |
Returns true if PPS drift computation needs to be reset. The flag is set back to false.
Referenced by PPSBuffer::bytesAvailable().
{
pthread_mutex_lock(&_timeStatusMutex);
bool r=_resetPpsDrift;
_resetPpsDrift=false;
pthread_mutex_unlock(&_timeStatusMutex);
return r;
}
| FILE* UbxDevice::lockFixStream | ( | ) | [inline] |
Referenced by startRecording(), and stopRecording().
{pthread_mutex_lock(&_fixStreamMutex); return _fixStream;}
| FILE* UbxDevice::lockRawStream | ( | ) | [inline] |
Referenced by recordingTime(), requestNavigation(), sendRaw(), startRecording(), and stopRecording().
{pthread_mutex_lock(&_rawStreamMutex); return _rawStream;}
| bool UbxDevice::monitorDriftMode | ( | ) | const [inline] |
Referenced by PPSBuffer::bytesAvailable().
{return _monitorDriftMode;}
| unsigned long int UbxDevice::recordingTime | ( | ) |
References lockRawStream(), TRACE, and unlockRawStream().
Referenced by sendState().
{
TRACE;
lockRawStream();
if(_rawStream) {
unlockRawStream();
return time(0)-_startRecordingTime;
} else {
unlockRawStream();
return 0;
}
}
| bool UbxDevice::requestNavigation | ( | ) |
Requests almanach and ephemeris. Executed in the same thread as the serial stream, hence no lock.
References GpCoreTools::Stream::fileDescriptor(), lockRawStream(), unlockRawStream(), and GpCoreTools::Serial::write().
Referenced by GpsBuffer::bytesAvailable(), and NavigationTimer::exec().
{
if(lockRawStream()) {
/* Checksum computation (N is number of bytes from class, id to end of payload)
CK_A=0, CK_B=0
For(I=0;I<N;I++) {
CK_A=CK_A + Buffer[I]
CK_B=CK_B + CK_A
}
*/
// AID-HUI (AID-DATA is returning blocks that are not accepted by teqc)
//static char pollAid[]={0xB5, 0x62, 0x0B, 0x02, 0x00, 0x00, 0x0D, 0x32};
// RXM-ALM
//static char pollAlm[]={0xB5, 0x62, 0x02, 0x30, 0x00, 0x00, 0x32, 0x98};
// RXM-EPH
static char pollEph[]={0xB5, 0x62, 0x02, 0x31, 0x00, 0x00, 0x33, 0x9B};
if(_serial->fileDescriptor()>0) {
//_serial->write(pollAid, 8);
//_serial->write(pollAlm, 8);
_serial->write(pollEph, 8);
Log::write(1, "request ephemeris\n");
}
unlockRawStream();
return true;
} else {
unlockRawStream();
return false;
}
}
| void UbxDevice::resetGpsDrift | ( | ) |
Sets flag to reset GPS drift computation whenever time is strongly modified by PPS thread.
Referenced by PPSBuffer::bytesAvailable().
{
pthread_mutex_lock(&_timeStatusMutex);
_resetGpsDrift=true;
pthread_mutex_unlock(&_timeStatusMutex);
}
| void UbxDevice::resetPpsDrift | ( | ) |
Sets flag to reset PPS drift computation whenever time is strongly modified by GPS thread.
{
pthread_mutex_lock(&_timeStatusMutex);
_resetPpsDrift=true;
pthread_mutex_unlock(&_timeStatusMutex);
}
| void UbxDevice::sendRaw | ( | GpsBuffer * | client | ) |
References GpCoreTools::FletcherChecksum::a, GpCoreTools::FletcherChecksum::add(), GpCoreTools::FletcherChecksum::b, lockRawStream(), GpCoreTools::DynamicBuffer::send(), TRACE, and unlockRawStream().
Referenced by GpsBuffer::bytesAvailable().
{
TRACE;
lockRawStream();
if(_rawFileName.size()==0) {
unlockRawStream();
return;
}
FILE * f=fopen(_rawFileName.data(), "rb");
unlockRawStream();
client->send("raw begin\n", 10);
char buffer[512];
FletcherChecksum chk;
while(!feof(f)) {
size_t readBytes=fread(buffer, 1, 512, f);
chk.add(buffer, readBytes);
client->send(buffer, readBytes);
}
char chkbuf[32];
snprintf(chkbuf, 32, "raw checksum=%02hhX%02hhX\n", chk.a(), chk.b());
client->send(chkbuf, strlen(chkbuf));
fclose(f);
}
| void UbxDevice::sendState | ( | GpsBuffer * | client | ) |
Returns a string describing current state
References GpCoreTools::Stream::fileDescriptor(), GpsLock, GpCoreTools::Serial::lock(), LostGpsLock, LostPpsLock, NoLock, PpsLock, recordingTime(), RecoverLockAfterGpsLost, RecoverLockAfterPpsLost, GpCoreTools::DynamicBuffer::send(), timeStatus(), and GpCoreTools::Serial::unlock().
Referenced by GpsBuffer::bytesAvailable().
{
char buf[64];
_serial->lock();
if(_serial->fileDescriptor()) {
_serial->unlock();
if(_fixStream && _rawStream) {
snprintf(buf, 64, "state=recording %lu s\n", recordingTime());
client->send(buf, strlen(buf));
} else {
TimeStatus t=timeStatus();
switch(t) {
case NoLock:
if(_gpsDriftCount==0) {
snprintf(buf, 64, "state=stopped (no lock: %i sv)\n", _satelliteCount);
} else {
snprintf(buf, 64, "state=stopped (GPS locking... %i)\n", _gpsDriftCount);
}
break;
case GpsLock:
snprintf(buf, 64, "state=stopped (PPS locking... %i)\n", _ppsDriftCount);
break;
case PpsLock:
snprintf(buf, 64, "state=stopped (PPS locked)\n");
break;
case LostPpsLock:
if(_gpsDriftCount==0) {
snprintf(buf, 64, "state=stopped (lost PPS: %i sv)\n", _satelliteCount);
} else {
client->send("state=stopped (GPS locking... %i)\n", _gpsDriftCount);
}
break;
case LostGpsLock:
if(_gpsDriftCount==0) {
snprintf(buf, 64, "state=stopped (lost GPS: %i sv)\n", _satelliteCount);
} else {
client->send("state=stopped (GPS locking... %i)\n", _gpsDriftCount);
}
break;
case RecoverLockAfterPpsLost:
client->send("state=stopped (PPS locking... %i)\n", _ppsDriftCount);
break;
case RecoverLockAfterGpsLost:
client->send("state=stopped (PPS locking... %i)\n", _ppsDriftCount);
break;
}
client->send(buf, strlen(buf));
}
} else {
_serial->unlock();
client->send("state=disconnected\n", 19);
}
}
| void UbxDevice::setGpsDriftCount | ( | int | c | ) | [inline] |
{_gpsDriftCount=c;}
| void UbxDevice::setMonitorDriftMode | ( | bool | m | ) | [inline] |
Referenced by main().
{_monitorDriftMode=m;}
| void UbxDevice::setPpsDriftCount | ( | int | c | ) | [inline] |
Referenced by PPSBuffer::bytesAvailable().
{_ppsDriftCount=c;}
| void UbxDevice::setSatelliteCount | ( | int | c | ) | [inline] |
{_satelliteCount=c;}
| void UbxDevice::setTimeStatus | ( | TimeStatus | s | ) |
Called by UbxBuffer and PPSTime when time is locked
References GpsLock, LostGpsLock, LostPpsLock, NoLock, PpsLock, RecoverLockAfterGpsLost, RecoverLockAfterPpsLost, startRecording(), and stopRecording().
Referenced by PPSBuffer::bytesAvailable().
{
pthread_mutex_lock(&_timeStatusMutex);
switch(_timeStatus) {
case NoLock:
if(s==GpsLock) {
_timeStatus=GpsLock;
}
// Ignores PPS locks if there is no GPS lock
break;
case GpsLock:
if(s==PpsLock) {
_timeStatus=PpsLock;
pthread_mutex_unlock(&_timeStatusMutex);
// Delayed opening of fix and raw files (not before having a correct clock)
stopRecording();
startRecording();
// Send "signal" to other process that internal clock is locked on GPS
FILE * f=fopen("/tmp/system_clock_set", "wb");
if(f) {
if(fwrite("GPS", 1, 3, f)!=3) {
Log::write(0, "error writing to /tmp/system_clock_set\n");
}
fclose(f);
} else {
Log::write(0, "cannot open file /tmp/system_clock_set for writing\n");
}
return;
}
break;
case PpsLock:
if(s==LostPpsLock) { // Lost PPS synchronisation
Log::write(0, "pps synchronisation lost\n");
_gpsDriftCount=0;
_ppsDriftCount=0;
_timeStatus=LostPpsLock;
} else if(s==LostGpsLock) {
Log::write(0, "gps synchronisation lost\n");
_gpsDriftCount=0;
_ppsDriftCount=0;
_timeStatus=LostGpsLock;
sendSeismic("stop\n");
}
break;
case LostPpsLock:
if(s==GpsLock) {
_timeStatus=RecoverLockAfterPpsLost;
}
break;
case LostGpsLock:
if(s==GpsLock) {
_timeStatus=RecoverLockAfterGpsLost;
}
break;
case RecoverLockAfterPpsLost:
if(s==PpsLock) {
Log::write(0, "pps synchronisation recovered after pps lost\n");
_timeStatus=PpsLock;
}
break;
case RecoverLockAfterGpsLost:
if(s==PpsLock) {
Log::write(0, "pps synchronisation recovered after gpc lost\n");
_timeStatus=PpsLock;
sendSeismic("start\n");
}
break;
}
pthread_mutex_unlock(&_timeStatusMutex);
}
| void UbxDevice::startBroadcast | ( | ) |
References GpCoreTools::Serial::buffer(), GpCoreTools::Stream::fileDescriptor(), GpCoreTools::Serial::lock(), and GpCoreTools::Serial::unlock().
Referenced by GpsBuffer::bytesAvailable().
{
_serial->lock();
if(_serial->fileDescriptor()) {
static_cast<UbxBuffer *>(_serial->buffer())->startBroadcast();
Log::write(1, "broadcast fix reset\n");
}
_serial->unlock();
}
| void UbxDevice::startRecording | ( | ) |
Start files
References lockFixStream(), lockRawStream(), PpsLock, unlockFixStream(), and unlockRawStream().
Referenced by GpsBuffer::bytesAvailable(), and setTimeStatus().
{
pthread_mutex_lock(&_timeStatusMutex);
if(_timeStatus==PpsLock) {
pthread_mutex_unlock(&_timeStatusMutex);
lockFixStream();
lockRawStream();
openFixFile();
openRawFile();
unlockFixStream();
unlockRawStream();
} else {
pthread_mutex_unlock(&_timeStatusMutex);
}
}
| void UbxDevice::stopRecording | ( | ) |
Start files
References lockFixStream(), lockRawStream(), PpsLock, unlockFixStream(), and unlockRawStream().
Referenced by GpsBuffer::bytesAvailable(), and setTimeStatus().
{
pthread_mutex_lock(&_timeStatusMutex);
if(_timeStatus==PpsLock) {
pthread_mutex_unlock(&_timeStatusMutex);
lockFixStream();
lockRawStream();
closeFixFile();
closeRawFile();
unlockFixStream();
unlockRawStream();
} else {
pthread_mutex_unlock(&_timeStatusMutex);
}
}
Returns current status versus GPS and PPS synchronization
Referenced by PPSBuffer::bytesAvailable(), and sendState().
{
pthread_mutex_lock(&_timeStatusMutex);
TimeStatus s=_timeStatus;
pthread_mutex_unlock(&_timeStatusMutex);
return s;
}
| void UbxDevice::unlockFixStream | ( | ) | [inline] |
Referenced by startRecording(), and stopRecording().
{pthread_mutex_unlock(&_fixStreamMutex);}
| void UbxDevice::unlockRawStream | ( | ) | [inline] |
Referenced by recordingTime(), requestNavigation(), sendRaw(), startRecording(), and stopRecording().
{pthread_mutex_unlock(&_rawStreamMutex);}