Mercurial > public > ostc4
comparison Discovery/Src/logbook.c @ 941:6d8ae8fbccf5 Evo_2_23
Added gnss to logbook data:
The gnss position is now available in the logbook. It is stored as event (7:2) at the start of the dive. The position will be shown in the logbook page 1 in the top middle position.
author | Ideenmodellierer |
---|---|
date | Mon, 16 Dec 2024 19:06:37 +0100 |
parents | 63c340abd70e |
children |
comparison
equal
deleted
inserted
replaced
940:4a406e873a95 | 941:6d8ae8fbccf5 |
---|---|
403 length += 2; | 403 length += 2; |
404 sample[2] = 0; | 404 sample[2] = 0; |
405 length++; | 405 length++; |
406 eventByte1.uw = 0; | 406 eventByte1.uw = 0; |
407 eventByte2.uw = 0; | 407 eventByte2.uw = 0; |
408 uint8_t* pdata; | |
408 //uint16_t tmpU16 = 0; | 409 //uint16_t tmpU16 = 0; |
409 const SDecoinfo * pDecoinfo; // new hw 160620 | 410 const SDecoinfo * pDecoinfo; // new hw 160620 |
410 | 411 |
411 //BuildEevntyte 1 | 412 //BuildEevntyte 1 |
412 // sub old 0-3 only one at a time | 413 // sub old 0-3 only one at a time |
460 } | 461 } |
461 if (state->events.compassHeadingUpdate) { | 462 if (state->events.compassHeadingUpdate) { |
462 eventByte1.ub.bit7 = 1; | 463 eventByte1.ub.bit7 = 1; |
463 eventByte2.ub.bit1 = 1; | 464 eventByte2.ub.bit1 = 1; |
464 } | 465 } |
466 if (state->events.gnssPositionUpdate) { | |
467 eventByte1.ub.bit7 = 1; | |
468 eventByte2.ub.bit2 = 1; | |
469 } | |
470 | |
465 //Add EventByte 1 | 471 //Add EventByte 1 |
466 if(eventByte1.uw > 0) | 472 if(eventByte1.uw > 0) |
467 { | 473 { |
468 sample[length] = eventByte1.uw; | 474 sample[length] = eventByte1.uw; |
469 length++; | 475 length++; |
505 if (state->events.compassHeadingUpdate) { | 511 if (state->events.compassHeadingUpdate) { |
506 // New heading and type of heading | 512 // New heading and type of heading |
507 sample[length++] = state->events.info_compassHeadingUpdate & 0xFF; | 513 sample[length++] = state->events.info_compassHeadingUpdate & 0xFF; |
508 sample[length++] = (state->events.info_compassHeadingUpdate & 0xFF00) >> 8; | 514 sample[length++] = (state->events.info_compassHeadingUpdate & 0xFF00) >> 8; |
509 } | 515 } |
510 | 516 if (state->events.gnssPositionUpdate) { |
517 pdata = (uint8_t*)&state->events.info_gnssPosition.fLon; | |
518 sample[length++] = *pdata++; | |
519 sample[length++] = *pdata++; | |
520 sample[length++] = *pdata++; | |
521 sample[length++] = *pdata++; | |
522 pdata = (uint8_t*)&state->events.info_gnssPosition.fLat; | |
523 sample[length++] = *pdata++; | |
524 sample[length++] = *pdata++; | |
525 sample[length++] = *pdata++; | |
526 sample[length++] = *pdata++; | |
527 } | |
511 | 528 |
512 if(divisor.temperature == 0) | 529 if(divisor.temperature == 0) |
513 { | 530 { |
514 divisor.temperature = smallHeader.tempDivisor - 1; | 531 divisor.temperature = smallHeader.tempDivisor - 1; |
515 addS16(&sample[length], (int16_t)((state->lifeData.temperature_celsius * 10.0f) + 0.5f)); | 532 addS16(&sample[length], (int16_t)((state->lifeData.temperature_celsius * 10.0f) + 0.5f)); |
686 * @param int32_t* sensor1, sensor2, sensor3: output Value | 703 * @param int32_t* sensor1, sensor2, sensor3: output Value |
687 * @param int32_t* cns: output Value | 704 * @param int32_t* cns: output Value |
688 * @return bytes read / 0 = reading Error | 705 * @return bytes read / 0 = reading Error |
689 */ | 706 */ |
690 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2, | 707 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2, |
691 int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank, uint8_t* event) | 708 int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank, |
709 SGnssCoord* pPosition, uint8_t* event) | |
692 { | 710 { |
693 int length = 0; | 711 int length = 0; |
694 _Bool bEvent = 0; | 712 _Bool bEvent = 0; |
695 bit8_Type eventByte1, eventByte2; | 713 bit8_Type eventByte1, eventByte2; |
696 bit8_Type profileByteFlag; | 714 bit8_Type profileByteFlag; |
698 eventByte1.uw = 0; | 716 eventByte1.uw = 0; |
699 eventByte2.uw = 0; | 717 eventByte2.uw = 0; |
700 uint8_t tempU8 = 0; | 718 uint8_t tempU8 = 0; |
701 uint16_t temp = 0; | 719 uint16_t temp = 0; |
702 uint16_t bytesRead = 0; | 720 uint16_t bytesRead = 0; |
721 uint32_t tempU32 = 0; | |
722 uint8_t index = 0; | |
703 | 723 |
704 if(gasid) | 724 if(gasid) |
705 *gasid = -1; | 725 *gasid = -1; |
706 if(temperature) | 726 if(temperature) |
707 *temperature = -1000; | 727 *temperature = -1000; |
813 length -= 1; | 833 length -= 1; |
814 manualGas->percentageHe = tempU8; | 834 manualGas->percentageHe = tempU8; |
815 | 835 |
816 if(gasid) | 836 if(gasid) |
817 *gasid = 0; | 837 *gasid = 0; |
838 } | |
839 /* gnss position start dive */ | |
840 if(eventByte2.ub.bit2) | |
841 { | |
842 tempU32 = 0; | |
843 for(index = 0; index < 4; index++) | |
844 { | |
845 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
846 bytesRead +=1; | |
847 length -= 1; | |
848 tempU32 |= (tempU8 << (index * 8)); | |
849 } | |
850 if(tempU32 != 0xffffffff) | |
851 { | |
852 memcpy(&pPosition->fLon, &tempU32, 4); | |
853 } | |
854 tempU32 = 0; | |
855 for(index = 0; index < 4; index++) | |
856 { | |
857 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
858 bytesRead +=1; | |
859 length -= 1; | |
860 tempU32 |= (tempU8 << (index * 8)); | |
861 } | |
862 if(tempU32 != 0xffffffff) | |
863 { | |
864 memcpy(&pPosition->fLat, &tempU32, 4); | |
865 } | |
818 } | 866 } |
819 } | 867 } |
820 | 868 |
821 if(divisor.temperature == 0) | 869 if(divisor.temperature == 0) |
822 { | 870 { |
956 * @param int32_t* cns : output array | 1004 * @param int32_t* cns : output array |
957 * @return length of output | 1005 * @return length of output |
958 */ | 1006 */ |
959 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t* gasid, int16_t* temperature, uint16_t* ppo2, | 1007 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t* gasid, int16_t* temperature, uint16_t* ppo2, |
960 uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout, | 1008 uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout, |
961 uint16_t* decostopDepth, uint16_t* tank, uint8_t* event) | 1009 uint16_t* decostopDepth, uint16_t* tank, SGnssCoord* pPosition, uint8_t* event) |
962 { | 1010 { |
963 //Test read | 1011 //Test read |
964 //SLogbookHeader header; | 1012 //SLogbookHeader header; |
965 | 1013 |
966 //logbook_getHeader(&header); | 1014 //logbook_getHeader(&header); |
993 int16_t decostepDepthVal = 0; | 1041 int16_t decostepDepthVal = 0; |
994 int16_t decostepDepthLast = 0; | 1042 int16_t decostepDepthLast = 0; |
995 uint16_t tankVal = 0; | 1043 uint16_t tankVal = 0; |
996 uint32_t small_profileLength = 0; | 1044 uint32_t small_profileLength = 0; |
997 uint8_t eventdata; | 1045 uint8_t eventdata; |
1046 SGnssCoord posCoord; | |
1047 posCoord.fLat = 0.0; | |
1048 posCoord.fLon = 0.0; | |
998 | 1049 |
999 SManualGas manualGasVal; | 1050 SManualGas manualGasVal; |
1000 SManualGas manualGasLast; | 1051 SManualGas manualGasLast; |
1001 manualGasLast.percentageO2 = 0; | 1052 manualGasLast.percentageO2 = 0; |
1002 manualGasLast.percentageHe = 0; | 1053 manualGasLast.percentageHe = 0; |
1073 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) | 1124 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) |
1074 { | 1125 { |
1075 ext_flash_set_entry_point(); | 1126 ext_flash_set_entry_point(); |
1076 divisorBackup = divisor; | 1127 divisorBackup = divisor; |
1077 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, | 1128 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
1078 &bailoutVal, &decostepDepthVal, &tankVal, &eventdata); | 1129 &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata); |
1079 | 1130 |
1080 if(retVal == 0) | 1131 if(retVal == 0) |
1081 { | 1132 { |
1082 //Error try to read again!!! | 1133 //Error try to read again!!! |
1083 ext_flash_reopen_read_sample_at_entry_point(); | 1134 ext_flash_reopen_read_sample_at_entry_point(); |
1084 divisor = divisorBackup; | 1135 divisor = divisorBackup; |
1085 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, | 1136 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, |
1086 &manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &eventdata); | 1137 &manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata); |
1087 | 1138 |
1088 if(retVal == 0) | 1139 if(retVal == 0) |
1089 break; | 1140 break; |
1090 } | 1141 } |
1091 bytesRead +=retVal; | 1142 bytesRead +=retVal; |
1221 event[iNum] = eventdata; | 1272 event[iNum] = eventdata; |
1222 eventdata = 0; | 1273 eventdata = 0; |
1223 } | 1274 } |
1224 } | 1275 } |
1225 } | 1276 } |
1277 if(pPosition) | |
1278 { | |
1279 memcpy(pPosition, &posCoord, sizeof(posCoord)); | |
1280 } | |
1226 } | 1281 } |
1227 else | 1282 else |
1228 { | 1283 { |
1229 logbook_createDummyProfile(&header, numSamples, depth, temperature, ppo2); | 1284 logbook_createDummyProfile(&header, numSamples, depth, temperature, ppo2); |
1230 iNum = numSamples; | 1285 iNum = numSamples; |
1249 * Automatically Initializes logbook at beginning of dive, | 1304 * Automatically Initializes logbook at beginning of dive, |
1250 * write samples every 2 seconds | 1305 * write samples every 2 seconds |
1251 * and finishes logbook after end of dive | 1306 * and finishes logbook after end of dive |
1252 *********************************************************************************/ | 1307 *********************************************************************************/ |
1253 | 1308 |
1254 void logbook_InitAndWrite(const SDiveState *pStateReal) | 1309 void logbook_InitAndWrite(SDiveState *pStateReal) |
1255 { | 1310 { |
1256 SSettings *pSettings = settingsGetPointer(); | 1311 SSettings *pSettings = settingsGetPointer(); |
1257 static uint8_t bDiveMode = 0; | 1312 static uint8_t bDiveMode = 0; |
1258 static uint32_t tickstart = 0; | 1313 static uint32_t tickstart = 0; |
1259 uint32_t ticksdiff = 0; | 1314 uint32_t ticksdiff = 0; |
1266 { | 1321 { |
1267 //InitdiveProfile | 1322 //InitdiveProfile |
1268 pSettings->totalDiveCounter++; | 1323 pSettings->totalDiveCounter++; |
1269 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); | 1324 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); |
1270 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | 1325 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; |
1326 | |
1271 //Write logbook sample | 1327 //Write logbook sample |
1272 logbook_writeSample(pStateReal); | 1328 logbook_writeSample(pStateReal); |
1273 resetEvents(pStateReal); | 1329 resetEvents(pStateReal); |
1274 tickstart = HAL_GetTick(); | 1330 tickstart = HAL_GetTick(); |
1275 bDiveMode = 1; | 1331 bDiveMode = 1; |
1302 ext_flash_write_settings(0); | 1358 ext_flash_write_settings(0); |
1303 ext_flash_disable_protection_for_logbook(); | 1359 ext_flash_disable_protection_for_logbook(); |
1304 | 1360 |
1305 ext_flash_CloseSector(); /* this is just a repair function which invalidates a not used sector in case a log maintenance was called before dive */ | 1361 ext_flash_CloseSector(); /* this is just a repair function which invalidates a not used sector in case a log maintenance was called before dive */ |
1306 bDiveMode = 3; | 1362 bDiveMode = 3; |
1363 | |
1364 #if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2 | |
1365 pStateReal->events.gnssPositionUpdate = 1; | |
1366 pStateReal->events.info_gnssPosition = pStateReal->lifeData.gnssData.coord; | |
1367 if((pStateReal->events.info_gnssPosition.fLat == 0.0) && (pStateReal->events.info_gnssPosition.fLon == 0.0)) /* no pos => define dummy */ | |
1368 { | |
1369 pStateReal->events.info_gnssPosition.fLon = 47.77; | |
1370 pStateReal->events.info_gnssPosition.fLat = 8.99; | |
1371 } | |
1372 #endif | |
1373 | |
1307 } | 1374 } |
1308 if(bDiveMode == 3) | 1375 if(bDiveMode == 3) |
1309 logbook_UpdateHeader(pStateReal); | 1376 logbook_UpdateHeader(pStateReal); |
1310 } | 1377 } |
1311 } | 1378 } |
1796 int32_t temperatureVal = 0; | 1863 int32_t temperatureVal = 0; |
1797 int32_t sensor1Val = 0; | 1864 int32_t sensor1Val = 0; |
1798 int32_t sensor2Val = 0; | 1865 int32_t sensor2Val = 0; |
1799 int32_t sensor3Val = 0; | 1866 int32_t sensor3Val = 0; |
1800 int32_t cnsVal = 0; | 1867 int32_t cnsVal = 0; |
1801 SManualGas manualGasVal; | 1868 SManualGas manualGasVal; |
1869 int16_t decostepDepthVal = 0; | |
1870 uint16_t tankVal = 0; | |
1871 uint8_t eventdata; | |
1872 SGnssCoord posCoord; | |
1802 | 1873 |
1803 //uint16_t* ppo2, uint16_t* cns# | 1874 //uint16_t* ppo2, uint16_t* cns# |
1804 uint32_t bytesRead = 0; | 1875 uint32_t bytesRead = 0; |
1805 | 1876 |
1806 ext_flash_read_block_start(); | 1877 ext_flash_read_block_start(); |
1816 while (true) | 1887 while (true) |
1817 { | 1888 { |
1818 | 1889 |
1819 ext_flash_set_entry_point(); | 1890 ext_flash_set_entry_point(); |
1820 divisorBackup = divisor; | 1891 divisorBackup = divisor; |
1821 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); | 1892 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
1893 &bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata); | |
1822 if(retVal == 0) | 1894 if(retVal == 0) |
1823 { | 1895 { |
1824 //Error try to read again!!! | 1896 //Error try to read again!!! |
1825 ext_flash_reopen_read_sample_at_entry_point(); | 1897 ext_flash_reopen_read_sample_at_entry_point(); |
1826 divisor = divisorBackup; | 1898 divisor = divisorBackup; |
1827 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); | 1899 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
1828 | 1900 &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata); |
1829 if(retVal == 0) | 1901 if(retVal == 0) |
1830 { | 1902 { |
1831 //Error try to read again!!! | 1903 //Error try to read again!!! |
1832 ext_flash_reopen_read_sample_at_entry_point(); | 1904 ext_flash_reopen_read_sample_at_entry_point(); |
1833 divisor = divisorBackup; | 1905 divisor = divisorBackup; |
1834 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); | 1906 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
1835 | 1907 &bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata); |
1836 if(retVal == 0) | 1908 if(retVal == 0) |
1837 { | 1909 { |
1838 ext_flash_reopen_read_sample_at_entry_point(); | 1910 ext_flash_reopen_read_sample_at_entry_point(); |
1839 break; | 1911 break; |
1840 } | 1912 } |