Mercurial > public > ostc4
comparison Discovery/Src/logbook.c @ 1020:b0d3e8b84966 GasConsumption
Fix: Add Missing Compass Heading to the Logbook Reader.
Fix: Add Missing Scrubber State to the Logbook Reader.
| author | heinrichsweikamp |
|---|---|
| date | Fri, 20 Jun 2025 07:59:32 +0200 |
| parents | 8c0134a287da |
| children | 158100a84ebd |
comparison
equal
deleted
inserted
replaced
| 1019:67e3dbc4d212 | 1020:b0d3e8b84966 |
|---|---|
| 717 * @param int32_t* cns: output Value | 717 * @param int32_t* cns: output Value |
| 718 * @return bytes read / 0 = reading Error | 718 * @return bytes read / 0 = reading Error |
| 719 */ | 719 */ |
| 720 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2, | 720 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2, |
| 721 int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank, | 721 int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank, |
| 722 SGnssCoord* pPosition, uint8_t* event) | 722 uint16_t* compassHeading, SGnssCoord* pPosition, uint16_t* scrubberState, uint8_t* event) |
| 723 { | 723 { |
| 724 int length = 0; | 724 int length = 0; |
| 725 _Bool bEvent = 0; | 725 _Bool bEvent = 0; |
| 726 bit8_Type eventByte1, eventByte2; | 726 bit8_Type eventByte1, eventByte2; |
| 727 bit8_Type profileByteFlag; | 727 bit8_Type profileByteFlag; |
| 751 if(bailout) | 751 if(bailout) |
| 752 *bailout = -1; | 752 *bailout = -1; |
| 753 if(tank) | 753 if(tank) |
| 754 *tank = 0; | 754 *tank = 0; |
| 755 | 755 |
| 756 if (compassHeading) | |
| 757 *compassHeading = UINT16_MAX; | |
| 758 | |
| 759 if (scrubberState) | |
| 760 *scrubberState = UINT16_MAX; | |
| 761 | |
| 756 if(manualGas) | 762 if(manualGas) |
| 757 { | 763 { |
| 758 manualGas->percentageO2 =-1; | 764 manualGas->percentageO2 =-1; |
| 759 manualGas->percentageHe =-1; | 765 manualGas->percentageHe =-1; |
| 760 } | 766 } |
| 847 manualGas->percentageHe = tempU8; | 853 manualGas->percentageHe = tempU8; |
| 848 | 854 |
| 849 if(gasid) | 855 if(gasid) |
| 850 *gasid = 0; | 856 *gasid = 0; |
| 851 } | 857 } |
| 858 | |
| 859 // Compass heading | |
| 860 if (eventByte2.ub.bit1) { | |
| 861 ext_flash_read_next_sample_part((uint8_t*)compassHeading, 2); | |
| 862 bytesRead += 2; | |
| 863 length -= 2; | |
| 864 } | |
| 865 | |
| 852 /* gnss position start dive */ | 866 /* gnss position start dive */ |
| 853 if(eventByte2.ub.bit2) | 867 if(eventByte2.ub.bit2) |
| 854 { | 868 { |
| 855 tempU32 = 0; | 869 tempU32 = 0; |
| 856 for(index = 0; index < 4; index++) | 870 for(index = 0; index < 4; index++) |
| 875 if(tempU32 != 0xffffffff) | 889 if(tempU32 != 0xffffffff) |
| 876 { | 890 { |
| 877 memcpy(&pPosition->fLat, &tempU32, 4); | 891 memcpy(&pPosition->fLat, &tempU32, 4); |
| 878 } | 892 } |
| 879 } | 893 } |
| 894 | |
| 895 // Scrubber state | |
| 896 if (eventByte2.ub.bit3) { | |
| 897 ext_flash_read_next_sample_part((uint8_t*)scrubberState, 2); | |
| 898 bytesRead += 2; | |
| 899 length -= 2; | |
| 900 } | |
| 880 } | 901 } |
| 881 | 902 |
| 882 if(divisor.temperature == 0) | 903 if(divisor.temperature == 0) |
| 883 { | 904 { |
| 884 divisor.temperature = smallHeader.tempDivisor - 1; | 905 divisor.temperature = smallHeader.tempDivisor - 1; |
| 1017 * @param int32_t* cns : output array | 1038 * @param int32_t* cns : output array |
| 1018 * @return length of output | 1039 * @return length of output |
| 1019 */ | 1040 */ |
| 1020 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t* gasid, int16_t* temperature, uint16_t* ppo2, | 1041 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t* gasid, int16_t* temperature, uint16_t* ppo2, |
| 1021 uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout, | 1042 uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout, |
| 1022 uint16_t* decostopDepth, uint16_t* tank, SGnssCoord* pPosition, uint8_t* event) | 1043 uint16_t* decostopDepth, uint16_t* tank, uint16_t* compassHeading, SGnssCoord* pPosition, uint16_t* scrubberState, uint8_t* event) |
| 1023 { | 1044 { |
| 1024 //Test read | 1045 //Test read |
| 1025 //SLogbookHeader header; | 1046 //SLogbookHeader header; |
| 1026 | 1047 |
| 1027 //logbook_getHeader(&header); | 1048 //logbook_getHeader(&header); |
| 1054 int16_t decostepDepthVal = 0; | 1075 int16_t decostepDepthVal = 0; |
| 1055 int16_t decostepDepthLast = 0; | 1076 int16_t decostepDepthLast = 0; |
| 1056 uint16_t tankVal = 0; | 1077 uint16_t tankVal = 0; |
| 1057 uint32_t small_profileLength = 0; | 1078 uint32_t small_profileLength = 0; |
| 1058 uint8_t eventdata; | 1079 uint8_t eventdata; |
| 1080 uint16_t compassHeadingVal; | |
| 1081 uint16_t compassHeadingLast = UINT16_MAX; | |
| 1082 uint16_t scrubberStateVal; | |
| 1083 uint16_t scrubberStateLast = UINT16_MAX; | |
| 1059 SGnssCoord posCoord; | 1084 SGnssCoord posCoord; |
| 1060 posCoord.fLat = 0.0; | 1085 posCoord.fLat = 0.0; |
| 1061 posCoord.fLon = 0.0; | 1086 posCoord.fLon = 0.0; |
| 1062 | 1087 |
| 1063 SManualGas manualGasVal; | 1088 SManualGas manualGasVal; |
| 1137 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) | 1162 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) |
| 1138 { | 1163 { |
| 1139 ext_flash_set_entry_point(); | 1164 ext_flash_set_entry_point(); |
| 1140 divisorBackup = divisor; | 1165 divisorBackup = divisor; |
| 1141 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, | 1166 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
| 1142 &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata); | 1167 &bailoutVal, &decostepDepthVal, &tankVal, &compassHeadingVal, &posCoord, &scrubberStateVal, &eventdata); |
| 1143 | 1168 |
| 1144 if(retVal == 0) | 1169 if(retVal == 0) |
| 1145 { | 1170 { |
| 1146 //Error try to read again!!! | 1171 //Error try to read again!!! |
| 1147 ext_flash_reopen_read_sample_at_entry_point(); | 1172 ext_flash_reopen_read_sample_at_entry_point(); |
| 1148 divisor = divisorBackup; | 1173 divisor = divisorBackup; |
| 1149 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, | 1174 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, |
| 1150 &manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata); | 1175 &manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &compassHeadingVal, &posCoord, &scrubberStateVal, &eventdata); |
| 1151 | 1176 |
| 1152 if(retVal == 0) | 1177 if(retVal == 0) |
| 1153 break; | 1178 break; |
| 1154 } | 1179 } |
| 1155 bytesRead +=retVal; | 1180 bytesRead +=retVal; |
| 1211 | 1236 |
| 1212 if(decostepDepthVal == -1) | 1237 if(decostepDepthVal == -1) |
| 1213 decostepDepthVal = decostepDepthLast; | 1238 decostepDepthVal = decostepDepthLast; |
| 1214 else | 1239 else |
| 1215 decostepDepthLast = decostepDepthVal; | 1240 decostepDepthLast = decostepDepthVal; |
| 1241 | |
| 1242 if (compassHeadingVal == UINT16_MAX) | |
| 1243 compassHeadingVal = compassHeadingLast; | |
| 1244 else | |
| 1245 compassHeadingLast = compassHeadingVal; | |
| 1246 | |
| 1247 if (scrubberStateVal == UINT16_MAX) | |
| 1248 scrubberStateVal = scrubberStateLast; | |
| 1249 else | |
| 1250 scrubberStateLast = scrubberStateVal; | |
| 1216 | 1251 |
| 1217 counter++; | 1252 counter++; |
| 1218 // Heed compression | 1253 // Heed compression |
| 1219 // Write here to arrays | 1254 // Write here to arrays |
| 1220 if(counter == compression) | 1255 if(counter == compression) |
| 1275 sensor1[iNum] = (sensor1Val / 0xFFFF) & 0xFF; | 1310 sensor1[iNum] = (sensor1Val / 0xFFFF) & 0xFF; |
| 1276 if(sensor2) | 1311 if(sensor2) |
| 1277 sensor2[iNum] = (sensor2Val / 0xFFFF) & 0xFF; | 1312 sensor2[iNum] = (sensor2Val / 0xFFFF) & 0xFF; |
| 1278 if(sensor3) | 1313 if(sensor3) |
| 1279 sensor3[iNum] = (sensor3Val / 0xFFFF) & 0xFF; | 1314 sensor3[iNum] = (sensor3Val / 0xFFFF) & 0xFF; |
| 1315 | |
| 1316 if (compassHeading) | |
| 1317 compassHeading[iNum] = compassHeadingVal; | |
| 1318 | |
| 1319 if (scrubberState) | |
| 1320 scrubberState[iNum] = scrubberStateVal; | |
| 1321 | |
| 1280 iNum++; | 1322 iNum++; |
| 1281 counter = 0; | 1323 counter = 0; |
| 1282 | 1324 |
| 1283 if(event) | 1325 if(event) |
| 1284 { | 1326 { |
| 1285 event[iNum] = eventdata; | 1327 event[iNum] = eventdata; |
| 1286 eventdata = 0; | 1328 eventdata = 0; |
| 1287 } | 1329 } |
| 1288 } | 1330 } |
| 1289 } | 1331 } |
| 1332 | |
| 1290 if(pPosition) | 1333 if(pPosition) |
| 1291 { | 1334 { |
| 1292 memcpy(pPosition, &posCoord, sizeof(posCoord)); | 1335 memcpy(pPosition, &posCoord, sizeof(posCoord)); |
| 1293 } | 1336 } |
| 1294 } | 1337 } |
| 1899 int32_t cnsVal = 0; | 1942 int32_t cnsVal = 0; |
| 1900 SManualGas manualGasVal; | 1943 SManualGas manualGasVal; |
| 1901 int16_t decostepDepthVal = 0; | 1944 int16_t decostepDepthVal = 0; |
| 1902 uint16_t tankVal = 0; | 1945 uint16_t tankVal = 0; |
| 1903 uint8_t eventdata; | 1946 uint8_t eventdata; |
| 1947 uint16_t compassHeadingVal; | |
| 1904 SGnssCoord posCoord; | 1948 SGnssCoord posCoord; |
| 1949 uint16_t scrubberStateVal; | |
| 1905 | 1950 |
| 1906 //uint16_t* ppo2, uint16_t* cns# | 1951 //uint16_t* ppo2, uint16_t* cns# |
| 1907 uint32_t bytesRead = 0; | 1952 uint32_t bytesRead = 0; |
| 1908 | 1953 |
| 1909 ext_flash_read_block_start(); | 1954 ext_flash_read_block_start(); |
| 1920 { | 1965 { |
| 1921 | 1966 |
| 1922 ext_flash_set_entry_point(); | 1967 ext_flash_set_entry_point(); |
| 1923 divisorBackup = divisor; | 1968 divisorBackup = divisor; |
| 1924 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, | 1969 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
| 1925 &bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata); | 1970 &bailoutVal, &decostepDepthVal, &tankVal, &compassHeadingVal, &posCoord, &scrubberStateVal, &eventdata); |
| 1926 if(retVal == 0) | 1971 if(retVal == 0) |
| 1927 { | 1972 { |
| 1928 //Error try to read again!!! | 1973 //Error try to read again!!! |
| 1929 ext_flash_reopen_read_sample_at_entry_point(); | 1974 ext_flash_reopen_read_sample_at_entry_point(); |
| 1930 divisor = divisorBackup; | 1975 divisor = divisorBackup; |
| 1931 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, | 1976 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
| 1932 &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata); | 1977 &bailoutVal, &decostepDepthVal, &tankVal, &compassHeadingVal, &posCoord, &scrubberStateVal, &eventdata); |
| 1933 if(retVal == 0) | 1978 if(retVal == 0) |
| 1934 { | 1979 { |
| 1935 //Error try to read again!!! | 1980 //Error try to read again!!! |
| 1936 ext_flash_reopen_read_sample_at_entry_point(); | 1981 ext_flash_reopen_read_sample_at_entry_point(); |
| 1937 divisor = divisorBackup; | 1982 divisor = divisorBackup; |
| 1938 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, | 1983 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
| 1939 &bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata); | 1984 &bailoutVal, &decostepDepthVal, &tankVal, &compassHeadingVal, &posCoord, &scrubberStateVal, &eventdata); |
| 1940 if(retVal == 0) | 1985 if(retVal == 0) |
| 1941 { | 1986 { |
| 1942 ext_flash_reopen_read_sample_at_entry_point(); | 1987 ext_flash_reopen_read_sample_at_entry_point(); |
| 1943 break; | 1988 break; |
| 1944 } | 1989 } |
