You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1026 lines
37 KiB
1026 lines
37 KiB
#include "XA1110_I2C.h"
|
|
#define LOG( X ) m_pLog->Log( "XA1110", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "XA1110", this, _LOG_ERROR, X )
|
|
|
|
#define XA1110_SENTENCE_COUNT 21
|
|
|
|
#define XA1110_SENTENCE_SIZE 5
|
|
|
|
const char *XA1110_SENTENCES[XA1110_SENTENCE_COUNT] = {
|
|
"PMTK0",
|
|
"PMTK5",
|
|
"PMTK7",
|
|
"PMTKS",
|
|
"PGACK",
|
|
"GPGGA",
|
|
"GNGGA",
|
|
"GPGSA",
|
|
"GLGSA",
|
|
"GPGSV",
|
|
"GLGSV",
|
|
"GPRMC",
|
|
"GNRMC",
|
|
"GPVTG",
|
|
"GNVTG",
|
|
"PGACK",
|
|
"PMTKE",
|
|
"PMTKD",
|
|
"PMTKA",
|
|
"GNGLL",
|
|
"GNZDA"
|
|
};
|
|
|
|
sensorXA1110::sensorXA1110( config_setting_t *Settings, PATHFINDER_DBC *DBC ): basicThread(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "UBLOX" );
|
|
m_pBLOG = objectPathfinderBinaryLog::getInstance();
|
|
m_pBus = NULL;
|
|
m_pDBC = DBC;
|
|
m_pDevicePath = "/dev/i2c-1";
|
|
m_bDeviceAddress = 0x10;
|
|
m_nSampleDelay = 100;
|
|
m_bInitStage = 0;
|
|
m_bIssuedCommand = 0;
|
|
m_bIsReady = false;
|
|
memset( &m_sRECORD, 0, sizeof( GPS_EVTREC ));
|
|
memset( &m_sSettings, 0, sizeof( GPS_SETTINGS ));
|
|
};
|
|
|
|
sensorXA1110::~sensorXA1110(){
|
|
waitThreadEnd( true );
|
|
if( m_pBus != NULL ) delete( m_pBus );
|
|
};
|
|
|
|
uint16_t sensorXA1110::finishupPackage( char * ptr ){
|
|
uint16_t clen = 0;
|
|
uint8_t cSum = 0;
|
|
char tVal[3];
|
|
clen = strlen( ptr );
|
|
ptr[0] = '$';
|
|
for( uint16_t idx = 1; idx < clen; idx++ ) {
|
|
cSum = cSum ^ ((uint8_t)ptr[idx]);
|
|
};
|
|
sprintf( tVal, "%02X", cSum );
|
|
ptr[clen] = '*';
|
|
ptr[clen+1] = tVal[0];
|
|
ptr[clen+2] = tVal[1];
|
|
ptr[clen+3] = (char)0x0A;
|
|
ptr[clen+4] = (char)0x0D;
|
|
ptr[clen+5] = (char)0x0A;
|
|
ptr[clen+6] = (char)0x00;
|
|
return clen+6;
|
|
};
|
|
bool sensorXA1110::request_Cold_Start(){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf(tBuffer,"$PMTK103");
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG
|
|
LOG(tBuffer);
|
|
#endif
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::request_Clear_ClearEPO(){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf(tBuffer,"$PMTK127");
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::request_Full_Cold_Start(){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf(tBuffer,"$PMTK104");
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::request_Hot_Start(){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf(tBuffer,"$PMTK101");
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::request_Version(){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf(tBuffer,"$PMTK605");
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 605;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::request_Warm_Start(){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf(tBuffer,"$PMTK102");
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::request_EASY_Status(){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf(tBuffer,"$PMTK869,0");
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::request_GNSS_SearchMode(){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf(tBuffer,"$PMTK355");
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 355;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::set_ConfigDEE( uint8_t SatVisible, uint8_t SignalNoiseRatio, uint32_t threshold, uint32_t gap){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
if( SatVisible < 1 ) SatVisible = 1;
|
|
if( SatVisible > 4 ) SatVisible = 4;
|
|
if( SignalNoiseRatio < 25 ) SignalNoiseRatio = 25;
|
|
if( SignalNoiseRatio > 30 ) SignalNoiseRatio = 30;
|
|
if( threshold < 40000 ) threshold = 40000;
|
|
if( threshold > 180000 ) threshold = 180000;
|
|
if( gap < 40000 ) gap = 40000;
|
|
if( gap > 3600000 ) gap = 3600000;
|
|
sprintf( tBuffer, "$PMTK223,%d,%d,%d,%d", SatVisible, SignalNoiseRatio, threshold, gap );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 223;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::set_ConfigDGPS( uint8_t mode ){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
if( mode > 2 ) mode = 2;
|
|
sprintf( tBuffer, "$PMTK301,%d", mode );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 301;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::set_ConfigDR( uint16_t cnt ){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
if( cnt > 37 ) cnt = 37;
|
|
sprintf( tBuffer, "$PMTK308,%d", cnt );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 308;
|
|
return true;
|
|
};
|
|
bool sensorXA1110::set_ConfigMinimumElevation( uint8_t elv ){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
if( elv > 20 ) elv = 20;
|
|
sprintf( tBuffer, "$PMTK311,%d", elv );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 311;
|
|
return true;
|
|
};
|
|
bool sensorXA1110::set_ConfigMinimumSNR( uint8_t mode ){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
if( mode < 9 ) mode = 9;
|
|
if( mode > 37 ) mode = 37;
|
|
sprintf( tBuffer, "$PMTK306,%d", mode );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 306;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::set_ConfigNMEA( uint8_t GLL, uint8_t RMC, uint8_t VTG, uint8_t GGA, uint8_t GSA, uint8_t GSV, uint8_t ZDA ){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
if( GLL > 5 ) GLL = 5;
|
|
if( RMC > 5 ) RMC = 5;
|
|
if( VTG > 5 ) VTG = 5;
|
|
if( GGA > 5 ) GGA = 5;
|
|
if( GSA > 5 ) GSA = 5;
|
|
if( GSV > 5 ) GSV = 5;
|
|
if( ZDA > 5 ) ZDA = 5;
|
|
sprintf( tBuffer, "$PMTK314,%d,%d,%d,%d,%d,%d,0,0,0,0,0,0,0,0,0,0,0,%d,0,0,0,0", GLL, RMC, VTG, GGA, GSA, GSV, ZDA );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 314;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::set_ConfigSBAS( bool mode ){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf( tBuffer, "$PMTK313,%d", (mode?1:0) );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 313;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::set_DebugMode( bool enabled ){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
sprintf( tBuffer, "$PMTK299,%d", (enabled?1:0) );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 299;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::set_UpdateRate( uint16_t msec ){
|
|
char tBuffer[128];
|
|
if( m_pBus == NULL ) return false;
|
|
if( msec < 100 ) msec = 100;
|
|
if( msec > 1000 ) msec = 1000;
|
|
sprintf( tBuffer, "$PMTK220,%d", msec );
|
|
if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
|
|
#ifdef DEBUG_GPS
|
|
LOG(tBuffer);
|
|
#endif
|
|
m_bIssuedCommand = 220;
|
|
return true;
|
|
};
|
|
|
|
bool sensorXA1110::create(){
|
|
if( m_pDevicePath == NULL ) return false;
|
|
if( m_pBus != NULL ) delete( m_pBus );
|
|
m_pBus = new i2cPort( m_pDevicePath, m_bDeviceAddress, 0, 0 );
|
|
if( m_pBus != NULL ) {
|
|
LOG( "Port Created!" );
|
|
if( m_pDBC != NULL ) {
|
|
m_pDBC->getSettingsGPS( &m_sSettings );
|
|
};
|
|
request_Version();
|
|
SLEEP( 100 );
|
|
m_bIsReady = init();
|
|
return m_bIsReady;
|
|
} else LOG_ERROR("No I2C Bus Created!");
|
|
return false;
|
|
};
|
|
|
|
void sensorXA1110::parsePackage( char * ptr ){
|
|
int8_t bTCM;
|
|
bTCM = -1;
|
|
for( uint8_t idx = 0; idx < XA1110_SENTENCE_COUNT; idx ++ ) {
|
|
if( strncmp( ptr, XA1110_SENTENCES[idx], XA1110_SENTENCE_SIZE ) == 0 ){
|
|
bTCM = idx;
|
|
};
|
|
};
|
|
if( bTCM < 0 ) {
|
|
LOG_ERROR("UNKNOWN PACKAGE");
|
|
LOG_ERROR( ptr );
|
|
} else {
|
|
#ifdef DEBUG_GPS
|
|
char tBuff[256];
|
|
sprintf( tBuff, "PK type is %d [%s]", bTCM, XA1110_SENTENCES[bTCM] );
|
|
LOG( tBuff );
|
|
#endif
|
|
switch( bTCM ) {
|
|
case 0:{
|
|
// PMTK Basic Dev -> Host msgs
|
|
uint16_t tSUB;
|
|
tSUB = atoi( ptr+5 );
|
|
switch( tSUB ) {
|
|
case 1:{
|
|
// ACK
|
|
char * pCOMA;
|
|
uint16_t tRCMD;
|
|
pCOMA = strchr( ptr, ',' );
|
|
if( pCOMA != NULL ) {
|
|
char * pCOMA2;
|
|
tRCMD = atoi( pCOMA+1 );
|
|
pCOMA2 = strchr( pCOMA+1, ',' );
|
|
if( pCOMA2 != NULL ) {
|
|
uint8_t rCODE;
|
|
rCODE = atoi( pCOMA2+1 );
|
|
#ifdef DEBUG_GPS
|
|
sprintf( tBuff, "Ack of CMD[%d] with CODE[%d]", tRCMD ,rCODE );
|
|
LOG( tBuff );
|
|
#endif
|
|
if( m_bIssuedCommand != 0 ) {
|
|
if( m_bIssuedCommand == tRCMD ) {
|
|
#ifdef DEBUG_GPS
|
|
LOG("Previous command Acknolaged!");
|
|
#endif
|
|
if( rCODE == 3 ) m_bInitStage++;
|
|
m_bIssuedCommand = 0;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case 10:{
|
|
// System MSG CODE
|
|
char * pSTAR;
|
|
char * pMSG;
|
|
pSTAR = strrchr( ptr, '*' );
|
|
pMSG = strchr( ptr, ',' );
|
|
if( ( pSTAR != NULL ) && ( pMSG != NULL ) ) {
|
|
uint16_t rCODE;
|
|
pMSG++;
|
|
*pSTAR = (char)0;
|
|
rCODE = atoi( pMSG );
|
|
#ifdef DEBUG_GPS
|
|
sprintf( tBuff, "System MSG with CODE[%d]", rCODE );
|
|
LOG( tBuff );
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
case 11:{
|
|
// System MSG TXT
|
|
char * pSTAR;
|
|
char * pMSG;
|
|
pSTAR = strrchr( ptr, '*' );
|
|
pMSG = strchr( ptr, ',' );
|
|
if( ( pSTAR != NULL ) && ( pMSG != NULL ) ) {
|
|
pMSG++;
|
|
*pSTAR = (char)0;
|
|
#ifdef DEBUG_GPS
|
|
sprintf( tBuff, "System MSG with TEXT[%s]", pMSG );
|
|
LOG( tBuff );
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
default:{
|
|
break;
|
|
};
|
|
};
|
|
LOG( ptr );
|
|
break;
|
|
};
|
|
case 1:{
|
|
// PMTK Advanced ACK
|
|
uint16_t tSUB;
|
|
tSUB = atoi( ptr+5 );
|
|
switch( tSUB ) {
|
|
case 0:{
|
|
// Fix Control Acknowledgment
|
|
char * pCOMA;
|
|
uint16_t tFIX;
|
|
uint16_t tDURATION;
|
|
uint16_t tRUNINTERVAL;
|
|
uint16_t tHACC;
|
|
uint16_t tVACC;
|
|
pCOMA = strchr( ptr, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tFIX = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tDURATION = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tRUNINTERVAL = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tHACC = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tVACC = atoi( pCOMA );
|
|
#ifdef DEBUG_GPS
|
|
sprintf( tBuff, "Fix Control Ack [%d][%d][%d][%d][%d]", tFIX, tDURATION, tRUNINTERVAL, tHACC, tVACC );
|
|
LOG( tBuff );
|
|
#endif
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case 2: {
|
|
// PMTK 7xx Advanced ACK
|
|
uint16_t tSUB;
|
|
tSUB = atoi( ptr+5 );
|
|
switch( tSUB ) {
|
|
case 5:{
|
|
LOG( ptr );
|
|
// Release Version Acknowledgment
|
|
/*char * pCOMA;
|
|
uint16_t tFIX;
|
|
uint16_t tDURATION;
|
|
uint16_t tRUNINTERVAL;
|
|
uint16_t tHACC;
|
|
uint16_t tVACC;
|
|
pCOMA = strchr( ptr, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tFIX = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tDURATION = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tRUNINTERVAL = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tHACC = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tVACC = atoi( pCOMA );
|
|
sprintf( tBuff, "Fix Control Ack [%d][%d][%d][%d][%d]", tFIX, tDURATION, tRUNINTERVAL, tHACC, tVACC );
|
|
LOG( tBuff );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
*/
|
|
break;
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case 3: break;
|
|
case 4: break;
|
|
// GGA Time, Position and Related Data of Navigation Fix
|
|
case 5: parse_GGA( GPS_SYSTEM, ptr ); break;
|
|
case 6: parse_GGA( GLONASS_SYSTEM, ptr ); break;
|
|
// GSA GNSS DOP and Active Satellites, Including GPS and GLONASS
|
|
case 7: parse_GSA( GPS_SYSTEM, ptr ); break;
|
|
case 8: parse_GSA( GLONASS_SYSTEM, ptr ); break;
|
|
// GSV Satellites in View, Including GPS (GPGSV) and GLONASS (GLGSV)
|
|
case 9: parse_GSV( GPS_SYSTEM, ptr ); break;
|
|
case 10: parse_GSV( GLONASS_SYSTEM, ptr ); break;
|
|
// RMC Recommended Minimum Navigation Information
|
|
case 11: parse_RMC( GPS_SYSTEM, ptr ); break;
|
|
case 12: parse_RMC( GLONASS_SYSTEM, ptr ); break;
|
|
// VTG Course and Speed Information Relating to the Ground
|
|
case 13: parse_VTG( GPS_SYSTEM, ptr ); break;
|
|
case 14: parse_VTG( GLONASS_SYSTEM, ptr ); break;
|
|
case 15: break;
|
|
// GLL
|
|
case 19: parse_GLL( ptr ); break;
|
|
};
|
|
};
|
|
};
|
|
|
|
void sensorXA1110::m_fThreadProc( void ){
|
|
uint8_t tBuffer[I2C_PAGE_BYTES];
|
|
char tPackage[2048];
|
|
uint16_t tIDX;
|
|
bool bPackages;
|
|
bool bHaveStart;
|
|
bool bHave0A;
|
|
bool bHave0D;
|
|
uint8_t bCounterTO = 0;
|
|
m_bThreadStatus = TH_WORKING;
|
|
while( m_bThreadStatus < TH_ENDED ){
|
|
if( m_bInitStage < 8 ) {
|
|
switch( m_bInitStage ) {
|
|
case 0:
|
|
if( m_pDBC != NULL ) {
|
|
m_pDBC->getSettingsGPS( &m_sSettings );
|
|
} else{
|
|
LOG_ERROR("No DBC!");
|
|
};
|
|
if( set_DebugMode( m_sSettings.bDEBUG_Mode ) ) {
|
|
m_bInitStage = 1;
|
|
bCounterTO = 0;
|
|
};
|
|
break;
|
|
case 1:
|
|
bCounterTO++;
|
|
if( bCounterTO > 100 ) {
|
|
m_bInitStage = 0;
|
|
}
|
|
break;
|
|
case 2:
|
|
if( set_ConfigNMEA( m_sSettings.bGLL_Rate,
|
|
m_sSettings.bRMC_Rate,
|
|
m_sSettings.bVTG_Rate,
|
|
m_sSettings.bGGA_Rate,
|
|
m_sSettings.bGSA_Rate,
|
|
m_sSettings.bGSV_Rate,
|
|
m_sSettings.bZDA_Rate ) ) {
|
|
m_bInitStage = 3;
|
|
bCounterTO = 0;
|
|
};
|
|
break;
|
|
case 3:
|
|
bCounterTO++;
|
|
if( bCounterTO > 100 ) {
|
|
m_bInitStage = 4;
|
|
}
|
|
break;
|
|
case 4:
|
|
if( set_ConfigDGPS( m_sSettings.bDGPS_Mode ) ) {
|
|
m_bInitStage = 5;
|
|
bCounterTO = 0;
|
|
};
|
|
break;
|
|
case 5:
|
|
bCounterTO++;
|
|
if( bCounterTO > 100 ) {
|
|
m_bInitStage = 6;
|
|
}
|
|
break;
|
|
case 6:
|
|
if( set_UpdateRate( m_sSettings.bFix_Rate ) ){
|
|
m_bInitStage = 7;
|
|
bCounterTO = 0;
|
|
};
|
|
break;
|
|
case 7:
|
|
bCounterTO++;
|
|
if( bCounterTO > 100 ) {
|
|
m_bInitStage = 8;
|
|
bCounterTO = 0;
|
|
}
|
|
break;
|
|
};
|
|
};
|
|
/* Catch some Data from Device! */
|
|
bPackages = false;
|
|
bHaveStart = false;
|
|
bHave0A = false;
|
|
bHave0D = false;
|
|
tIDX = 0;
|
|
do {
|
|
if( m_pBus->readMZ( 0, tBuffer, I2C_PAGE_BYTES ) ){
|
|
if( ( tBuffer[1] == 0x0A ) && ( tBuffer[0] == 0x0A ) ) break;
|
|
for( int idx = 0; idx < I2C_PAGE_BYTES; idx++ ) {
|
|
if( bHaveStart ) {
|
|
if( !bHave0A ) bHave0A = tBuffer[idx] == 0x0A;
|
|
if( !bHave0D ) bHave0D = tBuffer[idx] == 0x0D;
|
|
if( bHave0D && bHave0A ) {
|
|
bCounterTO = 0;
|
|
tPackage[tIDX] = (char)0;
|
|
parsePackage( tPackage );
|
|
bHave0D = false;
|
|
bHave0A = false;
|
|
bHaveStart = false;
|
|
tIDX = 0;
|
|
} else if( ( !bHave0D ) && ( !bHave0A ) ){
|
|
tPackage[tIDX] = (char) tBuffer[idx];
|
|
tIDX++;
|
|
};
|
|
} else bHaveStart = ( tBuffer[idx] == 0x24 );
|
|
if( idx > 0 ) {
|
|
if( ( tBuffer[idx] == 0x0A ) && ( tBuffer[idx-1] == 0x0A ) ){
|
|
bPackages = true;
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
SLEEP( 5 );
|
|
} else {
|
|
bCounterTO++;
|
|
break;
|
|
};
|
|
} while ( ( !bPackages ) && (m_bThreadStatus < TH_ENDED) );
|
|
if( m_bInitStage == 8 ) {
|
|
if( bCounterTO > 10 ) m_bIsReady = false;
|
|
};
|
|
SLEEP( m_nSampleDelay );
|
|
};
|
|
};
|
|
|
|
void sensorXA1110::parse_GGA( uint8_t SYS, char * ptr ){
|
|
uint8_t HH = 0;
|
|
uint8_t MM = 0;
|
|
uint8_t SS = 0;
|
|
uint16_t MS = 0;
|
|
float LAT = .0f;
|
|
float LON = .0f;
|
|
float MSL_ALT = .0f;
|
|
float GEOS = .0f;
|
|
float HDOP = .0f;
|
|
uint8_t FIX = 0;
|
|
uint8_t USAT = 0;
|
|
uint32_t DGPS_AGE = 0;
|
|
PF_TIMESTAMP * ts = NULL;
|
|
|
|
/* tVals */
|
|
double tFV = .0;
|
|
uint32_t tNV = 0;
|
|
char * pCOMA;
|
|
|
|
ts = getPFTS();
|
|
if( ts != NULL ) {
|
|
if( m_sRECORD.fix_type > 0 && m_sRECORD.fix_mode > 0 ){
|
|
// Submit previous
|
|
if( m_pBLOG != NULL ) {
|
|
m_pBLOG->registerGPS( &m_sRECORD );
|
|
};
|
|
if( m_pDBC != NULL ) {
|
|
m_pDBC->updateGPS_DATA( &m_sRECORD );
|
|
};
|
|
// Create New Record
|
|
memset( &m_sRECORD, 0, sizeof(GPS_EVTREC) );
|
|
m_sRECORD.seconds = ts->seconds;
|
|
m_sRECORD.milliseconds = ts->milliseconds;
|
|
};
|
|
tFV = atof( ptr+6 );
|
|
tNV = (uint32_t) tFV;
|
|
HH = tNV / 10000;
|
|
MM = ( tNV % 10000 ) / 100;
|
|
SS = tNV % 100;
|
|
MS = ( tFV - tNV ) * 1000;
|
|
pCOMA = strchr( ptr+6, ',' );
|
|
if( pCOMA != NULL ) {
|
|
uint32_t tDEG;
|
|
pCOMA++;
|
|
tFV = atof( pCOMA );
|
|
tNV = (uint32_t) tFV;
|
|
tDEG = tNV / 100;
|
|
LAT = ((float) tDEG ) + ( ( tFV - ( tDEG * 100.0f ) ) * ( 1.0f / 60.0f ) );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
if( pCOMA[0] == 'S' ) LAT = LAT * (-1.0f);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tFV = atof( pCOMA );
|
|
tNV = (uint32_t) tFV;
|
|
tDEG = tNV / 100;
|
|
LON = ((float) tDEG ) + ( ( tFV - ( tDEG * 100.0f ) ) * ( 1.0f / 60.0f ) );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
if( pCOMA[0] == 'W' ) LON = LON * (-1.0f);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
FIX = atoi(pCOMA);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
USAT = atoi(pCOMA);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
HDOP = atof(pCOMA);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
MSL_ALT = atof(pCOMA);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
GEOS = atof(pCOMA);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
DGPS_AGE = atoi(pCOMA);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
free( ts );
|
|
};
|
|
if( FIX ) {
|
|
m_sRECORD.lat = LAT;
|
|
m_sRECORD.lon = LON;
|
|
m_sRECORD.fix_type = FIX;
|
|
m_sRECORD.geo_separation = GEOS;
|
|
m_sRECORD.msl_alt = MSL_ALT;
|
|
};
|
|
#ifdef DEBUG_GPS
|
|
char tBuff[256];
|
|
sprintf( tBuff, "GGA MSG TS:%02d:%02d:%02d.%03d LAT:%.5f LON:%.5f ALT:%.2f FIX:%d SATS:%d", HH, MM, SS, MS, LAT, LON, MSL_ALT, FIX, USAT );
|
|
LOG( tBuff );
|
|
#endif
|
|
};
|
|
|
|
void sensorXA1110::parse_GSA( uint8_t SYS, char * ptr ){
|
|
char * pCOMA;
|
|
uint8_t CHANELS[12];
|
|
char FixDetectionAutomatic;
|
|
uint8_t FixDetectionType = 0;
|
|
float PDOP = .0f;
|
|
float VDOP = .0f;
|
|
float HDOP = .0f;
|
|
|
|
FixDetectionAutomatic = (ptr+6)[0];
|
|
FixDetectionType = atoi( ptr + 8 );
|
|
|
|
pCOMA = strchr( ptr + 8, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
for(uint8_t idx = 0; idx < 12; idx++ ) {
|
|
CHANELS[idx] = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
};
|
|
};
|
|
PDOP = atof( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
HDOP = atof( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
VDOP = atof( pCOMA );
|
|
};
|
|
};
|
|
};
|
|
if( m_pDBC != NULL ) {
|
|
m_pDBC->updateGPS_STATUS( SYS, FixDetectionAutomatic, FixDetectionType, PDOP, HDOP, VDOP, CHANELS );
|
|
};
|
|
};
|
|
|
|
void sensorXA1110::parse_GLL( char * ptr ){
|
|
if( m_pDBC == NULL ) return;
|
|
LOG( ptr );
|
|
PF_TIMESTAMP * ts = NULL;
|
|
|
|
ts = getPFTS();
|
|
if( ts != NULL ) {
|
|
if( m_sRECORD.fix_type > 0 && m_sRECORD.fix_mode > 0 ){
|
|
// Submit previous
|
|
if( m_pBLOG != NULL ) {
|
|
m_pBLOG->registerGPS( &m_sRECORD );
|
|
};
|
|
if( m_pDBC != NULL ) {
|
|
m_pDBC->updateGPS_DATA( &m_sRECORD );
|
|
};
|
|
// Create New Record
|
|
memset( &m_sRECORD, 0, sizeof(GPS_EVTREC) );
|
|
m_sRECORD.seconds = ts->seconds;
|
|
m_sRECORD.milliseconds = ts->milliseconds;
|
|
};
|
|
free( ts );
|
|
};
|
|
};
|
|
|
|
void sensorXA1110::parse_GSV( uint8_t SYS, char * ptr ){
|
|
if( m_pDBC == NULL ) return;
|
|
GPS_SAT_INFO * tVal = NULL;
|
|
tVal = (GPS_SAT_INFO *) malloc( sizeof(GPS_SAT_INFO));
|
|
if( tVal != NULL ) {
|
|
char * pCOMA;
|
|
char * pSTAR;
|
|
pSTAR = strchr( ptr, '*' );
|
|
pCOMA = strchr( ptr, ',' );
|
|
if( pCOMA != NULL && pSTAR != NULL ){
|
|
pCOMA++;//msgs
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ){
|
|
pCOMA++;//msg
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ){
|
|
pCOMA++;//sat in view
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ){
|
|
while ( ( pCOMA < pSTAR ) && ( pCOMA != NULL ) ) {
|
|
memset(tVal, 0 , sizeof(GPS_SAT_INFO));
|
|
tVal->const_id = SYS;
|
|
pCOMA++;
|
|
tVal->sat_id = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA!= NULL ) {
|
|
pCOMA++;
|
|
tVal->elevation = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA!= NULL ) {
|
|
pCOMA++;
|
|
tVal->azimuth = atoi( pCOMA );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA!= NULL ) {
|
|
pCOMA++;
|
|
tVal->SNR = atoi( pCOMA );
|
|
if( ( tVal->azimuth > 0 ) && ( tVal->elevation > 0 ) ) {
|
|
m_pDBC->updateGPS_SAT_INFO( tVal );
|
|
};
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
free( tVal );
|
|
};
|
|
};
|
|
|
|
void sensorXA1110::parse_RMC( uint8_t SYS, char * ptr ){
|
|
uint8_t HH = 0;
|
|
uint8_t MM = 0;
|
|
uint8_t DE = 0;
|
|
uint8_t MO = 0;
|
|
uint8_t YE = 0;
|
|
uint8_t SS = 0;
|
|
uint16_t MS = 0;
|
|
bool STATUS = false;
|
|
uint8_t MODE = 0;
|
|
float LAT = .0f;
|
|
float LON = .0f;
|
|
float MAGV = .0f;
|
|
float SPEED = .0f;
|
|
float HEADING = .0f;
|
|
|
|
/* tVals */
|
|
double tFV = .0;
|
|
uint32_t tNV = 0;
|
|
char * pCOMA;
|
|
|
|
PF_TIMESTAMP * ts = NULL;
|
|
|
|
ts = getPFTS();
|
|
if( ts != NULL ){
|
|
if( m_sRECORD.fix_type > 0 && m_sRECORD.fix_mode > 0 ){
|
|
// Submit previous
|
|
if( m_pBLOG != NULL ) {
|
|
m_pBLOG->registerGPS( &m_sRECORD );
|
|
};
|
|
if( m_pDBC != NULL ) {
|
|
m_pDBC->updateGPS_DATA( &m_sRECORD );
|
|
};
|
|
// Create New Record
|
|
memset( &m_sRECORD, 0, sizeof(GPS_EVTREC) );
|
|
m_sRECORD.seconds = ts->seconds;
|
|
m_sRECORD.milliseconds = ts->milliseconds;
|
|
};
|
|
|
|
tFV = atof( ptr+6 );
|
|
tNV = (uint32_t) tFV;
|
|
HH = tNV / 10000;
|
|
MM = ( tNV % 10000 ) / 100;
|
|
SS = tNV % 100;
|
|
MS = ( tFV - tNV ) * 1000;
|
|
pCOMA = strchr( ptr+6, ',' );
|
|
if( pCOMA != NULL ){
|
|
pCOMA++;
|
|
STATUS = ( pCOMA[0] == 'A' );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
uint32_t tDEG;
|
|
pCOMA++;
|
|
tFV = atof( pCOMA );
|
|
tNV = (uint32_t) tFV;
|
|
tDEG = tNV / 100;
|
|
LAT = ((float) tDEG ) + ( ( tFV - ( tDEG * 100.0f ) ) * ( 1.0f / 60.0f ) );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
if( pCOMA[0] == 'S' ) LAT = LAT * (-1.0f);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tFV = atof( pCOMA );
|
|
tNV = (uint32_t) tFV;
|
|
tDEG = tNV / 100;
|
|
LON = ((float) tDEG ) + ( ( tFV - ( tDEG * 100.0f ) ) * ( 1.0f / 60.0f ) );
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
if( pCOMA[0] == 'W' ) LON = LON * (-1.0f);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
SPEED = atof(pCOMA);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
HEADING = atof(pCOMA);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
tNV = atoi(pCOMA);
|
|
DE = tNV / 10000;
|
|
MO = (tNV % 10000) / 100;
|
|
YE = tNV % 100;
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
MAGV = atof(pCOMA);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
if( pCOMA[0] == 'W' ) MAGV = MAGV * (-1.0f);
|
|
pCOMA = strchr( pCOMA, ',' );
|
|
if( pCOMA != NULL ) {
|
|
pCOMA++;
|
|
if( pCOMA[0] == 'N' ) MODE = 0;
|
|
if( pCOMA[0] == 'A' ) MODE = 1;
|
|
if( pCOMA[0] == 'D' ) MODE = 2;
|
|
if( pCOMA[0] == 'E' ) MODE = 3;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
free( ts );
|
|
};
|
|
if( STATUS ) {
|
|
m_sRECORD.lat = LAT;
|
|
m_sRECORD.lon = LON;
|
|
m_sRECORD.og_course = HEADING;
|
|
m_sRECORD.og_speed = SPEED;
|
|
m_sRECORD.fix_mode = MODE;
|
|
m_sRECORD.mag_variation = MAGV;
|
|
};
|
|
#ifdef DEBUG_GPS
|
|
char tBuff[256];
|
|
sprintf( tBuff, "RMC MSG TS:%02d-%02d-%02d %02d:%02d:%02d.%03d LAT:%.5f LON:%.5f SPEED:%.2f HEAD:%.2f MAG:%.2f MODE:%d",
|
|
YE, MO, DE, HH, MM, SS, MS, LAT, LON, SPEED, HEADING, MAGV, MODE );
|
|
LOG( tBuff );
|
|
#endif
|
|
};
|
|
|
|
void sensorXA1110::parse_VTG( uint8_t SYS, char * ptr ){
|
|
};
|
|
|
|
float sensorXA1110::getCurrentAlt( void ){
|
|
if(!m_bIsReady) return 0.f;
|
|
return m_sRECORD.msl_alt;
|
|
};
|
|
|
|
uint8_t sensorXA1110::getCurrentFixType( void ){
|
|
if(!m_bIsReady) return 0;
|
|
return m_sRECORD.fix_type;
|
|
};
|
|
|
|
bool sensorXA1110::isDead(){
|
|
return !m_bIsReady;
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|