comparison Discovery/Src/logbook.c @ 981:c6c781a2e85b default

Merge into default
author heinrichsweikamp
date Tue, 11 Feb 2025 18:12:00 +0100
parents 9b29995d6619
children d9290c76b840
comparison
equal deleted inserted replaced
871:f7318457df4d 981:c6c781a2e85b
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
456 if(state->events.bailout) 457 if(state->events.bailout)
457 { 458 {
458 eventByte1.ub.bit7 = 1; 459 eventByte1.ub.bit7 = 1;
459 eventByte2.ub.bit0 = 1; 460 eventByte2.ub.bit0 = 1;
460 } 461 }
462 if (state->events.compassHeadingUpdate) {
463 eventByte1.ub.bit7 = 1;
464 eventByte2.ub.bit1 = 1;
465 }
466 if (state->events.gnssPositionUpdate) {
467 eventByte1.ub.bit7 = 1;
468 eventByte2.ub.bit2 = 1;
469 }
470
461 //Add EventByte 1 471 //Add EventByte 1
462 if(eventByte1.uw > 0) 472 if(eventByte1.uw > 0)
463 { 473 {
464 sample[length] = eventByte1.uw; 474 sample[length] = eventByte1.uw;
465 length++; 475 length++;
496 sample[length] = state->events.info_bailoutO2; 506 sample[length] = state->events.info_bailoutO2;
497 length += 1; 507 length += 1;
498 sample[length] = state->events.info_bailoutHe; 508 sample[length] = state->events.info_bailoutHe;
499 length += 1; 509 length += 1;
500 } 510 }
501 511 if (state->events.compassHeadingUpdate) {
512 // New heading and type of heading
513 sample[length++] = state->events.info_compassHeadingUpdate & 0xFF;
514 sample[length++] = (state->events.info_compassHeadingUpdate & 0xFF00) >> 8;
515 }
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 }
502 528
503 if(divisor.temperature == 0) 529 if(divisor.temperature == 0)
504 { 530 {
505 divisor.temperature = smallHeader.tempDivisor - 1; 531 divisor.temperature = smallHeader.tempDivisor - 1;
506 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));
677 * @param int32_t* sensor1, sensor2, sensor3: output Value 703 * @param int32_t* sensor1, sensor2, sensor3: output Value
678 * @param int32_t* cns: output Value 704 * @param int32_t* cns: output Value
679 * @return bytes read / 0 = reading Error 705 * @return bytes read / 0 = reading Error
680 */ 706 */
681 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,
682 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)
683 { 710 {
684 int length = 0; 711 int length = 0;
685 _Bool bEvent = 0; 712 _Bool bEvent = 0;
686 bit8_Type eventByte1, eventByte2; 713 bit8_Type eventByte1, eventByte2;
687 bit8_Type profileByteFlag; 714 bit8_Type profileByteFlag;
689 eventByte1.uw = 0; 716 eventByte1.uw = 0;
690 eventByte2.uw = 0; 717 eventByte2.uw = 0;
691 uint8_t tempU8 = 0; 718 uint8_t tempU8 = 0;
692 uint16_t temp = 0; 719 uint16_t temp = 0;
693 uint16_t bytesRead = 0; 720 uint16_t bytesRead = 0;
721 uint32_t tempU32 = 0;
722 uint8_t index = 0;
694 723
695 if(gasid) 724 if(gasid)
696 *gasid = -1; 725 *gasid = -1;
697 if(temperature) 726 if(temperature)
698 *temperature = -1000; 727 *temperature = -1000;
804 length -= 1; 833 length -= 1;
805 manualGas->percentageHe = tempU8; 834 manualGas->percentageHe = tempU8;
806 835
807 if(gasid) 836 if(gasid)
808 *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 }
809 } 866 }
810 } 867 }
811 868
812 if(divisor.temperature == 0) 869 if(divisor.temperature == 0)
813 { 870 {
947 * @param int32_t* cns : output array 1004 * @param int32_t* cns : output array
948 * @return length of output 1005 * @return length of output
949 */ 1006 */
950 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,
951 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,
952 uint16_t* decostopDepth, uint16_t* tank, uint8_t* event) 1009 uint16_t* decostopDepth, uint16_t* tank, SGnssCoord* pPosition, uint8_t* event)
953 { 1010 {
954 //Test read 1011 //Test read
955 //SLogbookHeader header; 1012 //SLogbookHeader header;
956 1013
957 //logbook_getHeader(&header); 1014 //logbook_getHeader(&header);
984 int16_t decostepDepthVal = 0; 1041 int16_t decostepDepthVal = 0;
985 int16_t decostepDepthLast = 0; 1042 int16_t decostepDepthLast = 0;
986 uint16_t tankVal = 0; 1043 uint16_t tankVal = 0;
987 uint32_t small_profileLength = 0; 1044 uint32_t small_profileLength = 0;
988 uint8_t eventdata; 1045 uint8_t eventdata;
1046 SGnssCoord posCoord;
1047 posCoord.fLat = 0.0;
1048 posCoord.fLon = 0.0;
989 1049
990 SManualGas manualGasVal; 1050 SManualGas manualGasVal;
991 SManualGas manualGasLast; 1051 SManualGas manualGasLast;
992 manualGasLast.percentageO2 = 0; 1052 manualGasLast.percentageO2 = 0;
993 manualGasLast.percentageHe = 0; 1053 manualGasLast.percentageHe = 0;
1064 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) 1124 while ((bytesRead < totalNumberOfBytes) && (iNum < length))
1065 { 1125 {
1066 ext_flash_set_entry_point(); 1126 ext_flash_set_entry_point();
1067 divisorBackup = divisor; 1127 divisorBackup = divisor;
1068 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, 1128 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
1069 &bailoutVal, &decostepDepthVal, &tankVal, &eventdata); 1129 &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
1070 1130
1071 if(retVal == 0) 1131 if(retVal == 0)
1072 { 1132 {
1073 //Error try to read again!!! 1133 //Error try to read again!!!
1074 ext_flash_reopen_read_sample_at_entry_point(); 1134 ext_flash_reopen_read_sample_at_entry_point();
1075 divisor = divisorBackup; 1135 divisor = divisorBackup;
1076 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, 1136 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal,
1077 &manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &eventdata); 1137 &manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
1078 1138
1079 if(retVal == 0) 1139 if(retVal == 0)
1080 break; 1140 break;
1081 } 1141 }
1082 bytesRead +=retVal; 1142 bytesRead +=retVal;
1212 event[iNum] = eventdata; 1272 event[iNum] = eventdata;
1213 eventdata = 0; 1273 eventdata = 0;
1214 } 1274 }
1215 } 1275 }
1216 } 1276 }
1277 if(pPosition)
1278 {
1279 memcpy(pPosition, &posCoord, sizeof(posCoord));
1280 }
1217 } 1281 }
1218 else 1282 else
1219 { 1283 {
1220 logbook_createDummyProfile(&header, numSamples, depth, temperature, ppo2); 1284 logbook_createDummyProfile(&header, numSamples, depth, temperature, ppo2);
1221 iNum = numSamples; 1285 iNum = numSamples;
1240 * Automatically Initializes logbook at beginning of dive, 1304 * Automatically Initializes logbook at beginning of dive,
1241 * write samples every 2 seconds 1305 * write samples every 2 seconds
1242 * and finishes logbook after end of dive 1306 * and finishes logbook after end of dive
1243 *********************************************************************************/ 1307 *********************************************************************************/
1244 1308
1245 void logbook_InitAndWrite(const SDiveState *pStateReal) 1309 void logbook_InitAndWrite(SDiveState *pStateReal)
1246 { 1310 {
1247 SSettings *pSettings = settingsGetPointer(); 1311 SSettings *pSettings = settingsGetPointer();
1248 static uint8_t bDiveMode = 0; 1312 static uint8_t bDiveMode = 0;
1249 static uint32_t tickstart = 0; 1313 static uint32_t tickstart = 0;
1250 uint32_t ticksdiff = 0; 1314 uint32_t ticksdiff = 0;
1257 { 1321 {
1258 //InitdiveProfile 1322 //InitdiveProfile
1259 pSettings->totalDiveCounter++; 1323 pSettings->totalDiveCounter++;
1260 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); 1324 logbook_initNewdiveProfile(pStateReal,settingsGetPointer());
1261 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; 1325 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius;
1326
1262 //Write logbook sample 1327 //Write logbook sample
1263 logbook_writeSample(pStateReal); 1328 logbook_writeSample(pStateReal);
1264 resetEvents(pStateReal); 1329 resetEvents(pStateReal);
1265 tickstart = HAL_GetTick(); 1330 tickstart = HAL_GetTick();
1266 bDiveMode = 1; 1331 bDiveMode = 1;
1293 ext_flash_write_settings(0); 1358 ext_flash_write_settings(0);
1294 ext_flash_disable_protection_for_logbook(); 1359 ext_flash_disable_protection_for_logbook();
1295 1360
1296 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 */
1297 bDiveMode = 3; 1362 bDiveMode = 3;
1363
1364 #if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
1365 pStateReal->events.gnssPositionUpdate = 1;
1366
1367 if(pStateReal->lifeData.gnssData.alive & GNSS_ALIVE_BACKUP_POS)
1368 {
1369 pStateReal->events.info_gnssPosition = pStateReal->lifeData.gnssData.coord;
1370 }
1371 else /* no pos => define dummy */
1372 {
1373 pStateReal->events.info_gnssPosition.fLon = 47.77;
1374 pStateReal->events.info_gnssPosition.fLat = 8.99;
1375 }
1376 #endif
1377
1298 } 1378 }
1299 if(bDiveMode == 3) 1379 if(bDiveMode == 3)
1300 logbook_UpdateHeader(pStateReal); 1380 logbook_UpdateHeader(pStateReal);
1301 } 1381 }
1302 } 1382 }
1787 int32_t temperatureVal = 0; 1867 int32_t temperatureVal = 0;
1788 int32_t sensor1Val = 0; 1868 int32_t sensor1Val = 0;
1789 int32_t sensor2Val = 0; 1869 int32_t sensor2Val = 0;
1790 int32_t sensor3Val = 0; 1870 int32_t sensor3Val = 0;
1791 int32_t cnsVal = 0; 1871 int32_t cnsVal = 0;
1792 SManualGas manualGasVal; 1872 SManualGas manualGasVal;
1873 int16_t decostepDepthVal = 0;
1874 uint16_t tankVal = 0;
1875 uint8_t eventdata;
1876 SGnssCoord posCoord;
1793 1877
1794 //uint16_t* ppo2, uint16_t* cns# 1878 //uint16_t* ppo2, uint16_t* cns#
1795 uint32_t bytesRead = 0; 1879 uint32_t bytesRead = 0;
1796 1880
1797 ext_flash_read_block_start(); 1881 ext_flash_read_block_start();
1807 while (true) 1891 while (true)
1808 { 1892 {
1809 1893
1810 ext_flash_set_entry_point(); 1894 ext_flash_set_entry_point();
1811 divisorBackup = divisor; 1895 divisorBackup = divisor;
1812 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); 1896 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
1897 &bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata);
1813 if(retVal == 0) 1898 if(retVal == 0)
1814 { 1899 {
1815 //Error try to read again!!! 1900 //Error try to read again!!!
1816 ext_flash_reopen_read_sample_at_entry_point(); 1901 ext_flash_reopen_read_sample_at_entry_point();
1817 divisor = divisorBackup; 1902 divisor = divisorBackup;
1818 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); 1903 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
1819 1904 &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
1820 if(retVal == 0) 1905 if(retVal == 0)
1821 { 1906 {
1822 //Error try to read again!!! 1907 //Error try to read again!!!
1823 ext_flash_reopen_read_sample_at_entry_point(); 1908 ext_flash_reopen_read_sample_at_entry_point();
1824 divisor = divisorBackup; 1909 divisor = divisorBackup;
1825 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); 1910 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
1826 1911 &bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata);
1827 if(retVal == 0) 1912 if(retVal == 0)
1828 { 1913 {
1829 ext_flash_reopen_read_sample_at_entry_point(); 1914 ext_flash_reopen_read_sample_at_entry_point();
1830 break; 1915 break;
1831 } 1916 }