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

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "XA1110_I2C.h"
  2. #define LOG( X ) m_pLog->Log( "XA1110", this, X )
  3. #define LOG_ERROR( X ) m_pLog->Log( "XA1110", this, _LOG_ERROR, X )
  4. #define XA1110_SENTENCE_COUNT 21
  5. #define XA1110_SENTENCE_SIZE 5
  6. const char *XA1110_SENTENCES[XA1110_SENTENCE_COUNT] = {
  7. "PMTK0",
  8. "PMTK5",
  9. "PMTK7",
  10. "PMTKS",
  11. "PGACK",
  12. "GPGGA",
  13. "GNGGA",
  14. "GPGSA",
  15. "GLGSA",
  16. "GPGSV",
  17. "GLGSV",
  18. "GPRMC",
  19. "GNRMC",
  20. "GPVTG",
  21. "GNVTG",
  22. "PGACK",
  23. "PMTKE",
  24. "PMTKD",
  25. "PMTKA",
  26. "GNGLL",
  27. "GNZDA"
  28. };
  29. sensorXA1110::sensorXA1110( config_setting_t *Settings, PATHFINDER_DBC *DBC ): basicThread(){
  30. m_pLog = basicLogCollection::getInstance();
  31. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "UBLOX" );
  32. m_pBLOG = objectPathfinderBinaryLog::getInstance();
  33. m_pBus = NULL;
  34. m_pDBC = DBC;
  35. m_pDevicePath = "/dev/i2c-1";
  36. m_bDeviceAddress = 0x10;
  37. m_nSampleDelay = 100;
  38. m_bInitStage = 0;
  39. m_bIssuedCommand = 0;
  40. m_bIsReady = false;
  41. memset( &m_sRECORD, 0, sizeof( GPS_EVTREC ));
  42. memset( &m_sSettings, 0, sizeof( GPS_SETTINGS ));
  43. };
  44. sensorXA1110::~sensorXA1110(){
  45. waitThreadEnd( true );
  46. if( m_pBus != NULL ) delete( m_pBus );
  47. };
  48. uint16_t sensorXA1110::finishupPackage( char * ptr ){
  49. uint16_t clen = 0;
  50. uint8_t cSum = 0;
  51. char tVal[3];
  52. clen = strlen( ptr );
  53. ptr[0] = '$';
  54. for( uint16_t idx = 1; idx < clen; idx++ ) {
  55. cSum = cSum ^ ((uint8_t)ptr[idx]);
  56. };
  57. sprintf( tVal, "%02X", cSum );
  58. ptr[clen] = '*';
  59. ptr[clen+1] = tVal[0];
  60. ptr[clen+2] = tVal[1];
  61. ptr[clen+3] = (char)0x0A;
  62. ptr[clen+4] = (char)0x0D;
  63. ptr[clen+5] = (char)0x0A;
  64. ptr[clen+6] = (char)0x00;
  65. return clen+6;
  66. };
  67. bool sensorXA1110::request_Cold_Start(){
  68. char tBuffer[128];
  69. if( m_pBus == NULL ) return false;
  70. sprintf(tBuffer,"$PMTK103");
  71. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  72. #ifdef DEBUG
  73. LOG(tBuffer);
  74. #endif
  75. return true;
  76. };
  77. bool sensorXA1110::request_Clear_ClearEPO(){
  78. char tBuffer[128];
  79. if( m_pBus == NULL ) return false;
  80. sprintf(tBuffer,"$PMTK127");
  81. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  82. #ifdef DEBUG_GPS
  83. LOG(tBuffer);
  84. #endif
  85. return true;
  86. };
  87. bool sensorXA1110::request_Full_Cold_Start(){
  88. char tBuffer[128];
  89. if( m_pBus == NULL ) return false;
  90. sprintf(tBuffer,"$PMTK104");
  91. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  92. #ifdef DEBUG_GPS
  93. LOG(tBuffer);
  94. #endif
  95. return true;
  96. };
  97. bool sensorXA1110::request_Hot_Start(){
  98. char tBuffer[128];
  99. if( m_pBus == NULL ) return false;
  100. sprintf(tBuffer,"$PMTK101");
  101. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  102. #ifdef DEBUG_GPS
  103. LOG(tBuffer);
  104. #endif
  105. return true;
  106. };
  107. bool sensorXA1110::request_Version(){
  108. char tBuffer[128];
  109. if( m_pBus == NULL ) return false;
  110. sprintf(tBuffer,"$PMTK605");
  111. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  112. #ifdef DEBUG_GPS
  113. LOG(tBuffer);
  114. #endif
  115. m_bIssuedCommand = 605;
  116. return true;
  117. };
  118. bool sensorXA1110::request_Warm_Start(){
  119. char tBuffer[128];
  120. if( m_pBus == NULL ) return false;
  121. sprintf(tBuffer,"$PMTK102");
  122. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  123. #ifdef DEBUG_GPS
  124. LOG(tBuffer);
  125. #endif
  126. return true;
  127. };
  128. bool sensorXA1110::request_EASY_Status(){
  129. char tBuffer[128];
  130. if( m_pBus == NULL ) return false;
  131. sprintf(tBuffer,"$PMTK869,0");
  132. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  133. #ifdef DEBUG_GPS
  134. LOG(tBuffer);
  135. #endif
  136. return true;
  137. };
  138. bool sensorXA1110::request_GNSS_SearchMode(){
  139. char tBuffer[128];
  140. if( m_pBus == NULL ) return false;
  141. sprintf(tBuffer,"$PMTK355");
  142. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  143. #ifdef DEBUG_GPS
  144. LOG(tBuffer);
  145. #endif
  146. m_bIssuedCommand = 355;
  147. return true;
  148. };
  149. bool sensorXA1110::set_ConfigDEE( uint8_t SatVisible, uint8_t SignalNoiseRatio, uint32_t threshold, uint32_t gap){
  150. char tBuffer[128];
  151. if( m_pBus == NULL ) return false;
  152. if( SatVisible < 1 ) SatVisible = 1;
  153. if( SatVisible > 4 ) SatVisible = 4;
  154. if( SignalNoiseRatio < 25 ) SignalNoiseRatio = 25;
  155. if( SignalNoiseRatio > 30 ) SignalNoiseRatio = 30;
  156. if( threshold < 40000 ) threshold = 40000;
  157. if( threshold > 180000 ) threshold = 180000;
  158. if( gap < 40000 ) gap = 40000;
  159. if( gap > 3600000 ) gap = 3600000;
  160. sprintf( tBuffer, "$PMTK223,%d,%d,%d,%d", SatVisible, SignalNoiseRatio, threshold, gap );
  161. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  162. #ifdef DEBUG_GPS
  163. LOG(tBuffer);
  164. #endif
  165. m_bIssuedCommand = 223;
  166. return true;
  167. };
  168. bool sensorXA1110::set_ConfigDGPS( uint8_t mode ){
  169. char tBuffer[128];
  170. if( m_pBus == NULL ) return false;
  171. if( mode > 2 ) mode = 2;
  172. sprintf( tBuffer, "$PMTK301,%d", mode );
  173. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  174. #ifdef DEBUG_GPS
  175. LOG(tBuffer);
  176. #endif
  177. m_bIssuedCommand = 301;
  178. return true;
  179. };
  180. bool sensorXA1110::set_ConfigDR( uint16_t cnt ){
  181. char tBuffer[128];
  182. if( m_pBus == NULL ) return false;
  183. if( cnt > 37 ) cnt = 37;
  184. sprintf( tBuffer, "$PMTK308,%d", cnt );
  185. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  186. #ifdef DEBUG_GPS
  187. LOG(tBuffer);
  188. #endif
  189. m_bIssuedCommand = 308;
  190. return true;
  191. };
  192. bool sensorXA1110::set_ConfigMinimumElevation( uint8_t elv ){
  193. char tBuffer[128];
  194. if( m_pBus == NULL ) return false;
  195. if( elv > 20 ) elv = 20;
  196. sprintf( tBuffer, "$PMTK311,%d", elv );
  197. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  198. #ifdef DEBUG_GPS
  199. LOG(tBuffer);
  200. #endif
  201. m_bIssuedCommand = 311;
  202. return true;
  203. };
  204. bool sensorXA1110::set_ConfigMinimumSNR( uint8_t mode ){
  205. char tBuffer[128];
  206. if( m_pBus == NULL ) return false;
  207. if( mode < 9 ) mode = 9;
  208. if( mode > 37 ) mode = 37;
  209. sprintf( tBuffer, "$PMTK306,%d", mode );
  210. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  211. #ifdef DEBUG_GPS
  212. LOG(tBuffer);
  213. #endif
  214. m_bIssuedCommand = 306;
  215. return true;
  216. };
  217. 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 ){
  218. char tBuffer[128];
  219. if( m_pBus == NULL ) return false;
  220. if( GLL > 5 ) GLL = 5;
  221. if( RMC > 5 ) RMC = 5;
  222. if( VTG > 5 ) VTG = 5;
  223. if( GGA > 5 ) GGA = 5;
  224. if( GSA > 5 ) GSA = 5;
  225. if( GSV > 5 ) GSV = 5;
  226. if( ZDA > 5 ) ZDA = 5;
  227. 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 );
  228. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  229. #ifdef DEBUG_GPS
  230. LOG(tBuffer);
  231. #endif
  232. m_bIssuedCommand = 314;
  233. return true;
  234. };
  235. bool sensorXA1110::set_ConfigSBAS( bool mode ){
  236. char tBuffer[128];
  237. if( m_pBus == NULL ) return false;
  238. sprintf( tBuffer, "$PMTK313,%d", (mode?1:0) );
  239. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  240. #ifdef DEBUG_GPS
  241. LOG(tBuffer);
  242. #endif
  243. m_bIssuedCommand = 313;
  244. return true;
  245. };
  246. bool sensorXA1110::set_DebugMode( bool enabled ){
  247. char tBuffer[128];
  248. if( m_pBus == NULL ) return false;
  249. sprintf( tBuffer, "$PMTK299,%d", (enabled?1:0) );
  250. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  251. #ifdef DEBUG_GPS
  252. LOG(tBuffer);
  253. #endif
  254. m_bIssuedCommand = 299;
  255. return true;
  256. };
  257. bool sensorXA1110::set_UpdateRate( uint16_t msec ){
  258. char tBuffer[128];
  259. if( m_pBus == NULL ) return false;
  260. if( msec < 100 ) msec = 100;
  261. if( msec > 1000 ) msec = 1000;
  262. sprintf( tBuffer, "$PMTK220,%d", msec );
  263. if( !m_pBus->writeMZ( 0, (uint8_t *)tBuffer, finishupPackage( tBuffer ) ) ) return false;
  264. #ifdef DEBUG_GPS
  265. LOG(tBuffer);
  266. #endif
  267. m_bIssuedCommand = 220;
  268. return true;
  269. };
  270. bool sensorXA1110::create(){
  271. if( m_pDevicePath == NULL ) return false;
  272. if( m_pBus != NULL ) delete( m_pBus );
  273. m_pBus = new i2cPort( m_pDevicePath, m_bDeviceAddress, 0, 0 );
  274. if( m_pBus != NULL ) {
  275. LOG( "Port Created!" );
  276. if( m_pDBC != NULL ) {
  277. m_pDBC->getSettingsGPS( &m_sSettings );
  278. };
  279. request_Version();
  280. SLEEP( 100 );
  281. m_bIsReady = init();
  282. return m_bIsReady;
  283. } else LOG_ERROR("No I2C Bus Created!");
  284. return false;
  285. };
  286. void sensorXA1110::parsePackage( char * ptr ){
  287. int8_t bTCM;
  288. bTCM = -1;
  289. for( uint8_t idx = 0; idx < XA1110_SENTENCE_COUNT; idx ++ ) {
  290. if( strncmp( ptr, XA1110_SENTENCES[idx], XA1110_SENTENCE_SIZE ) == 0 ){
  291. bTCM = idx;
  292. };
  293. };
  294. if( bTCM < 0 ) {
  295. LOG_ERROR("UNKNOWN PACKAGE");
  296. LOG_ERROR( ptr );
  297. } else {
  298. #ifdef DEBUG_GPS
  299. char tBuff[256];
  300. sprintf( tBuff, "PK type is %d [%s]", bTCM, XA1110_SENTENCES[bTCM] );
  301. LOG( tBuff );
  302. #endif
  303. switch( bTCM ) {
  304. case 0:{
  305. // PMTK Basic Dev -> Host msgs
  306. uint16_t tSUB;
  307. tSUB = atoi( ptr+5 );
  308. switch( tSUB ) {
  309. case 1:{
  310. // ACK
  311. char * pCOMA;
  312. uint16_t tRCMD;
  313. pCOMA = strchr( ptr, ',' );
  314. if( pCOMA != NULL ) {
  315. char * pCOMA2;
  316. tRCMD = atoi( pCOMA+1 );
  317. pCOMA2 = strchr( pCOMA+1, ',' );
  318. if( pCOMA2 != NULL ) {
  319. uint8_t rCODE;
  320. rCODE = atoi( pCOMA2+1 );
  321. #ifdef DEBUG_GPS
  322. sprintf( tBuff, "Ack of CMD[%d] with CODE[%d]", tRCMD ,rCODE );
  323. LOG( tBuff );
  324. #endif
  325. if( m_bIssuedCommand != 0 ) {
  326. if( m_bIssuedCommand == tRCMD ) {
  327. #ifdef DEBUG_GPS
  328. LOG("Previous command Acknolaged!");
  329. #endif
  330. if( rCODE == 3 ) m_bInitStage++;
  331. m_bIssuedCommand = 0;
  332. };
  333. };
  334. };
  335. };
  336. break;
  337. };
  338. case 10:{
  339. // System MSG CODE
  340. char * pSTAR;
  341. char * pMSG;
  342. pSTAR = strrchr( ptr, '*' );
  343. pMSG = strchr( ptr, ',' );
  344. if( ( pSTAR != NULL ) && ( pMSG != NULL ) ) {
  345. uint16_t rCODE;
  346. pMSG++;
  347. *pSTAR = (char)0;
  348. rCODE = atoi( pMSG );
  349. #ifdef DEBUG_GPS
  350. sprintf( tBuff, "System MSG with CODE[%d]", rCODE );
  351. LOG( tBuff );
  352. #endif
  353. };
  354. break;
  355. };
  356. case 11:{
  357. // System MSG TXT
  358. char * pSTAR;
  359. char * pMSG;
  360. pSTAR = strrchr( ptr, '*' );
  361. pMSG = strchr( ptr, ',' );
  362. if( ( pSTAR != NULL ) && ( pMSG != NULL ) ) {
  363. pMSG++;
  364. *pSTAR = (char)0;
  365. #ifdef DEBUG_GPS
  366. sprintf( tBuff, "System MSG with TEXT[%s]", pMSG );
  367. LOG( tBuff );
  368. #endif
  369. };
  370. break;
  371. };
  372. default:{
  373. break;
  374. };
  375. };
  376. LOG( ptr );
  377. break;
  378. };
  379. case 1:{
  380. // PMTK Advanced ACK
  381. uint16_t tSUB;
  382. tSUB = atoi( ptr+5 );
  383. switch( tSUB ) {
  384. case 0:{
  385. // Fix Control Acknowledgment
  386. char * pCOMA;
  387. uint16_t tFIX;
  388. uint16_t tDURATION;
  389. uint16_t tRUNINTERVAL;
  390. uint16_t tHACC;
  391. uint16_t tVACC;
  392. pCOMA = strchr( ptr, ',' );
  393. if( pCOMA != NULL ) {
  394. pCOMA++;
  395. tFIX = atoi( pCOMA );
  396. pCOMA = strchr( pCOMA, ',' );
  397. if( pCOMA != NULL ) {
  398. pCOMA++;
  399. tDURATION = atoi( pCOMA );
  400. pCOMA = strchr( pCOMA, ',' );
  401. if( pCOMA != NULL ) {
  402. pCOMA++;
  403. tRUNINTERVAL = atoi( pCOMA );
  404. pCOMA = strchr( pCOMA, ',' );
  405. if( pCOMA != NULL ) {
  406. pCOMA++;
  407. tHACC = atoi( pCOMA );
  408. pCOMA = strchr( pCOMA, ',' );
  409. if( pCOMA != NULL ) {
  410. pCOMA++;
  411. tVACC = atoi( pCOMA );
  412. #ifdef DEBUG_GPS
  413. sprintf( tBuff, "Fix Control Ack [%d][%d][%d][%d][%d]", tFIX, tDURATION, tRUNINTERVAL, tHACC, tVACC );
  414. LOG( tBuff );
  415. #endif
  416. };
  417. };
  418. };
  419. };
  420. };
  421. break;
  422. };
  423. };
  424. break;
  425. };
  426. case 2: {
  427. // PMTK 7xx Advanced ACK
  428. uint16_t tSUB;
  429. tSUB = atoi( ptr+5 );
  430. switch( tSUB ) {
  431. case 5:{
  432. LOG( ptr );
  433. // Release Version Acknowledgment
  434. /*char * pCOMA;
  435. uint16_t tFIX;
  436. uint16_t tDURATION;
  437. uint16_t tRUNINTERVAL;
  438. uint16_t tHACC;
  439. uint16_t tVACC;
  440. pCOMA = strchr( ptr, ',' );
  441. if( pCOMA != NULL ) {
  442. pCOMA++;
  443. tFIX = atoi( pCOMA );
  444. pCOMA = strchr( pCOMA, ',' );
  445. if( pCOMA != NULL ) {
  446. pCOMA++;
  447. tDURATION = atoi( pCOMA );
  448. pCOMA = strchr( pCOMA, ',' );
  449. if( pCOMA != NULL ) {
  450. pCOMA++;
  451. tRUNINTERVAL = atoi( pCOMA );
  452. pCOMA = strchr( pCOMA, ',' );
  453. if( pCOMA != NULL ) {
  454. pCOMA++;
  455. tHACC = atoi( pCOMA );
  456. pCOMA = strchr( pCOMA, ',' );
  457. if( pCOMA != NULL ) {
  458. pCOMA++;
  459. tVACC = atoi( pCOMA );
  460. sprintf( tBuff, "Fix Control Ack [%d][%d][%d][%d][%d]", tFIX, tDURATION, tRUNINTERVAL, tHACC, tVACC );
  461. LOG( tBuff );
  462. };
  463. };
  464. };
  465. };
  466. };
  467. */
  468. break;
  469. };
  470. };
  471. break;
  472. };
  473. case 3: break;
  474. case 4: break;
  475. // GGA Time, Position and Related Data of Navigation Fix
  476. case 5: parse_GGA( GPS_SYSTEM, ptr ); break;
  477. case 6: parse_GGA( GLONASS_SYSTEM, ptr ); break;
  478. // GSA GNSS DOP and Active Satellites, Including GPS and GLONASS
  479. case 7: parse_GSA( GPS_SYSTEM, ptr ); break;
  480. case 8: parse_GSA( GLONASS_SYSTEM, ptr ); break;
  481. // GSV Satellites in View, Including GPS (GPGSV) and GLONASS (GLGSV)
  482. case 9: parse_GSV( GPS_SYSTEM, ptr ); break;
  483. case 10: parse_GSV( GLONASS_SYSTEM, ptr ); break;
  484. // RMC Recommended Minimum Navigation Information
  485. case 11: parse_RMC( GPS_SYSTEM, ptr ); break;
  486. case 12: parse_RMC( GLONASS_SYSTEM, ptr ); break;
  487. // VTG Course and Speed Information Relating to the Ground
  488. case 13: parse_VTG( GPS_SYSTEM, ptr ); break;
  489. case 14: parse_VTG( GLONASS_SYSTEM, ptr ); break;
  490. case 15: break;
  491. // GLL
  492. case 19: parse_GLL( ptr ); break;
  493. };
  494. };
  495. };
  496. void sensorXA1110::m_fThreadProc( void ){
  497. uint8_t tBuffer[I2C_PAGE_BYTES];
  498. char tPackage[2048];
  499. uint16_t tIDX;
  500. bool bPackages;
  501. bool bHaveStart;
  502. bool bHave0A;
  503. bool bHave0D;
  504. uint8_t bCounterTO = 0;
  505. m_bThreadStatus = TH_WORKING;
  506. while( m_bThreadStatus < TH_ENDED ){
  507. if( m_bInitStage < 8 ) {
  508. switch( m_bInitStage ) {
  509. case 0:
  510. if( m_pDBC != NULL ) {
  511. m_pDBC->getSettingsGPS( &m_sSettings );
  512. } else{
  513. LOG_ERROR("No DBC!");
  514. };
  515. if( set_DebugMode( m_sSettings.bDEBUG_Mode ) ) {
  516. m_bInitStage = 1;
  517. bCounterTO = 0;
  518. };
  519. break;
  520. case 1:
  521. bCounterTO++;
  522. if( bCounterTO > 100 ) {
  523. m_bInitStage = 0;
  524. }
  525. break;
  526. case 2:
  527. if( set_ConfigNMEA( m_sSettings.bGLL_Rate,
  528. m_sSettings.bRMC_Rate,
  529. m_sSettings.bVTG_Rate,
  530. m_sSettings.bGGA_Rate,
  531. m_sSettings.bGSA_Rate,
  532. m_sSettings.bGSV_Rate,
  533. m_sSettings.bZDA_Rate ) ) {
  534. m_bInitStage = 3;
  535. bCounterTO = 0;
  536. };
  537. break;
  538. case 3:
  539. bCounterTO++;
  540. if( bCounterTO > 100 ) {
  541. m_bInitStage = 4;
  542. }
  543. break;
  544. case 4:
  545. if( set_ConfigDGPS( m_sSettings.bDGPS_Mode ) ) {
  546. m_bInitStage = 5;
  547. bCounterTO = 0;
  548. };
  549. break;
  550. case 5:
  551. bCounterTO++;
  552. if( bCounterTO > 100 ) {
  553. m_bInitStage = 6;
  554. }
  555. break;
  556. case 6:
  557. if( set_UpdateRate( m_sSettings.bFix_Rate ) ){
  558. m_bInitStage = 7;
  559. bCounterTO = 0;
  560. };
  561. break;
  562. case 7:
  563. bCounterTO++;
  564. if( bCounterTO > 100 ) {
  565. m_bInitStage = 8;
  566. bCounterTO = 0;
  567. }
  568. break;
  569. };
  570. };
  571. /* Catch some Data from Device! */
  572. bPackages = false;
  573. bHaveStart = false;
  574. bHave0A = false;
  575. bHave0D = false;
  576. tIDX = 0;
  577. do {
  578. if( m_pBus->readMZ( 0, tBuffer, I2C_PAGE_BYTES ) ){
  579. if( ( tBuffer[1] == 0x0A ) && ( tBuffer[0] == 0x0A ) ) break;
  580. for( int idx = 0; idx < I2C_PAGE_BYTES; idx++ ) {
  581. if( bHaveStart ) {
  582. if( !bHave0A ) bHave0A = tBuffer[idx] == 0x0A;
  583. if( !bHave0D ) bHave0D = tBuffer[idx] == 0x0D;
  584. if( bHave0D && bHave0A ) {
  585. bCounterTO = 0;
  586. tPackage[tIDX] = (char)0;
  587. parsePackage( tPackage );
  588. bHave0D = false;
  589. bHave0A = false;
  590. bHaveStart = false;
  591. tIDX = 0;
  592. } else if( ( !bHave0D ) && ( !bHave0A ) ){
  593. tPackage[tIDX] = (char) tBuffer[idx];
  594. tIDX++;
  595. };
  596. } else bHaveStart = ( tBuffer[idx] == 0x24 );
  597. if( idx > 0 ) {
  598. if( ( tBuffer[idx] == 0x0A ) && ( tBuffer[idx-1] == 0x0A ) ){
  599. bPackages = true;
  600. break;
  601. };
  602. };
  603. };
  604. SLEEP( 5 );
  605. } else {
  606. bCounterTO++;
  607. break;
  608. };
  609. } while ( ( !bPackages ) && (m_bThreadStatus < TH_ENDED) );
  610. if( m_bInitStage == 8 ) {
  611. if( bCounterTO > 10 ) m_bIsReady = false;
  612. };
  613. SLEEP( m_nSampleDelay );
  614. };
  615. };
  616. void sensorXA1110::parse_GGA( uint8_t SYS, char * ptr ){
  617. uint8_t HH = 0;
  618. uint8_t MM = 0;
  619. uint8_t SS = 0;
  620. uint16_t MS = 0;
  621. float LAT = .0f;
  622. float LON = .0f;
  623. float MSL_ALT = .0f;
  624. float GEOS = .0f;
  625. float HDOP = .0f;
  626. uint8_t FIX = 0;
  627. uint8_t USAT = 0;
  628. uint32_t DGPS_AGE = 0;
  629. PF_TIMESTAMP * ts = NULL;
  630. /* tVals */
  631. double tFV = .0;
  632. uint32_t tNV = 0;
  633. char * pCOMA;
  634. ts = getPFTS();
  635. if( ts != NULL ) {
  636. if( m_sRECORD.fix_type > 0 && m_sRECORD.fix_mode > 0 ){
  637. // Submit previous
  638. if( m_pBLOG != NULL ) {
  639. m_pBLOG->registerGPS( &m_sRECORD );
  640. };
  641. if( m_pDBC != NULL ) {
  642. m_pDBC->updateGPS_DATA( &m_sRECORD );
  643. };
  644. // Create New Record
  645. memset( &m_sRECORD, 0, sizeof(GPS_EVTREC) );
  646. m_sRECORD.seconds = ts->seconds;
  647. m_sRECORD.milliseconds = ts->milliseconds;
  648. };
  649. tFV = atof( ptr+6 );
  650. tNV = (uint32_t) tFV;
  651. HH = tNV / 10000;
  652. MM = ( tNV % 10000 ) / 100;
  653. SS = tNV % 100;
  654. MS = ( tFV - tNV ) * 1000;
  655. pCOMA = strchr( ptr+6, ',' );
  656. if( pCOMA != NULL ) {
  657. uint32_t tDEG;
  658. pCOMA++;
  659. tFV = atof( pCOMA );
  660. tNV = (uint32_t) tFV;
  661. tDEG = tNV / 100;
  662. LAT = ((float) tDEG ) + ( ( tFV - ( tDEG * 100.0f ) ) * ( 1.0f / 60.0f ) );
  663. pCOMA = strchr( pCOMA, ',' );
  664. if( pCOMA != NULL ) {
  665. pCOMA++;
  666. if( pCOMA[0] == 'S' ) LAT = LAT * (-1.0f);
  667. pCOMA = strchr( pCOMA, ',' );
  668. if( pCOMA != NULL ) {
  669. pCOMA++;
  670. tFV = atof( pCOMA );
  671. tNV = (uint32_t) tFV;
  672. tDEG = tNV / 100;
  673. LON = ((float) tDEG ) + ( ( tFV - ( tDEG * 100.0f ) ) * ( 1.0f / 60.0f ) );
  674. pCOMA = strchr( pCOMA, ',' );
  675. if( pCOMA != NULL ) {
  676. pCOMA++;
  677. if( pCOMA[0] == 'W' ) LON = LON * (-1.0f);
  678. pCOMA = strchr( pCOMA, ',' );
  679. if( pCOMA != NULL ) {
  680. pCOMA++;
  681. FIX = atoi(pCOMA);
  682. pCOMA = strchr( pCOMA, ',' );
  683. if( pCOMA != NULL ) {
  684. pCOMA++;
  685. USAT = atoi(pCOMA);
  686. pCOMA = strchr( pCOMA, ',' );
  687. if( pCOMA != NULL ) {
  688. pCOMA++;
  689. HDOP = atof(pCOMA);
  690. pCOMA = strchr( pCOMA, ',' );
  691. if( pCOMA != NULL ) {
  692. pCOMA++;
  693. MSL_ALT = atof(pCOMA);
  694. pCOMA = strchr( pCOMA, ',' );
  695. if( pCOMA != NULL ) {
  696. pCOMA++;
  697. pCOMA = strchr( pCOMA, ',' );
  698. if( pCOMA != NULL ) {
  699. pCOMA++;
  700. GEOS = atof(pCOMA);
  701. pCOMA = strchr( pCOMA, ',' );
  702. if( pCOMA != NULL ) {
  703. pCOMA++;
  704. pCOMA = strchr( pCOMA, ',' );
  705. if( pCOMA != NULL ) {
  706. pCOMA++;
  707. DGPS_AGE = atoi(pCOMA);
  708. };
  709. };
  710. };
  711. };
  712. };
  713. };
  714. };
  715. };
  716. };
  717. };
  718. };
  719. };
  720. free( ts );
  721. };
  722. if( FIX ) {
  723. m_sRECORD.lat = LAT;
  724. m_sRECORD.lon = LON;
  725. m_sRECORD.fix_type = FIX;
  726. m_sRECORD.geo_separation = GEOS;
  727. m_sRECORD.msl_alt = MSL_ALT;
  728. };
  729. #ifdef DEBUG_GPS
  730. char tBuff[256];
  731. 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 );
  732. LOG( tBuff );
  733. #endif
  734. };
  735. void sensorXA1110::parse_GSA( uint8_t SYS, char * ptr ){
  736. char * pCOMA;
  737. uint8_t CHANELS[12];
  738. char FixDetectionAutomatic;
  739. uint8_t FixDetectionType = 0;
  740. float PDOP = .0f;
  741. float VDOP = .0f;
  742. float HDOP = .0f;
  743. FixDetectionAutomatic = (ptr+6)[0];
  744. FixDetectionType = atoi( ptr + 8 );
  745. pCOMA = strchr( ptr + 8, ',' );
  746. if( pCOMA != NULL ) {
  747. pCOMA++;
  748. for(uint8_t idx = 0; idx < 12; idx++ ) {
  749. CHANELS[idx] = atoi( pCOMA );
  750. pCOMA = strchr( pCOMA, ',' );
  751. if( pCOMA != NULL ) {
  752. pCOMA++;
  753. };
  754. };
  755. PDOP = atof( pCOMA );
  756. pCOMA = strchr( pCOMA, ',' );
  757. if( pCOMA != NULL ) {
  758. pCOMA++;
  759. HDOP = atof( pCOMA );
  760. pCOMA = strchr( pCOMA, ',' );
  761. if( pCOMA != NULL ) {
  762. pCOMA++;
  763. VDOP = atof( pCOMA );
  764. };
  765. };
  766. };
  767. if( m_pDBC != NULL ) {
  768. m_pDBC->updateGPS_STATUS( SYS, FixDetectionAutomatic, FixDetectionType, PDOP, HDOP, VDOP, CHANELS );
  769. };
  770. };
  771. void sensorXA1110::parse_GLL( char * ptr ){
  772. if( m_pDBC == NULL ) return;
  773. LOG( ptr );
  774. PF_TIMESTAMP * ts = NULL;
  775. ts = getPFTS();
  776. if( ts != NULL ) {
  777. if( m_sRECORD.fix_type > 0 && m_sRECORD.fix_mode > 0 ){
  778. // Submit previous
  779. if( m_pBLOG != NULL ) {
  780. m_pBLOG->registerGPS( &m_sRECORD );
  781. };
  782. if( m_pDBC != NULL ) {
  783. m_pDBC->updateGPS_DATA( &m_sRECORD );
  784. };
  785. // Create New Record
  786. memset( &m_sRECORD, 0, sizeof(GPS_EVTREC) );
  787. m_sRECORD.seconds = ts->seconds;
  788. m_sRECORD.milliseconds = ts->milliseconds;
  789. };
  790. free( ts );
  791. };
  792. };
  793. void sensorXA1110::parse_GSV( uint8_t SYS, char * ptr ){
  794. if( m_pDBC == NULL ) return;
  795. GPS_SAT_INFO * tVal = NULL;
  796. tVal = (GPS_SAT_INFO *) malloc( sizeof(GPS_SAT_INFO));
  797. if( tVal != NULL ) {
  798. char * pCOMA;
  799. char * pSTAR;
  800. pSTAR = strchr( ptr, '*' );
  801. pCOMA = strchr( ptr, ',' );
  802. if( pCOMA != NULL && pSTAR != NULL ){
  803. pCOMA++;//msgs
  804. pCOMA = strchr( pCOMA, ',' );
  805. if( pCOMA != NULL ){
  806. pCOMA++;//msg
  807. pCOMA = strchr( pCOMA, ',' );
  808. if( pCOMA != NULL ){
  809. pCOMA++;//sat in view
  810. pCOMA = strchr( pCOMA, ',' );
  811. if( pCOMA != NULL ){
  812. while ( ( pCOMA < pSTAR ) && ( pCOMA != NULL ) ) {
  813. memset(tVal, 0 , sizeof(GPS_SAT_INFO));
  814. tVal->const_id = SYS;
  815. pCOMA++;
  816. tVal->sat_id = atoi( pCOMA );
  817. pCOMA = strchr( pCOMA, ',' );
  818. if( pCOMA!= NULL ) {
  819. pCOMA++;
  820. tVal->elevation = atoi( pCOMA );
  821. pCOMA = strchr( pCOMA, ',' );
  822. if( pCOMA!= NULL ) {
  823. pCOMA++;
  824. tVal->azimuth = atoi( pCOMA );
  825. pCOMA = strchr( pCOMA, ',' );
  826. if( pCOMA!= NULL ) {
  827. pCOMA++;
  828. tVal->SNR = atoi( pCOMA );
  829. if( ( tVal->azimuth > 0 ) && ( tVal->elevation > 0 ) ) {
  830. m_pDBC->updateGPS_SAT_INFO( tVal );
  831. };
  832. pCOMA = strchr( pCOMA, ',' );
  833. };
  834. };
  835. };
  836. };
  837. };
  838. };
  839. };
  840. };
  841. free( tVal );
  842. };
  843. };
  844. void sensorXA1110::parse_RMC( uint8_t SYS, char * ptr ){
  845. uint8_t HH = 0;
  846. uint8_t MM = 0;
  847. uint8_t DE = 0;
  848. uint8_t MO = 0;
  849. uint8_t YE = 0;
  850. uint8_t SS = 0;
  851. uint16_t MS = 0;
  852. bool STATUS = false;
  853. uint8_t MODE = 0;
  854. float LAT = .0f;
  855. float LON = .0f;
  856. float MAGV = .0f;
  857. float SPEED = .0f;
  858. float HEADING = .0f;
  859. /* tVals */
  860. double tFV = .0;
  861. uint32_t tNV = 0;
  862. char * pCOMA;
  863. PF_TIMESTAMP * ts = NULL;
  864. ts = getPFTS();
  865. if( ts != NULL ){
  866. if( m_sRECORD.fix_type > 0 && m_sRECORD.fix_mode > 0 ){
  867. // Submit previous
  868. if( m_pBLOG != NULL ) {
  869. m_pBLOG->registerGPS( &m_sRECORD );
  870. };
  871. if( m_pDBC != NULL ) {
  872. m_pDBC->updateGPS_DATA( &m_sRECORD );
  873. };
  874. // Create New Record
  875. memset( &m_sRECORD, 0, sizeof(GPS_EVTREC) );
  876. m_sRECORD.seconds = ts->seconds;
  877. m_sRECORD.milliseconds = ts->milliseconds;
  878. };
  879. tFV = atof( ptr+6 );
  880. tNV = (uint32_t) tFV;
  881. HH = tNV / 10000;
  882. MM = ( tNV % 10000 ) / 100;
  883. SS = tNV % 100;
  884. MS = ( tFV - tNV ) * 1000;
  885. pCOMA = strchr( ptr+6, ',' );
  886. if( pCOMA != NULL ){
  887. pCOMA++;
  888. STATUS = ( pCOMA[0] == 'A' );
  889. pCOMA = strchr( pCOMA, ',' );
  890. if( pCOMA != NULL ) {
  891. uint32_t tDEG;
  892. pCOMA++;
  893. tFV = atof( pCOMA );
  894. tNV = (uint32_t) tFV;
  895. tDEG = tNV / 100;
  896. LAT = ((float) tDEG ) + ( ( tFV - ( tDEG * 100.0f ) ) * ( 1.0f / 60.0f ) );
  897. pCOMA = strchr( pCOMA, ',' );
  898. if( pCOMA != NULL ) {
  899. pCOMA++;
  900. if( pCOMA[0] == 'S' ) LAT = LAT * (-1.0f);
  901. pCOMA = strchr( pCOMA, ',' );
  902. if( pCOMA != NULL ) {
  903. pCOMA++;
  904. tFV = atof( pCOMA );
  905. tNV = (uint32_t) tFV;
  906. tDEG = tNV / 100;
  907. LON = ((float) tDEG ) + ( ( tFV - ( tDEG * 100.0f ) ) * ( 1.0f / 60.0f ) );
  908. pCOMA = strchr( pCOMA, ',' );
  909. if( pCOMA != NULL ) {
  910. pCOMA++;
  911. if( pCOMA[0] == 'W' ) LON = LON * (-1.0f);
  912. pCOMA = strchr( pCOMA, ',' );
  913. if( pCOMA != NULL ) {
  914. pCOMA++;
  915. SPEED = atof(pCOMA);
  916. pCOMA = strchr( pCOMA, ',' );
  917. if( pCOMA != NULL ) {
  918. pCOMA++;
  919. HEADING = atof(pCOMA);
  920. pCOMA = strchr( pCOMA, ',' );
  921. if( pCOMA != NULL ) {
  922. pCOMA++;
  923. tNV = atoi(pCOMA);
  924. DE = tNV / 10000;
  925. MO = (tNV % 10000) / 100;
  926. YE = tNV % 100;
  927. pCOMA = strchr( pCOMA, ',' );
  928. if( pCOMA != NULL ) {
  929. pCOMA++;
  930. MAGV = atof(pCOMA);
  931. pCOMA = strchr( pCOMA, ',' );
  932. if( pCOMA != NULL ) {
  933. pCOMA++;
  934. if( pCOMA[0] == 'W' ) MAGV = MAGV * (-1.0f);
  935. pCOMA = strchr( pCOMA, ',' );
  936. if( pCOMA != NULL ) {
  937. pCOMA++;
  938. if( pCOMA[0] == 'N' ) MODE = 0;
  939. if( pCOMA[0] == 'A' ) MODE = 1;
  940. if( pCOMA[0] == 'D' ) MODE = 2;
  941. if( pCOMA[0] == 'E' ) MODE = 3;
  942. };
  943. };
  944. };
  945. };
  946. };
  947. };
  948. };
  949. };
  950. };
  951. };
  952. };
  953. free( ts );
  954. };
  955. if( STATUS ) {
  956. m_sRECORD.lat = LAT;
  957. m_sRECORD.lon = LON;
  958. m_sRECORD.og_course = HEADING;
  959. m_sRECORD.og_speed = SPEED;
  960. m_sRECORD.fix_mode = MODE;
  961. m_sRECORD.mag_variation = MAGV;
  962. };
  963. #ifdef DEBUG_GPS
  964. char tBuff[256];
  965. sprintf( tBuff, "RMC MSG TS:%02d-%02d-%02d %02d:%02d:%02d.%03d LAT:%.5f LON:%.5f SPEED:%.2f HEAD:%.2f MAG:%.2f MODE:%d",
  966. YE, MO, DE, HH, MM, SS, MS, LAT, LON, SPEED, HEADING, MAGV, MODE );
  967. LOG( tBuff );
  968. #endif
  969. };
  970. void sensorXA1110::parse_VTG( uint8_t SYS, char * ptr ){
  971. };
  972. float sensorXA1110::getCurrentAlt( void ){
  973. if(!m_bIsReady) return 0.f;
  974. return m_sRECORD.msl_alt;
  975. };
  976. uint8_t sensorXA1110::getCurrentFixType( void ){
  977. if(!m_bIsReady) return 0;
  978. return m_sRECORD.fix_type;
  979. };
  980. bool sensorXA1110::isDead(){
  981. return !m_bIsReady;
  982. };
  983. #undef LOG
  984. #undef LOG_ERROR