comparison Discovery/Src/logbook.c @ 458:5dd996ed8611 minor_improvments

Added ppO2 to dummy profile data: PPO2 calculation based on the first gas has been added to the dummy profile to enable drawing of the graph at log page four As this increased the number of parameters to be passed to the sub functions, the complete dive header is passed as reference instead of single members to increase the code maintanability
author ideenmodellierer
date Sat, 28 Mar 2020 21:41:47 +0100
parents 4bd01f48c285
children 2c2df051e554
comparison
equal deleted inserted replaced
457:4bd01f48c285 458:5dd996ed8611
101 static void logbook_SetMaxCNS(float max_cns_percentage); 101 static void logbook_SetMaxCNS(float max_cns_percentage);
102 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal); 102 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal);
103 static void logbook_SetLastStop(float last_stop_depth_bar); 103 static void logbook_SetLastStop(float last_stop_depth_bar);
104 static void logbook_writedata(void * data, int length_byte); 104 static void logbook_writedata(void * data, int length_byte);
105 static void logbook_UpdateHeader(const SDiveState * pStateReal); 105 static void logbook_UpdateHeader(const SDiveState * pStateReal);
106 static void logbook_createDummyProfile(uint16_t maxDepth, uint8_t lastDecostop_m, int16_t minTemp, uint16_t length, uint16_t* depth, int16_t* temperature); 106 static void logbook_createDummyProfile(SLogbookHeader* pHeader, uint16_t length, uint16_t* depth, int16_t* temperature, uint16_t* ppo2);
107 107
108 /* Exported functions --------------------------------------------------------*/ 108 /* Exported functions --------------------------------------------------------*/
109 109
110 void logbook_EndDive(void) 110 void logbook_EndDive(void)
111 { 111 {
526 { 526 {
527 sample[length] = 0; 527 sample[length] = 0;
528 length += 1; 528 length += 1;
529 sample[length] = 0; 529 sample[length] = 0;
530 length += 1; 530 length += 1;
531 pDecoinfo = &stateUsed->decolistBuehlmann; /* use GF per default if something went wrong */
531 } 532 }
532 533
533 if(pDecoinfo->output_ndl_seconds > 0) 534 if(pDecoinfo->output_ndl_seconds > 0)
534 { 535 {
535 sample[length] = 0; 536 sample[length] = 0;
950 //Test read 951 //Test read
951 //SLogbookHeader header; 952 //SLogbookHeader header;
952 953
953 //logbook_getHeader(&header); 954 //logbook_getHeader(&header);
954 SLogbookHeader header; 955 SLogbookHeader header;
955 int iNum; 956 int16_t iNum;
956 int firstgasid = 0; 957 int16_t firstgasid = 0;
957 int retVal = 0; 958 uint16_t retVal = 0;
958 int compression = 0; 959 int16_t compression = 0;
959 int i; 960 int16_t i;
960 // uint32_t diveTime_seconds; 961 // uint32_t diveTime_seconds;
961 int32_t depthVal = 0; 962 int32_t depthVal = 0;
962 int16_t gasidVal = 0; 963 int16_t gasidVal = 0;
963 int16_t setPointVal = 0; 964 int16_t setPointVal = 0;
964 int16_t bailoutVal = 0; 965 int16_t bailoutVal = 0;
1188 } 1189 }
1189 } 1190 }
1190 } 1191 }
1191 else 1192 else
1192 { 1193 {
1193 logbook_createDummyProfile(header.maxDepth, header.lastDecostop_m, header.minTemp, numSamples, depth, temperature); 1194 logbook_createDummyProfile(&header, numSamples, depth, temperature, ppo2);
1194 iNum = numSamples; 1195 iNum = numSamples;
1195 } 1196 }
1196 1197
1197 // Fix first Temperature Entries 150930 hw 1198 // Fix first Temperature Entries 150930 hw
1198 if(temperature) 1199 if(temperature)
1477 1478
1478 if( (pHead->pBeginProfileData[0] == 0) /* no sample data available => use dummy */ 1479 if( (pHead->pBeginProfileData[0] == 0) /* no sample data available => use dummy */
1479 &&(pHead->pBeginProfileData[1] == 0) 1480 &&(pHead->pBeginProfileData[1] == 0)
1480 &&(pHead->pBeginProfileData[2] == 0)) 1481 &&(pHead->pBeginProfileData[2] == 0))
1481 { 1482 {
1482 dummyLength = logbook_fillDummySampleBuffer(pHead->diveTimeMinutes, pHead->diveTimeSeconds,pHead->maxDepth 1483 dummyLength = logbook_fillDummySampleBuffer(pHead);
1483 ,pHead->lastDecostop_m, pHead->minTemp);
1484 1484
1485 data2.u32bit = data.u32bit + dummyLength; /* calc new end address (which is equal to dummyLength) */ 1485 data2.u32bit = data.u32bit + dummyLength; /* calc new end address (which is equal to dummyLength) */
1486 data.u32bit = data2.u32bit; /* data is used below to represent the length */ 1486 data.u32bit = data2.u32bit; /* data is used below to represent the length */
1487 } 1487 }
1488 else 1488 else
1634 1634
1635 if( (pHead->pBeginProfileData[0] == 0) /* no sample data available => use dummy */ 1635 if( (pHead->pBeginProfileData[0] == 0) /* no sample data available => use dummy */
1636 &&(pHead->pBeginProfileData[1] == 0) 1636 &&(pHead->pBeginProfileData[1] == 0)
1637 &&(pHead->pBeginProfileData[2] == 0)) 1637 &&(pHead->pBeginProfileData[2] == 0))
1638 { 1638 {
1639 dummyLength = logbook_fillDummySampleBuffer(pHead->diveTimeMinutes, pHead->diveTimeSeconds,pHead->maxDepth 1639 dummyLength = logbook_fillDummySampleBuffer(pHead);
1640 ,pHead->lastDecostop_m, pHead->minTemp);
1641 1640
1642 data2.u32bit = data.u32bit + dummyLength; /* calc new end address (which is equal to dummyLength) */ 1641 data2.u32bit = data.u32bit + dummyLength; /* calc new end address (which is equal to dummyLength) */
1643 data.u32bit = data2.u32bit; /* data is used below to represent the length */ 1642 data.u32bit = data2.u32bit; /* data is used below to represent the length */
1644 } 1643 }
1645 else 1644 else
1785 SSettings * settings = settingsGetPointer(); 1784 SSettings * settings = settingsGetPointer();
1786 settings->lastDiveLogId = headerId; 1785 settings->lastDiveLogId = headerId;
1787 ext_flash_close_new_dive_log((uint8_t *)&header); 1786 ext_flash_close_new_dive_log((uint8_t *)&header);
1788 } 1787 }
1789 1788
1790 void logbook_createDummyProfile(uint16_t maxDepth, uint8_t lastDecostop_m, int16_t minTemp, uint16_t length, uint16_t* depth, int16_t* temperature) 1789 void logbook_createDummyProfile(SLogbookHeader* pHeader, uint16_t length, uint16_t* depth, int16_t* temperature, uint16_t* ppo2)
1791 { 1790 {
1792 uint8_t drawDeco = 1; 1791 uint8_t drawDeco = 1;
1793 uint16_t index = 0; 1792 uint16_t index = 0;
1794 uint16_t indexDescenStop = 0; 1793 uint16_t indexDescenStop = 0;
1795 uint16_t indexAscendStart = 0; 1794 uint16_t indexAscendStart = 0;
1796 uint16_t simDecentDepth = 0; 1795 uint16_t simDecentDepth = 0;
1797 uint16_t simDecentStep = 0; 1796 uint16_t simDecentStep = 0;
1798 uint16_t simAcentDepth = 0; 1797 uint16_t simAcentDepth = 0;
1799 uint16_t simAcentStep = 0; 1798 uint16_t simAcentStep = 0;
1800 1799 float ambiant_pressure_bar = 0;
1801 simDecentStep = maxDepth / (length / 6); /* first 1/6 for descend */ 1800
1802 simAcentStep = maxDepth / (length / 3); /* first 1/3 for ascend */ 1801 simDecentStep = pHeader->maxDepth / (length / 6); /* first 1/6 for descend */
1803 1802 simAcentStep = pHeader->maxDepth / (length / 3); /* first 1/3 for ascend */
1804 while((index < length) && (simDecentDepth < maxDepth)) /* draw decent */ 1803
1804 SGas gas;
1805
1806
1807 if(ppo2)
1808 {
1809 /* find first gas ID */
1810 for(index = 0; index < NUM_GAS; index++)
1811 {
1812 if(pHeader->gasordil[index].note.ub.first)
1813 break;
1814 }
1815 if(index != NUM_GAS)
1816 {
1817 gas.helium_percentage = pHeader->gasordil[index].helium_percentage;
1818 gas.nitrogen_percentage = 100 - gas.helium_percentage - pHeader->gasordil[index].oxygen_percentage;
1819 }
1820 }
1821
1822 while((index < length) && (simDecentDepth < pHeader->maxDepth)) /* draw decent */
1805 { 1823 {
1806 depth[index] = simDecentDepth; 1824 depth[index] = simDecentDepth;
1807 temperature[index] = minTemp; 1825 temperature[index] = pHeader->minTemp;
1826 if(ppo2)
1827 {
1828 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
1829 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
1830 }
1808 index++; 1831 index++;
1809 simDecentDepth += simDecentStep; 1832 simDecentDepth += simDecentStep;
1810 } 1833 }
1811 indexDescenStop = index; 1834 indexDescenStop = index;
1812 index = length -1; 1835 index = length -1;
1813 while((index > indexDescenStop) && (simAcentDepth < maxDepth)) /* draw ascend including max deco stop */ 1836 while((index > indexDescenStop) && (simAcentDepth < pHeader->maxDepth)) /* draw ascend including max deco stop */
1814 { 1837 {
1815 depth[index] = simAcentDepth; 1838 depth[index] = simAcentDepth;
1816 temperature[index] = minTemp; 1839 temperature[index] = pHeader->minTemp;
1817 if((drawDeco) && (simAcentDepth < lastDecostop_m)) /* draw deco step */ 1840 if(ppo2)
1841 {
1842 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
1843 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
1844 }
1845 if((drawDeco) && (simAcentDepth < pHeader->lastDecostop_m)) /* draw deco step */
1818 { 1846 {
1819 drawDeco = length / 10; 1847 drawDeco = length / 10;
1820 while (drawDeco) 1848 while(drawDeco)
1821 { 1849 {
1822 index--; 1850 index--;
1823 depth[index] = simAcentDepth; 1851 depth[index] = simAcentDepth;
1824 temperature[index] = minTemp; 1852 temperature[index] = pHeader->minTemp;
1853 if(ppo2)
1854 {
1855 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
1856 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
1857 }
1858 drawDeco--;
1825 } 1859 }
1826 } 1860 }
1827 index--; 1861 index--;
1828 simAcentDepth += simAcentStep; 1862 simAcentDepth += simAcentStep;
1829 } 1863 }
1830 indexAscendStart = index; 1864 indexAscendStart = index;
1831 index = indexDescenStop; 1865 index = indexDescenStop;
1832 while(index <= indexAscendStart) /* draw isobar dive phase */ 1866 while(index <= indexAscendStart) /* draw isobar dive phase */
1833 { 1867 {
1834 depth[index] = maxDepth; 1868 depth[index] = pHeader->maxDepth;
1835 temperature[index] = minTemp; 1869 temperature[index] = pHeader->minTemp;
1870 if(ppo2)
1871 {
1872 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
1873 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
1874 }
1836 index++; 1875 index++;
1837 } 1876 }
1838 } 1877 }
1839 1878
1840 void logbook_resetDummy() 1879 void logbook_resetDummy()
1873 1912
1874 logbook_writeDummy((void *) &smallDummyHeader,sizeof(smallDummyHeader)); 1913 logbook_writeDummy((void *) &smallDummyHeader,sizeof(smallDummyHeader));
1875 } 1914 }
1876 1915
1877 1916
1878 uint16_t logbook_fillDummySampleBuffer(uint16_t diveMinutes, uint8_t diveSeconds, uint16_t maxDepth, uint8_t lastDecostop_m, int16_t minTemp) 1917 uint16_t logbook_fillDummySampleBuffer(SLogbookHeader* pHeader)
1879 { 1918 {
1880 uint16_t depthArray[DUMMY_SAMPLES]; 1919 uint16_t depthArray[DUMMY_SAMPLES];
1881 int16_t temperatureArray[DUMMY_SAMPLES]; 1920 int16_t temperatureArray[DUMMY_SAMPLES];
1921 uint16_t ppo2Array[DUMMY_SAMPLES];
1882 1922
1883 uint16_t index = 0; 1923 uint16_t index = 0;
1884 uint16_t dummyBufferSize = 0; 1924 uint16_t dummyBufferSize = 0;
1885 uint16_t dummyProfileLength = 0; 1925 uint16_t dummyProfileLength = 0;
1886 uint32_t overallSecond = diveMinutes * 60 + diveSeconds; 1926 uint32_t overallSecond = pHeader->diveTimeMinutes * 60 + pHeader->diveTimeSeconds;
1887 1927
1888 logbook_resetDummy(); 1928 logbook_resetDummy();
1889 clear_divisor(); 1929 clear_divisor();
1890 1930
1891 smallDummyHeader.profileLength[0] = 0xFF; 1931 smallDummyHeader.profileLength[0] = 0xFF;
1934 else 1974 else
1935 { 1975 {
1936 dummyProfileLength = overallSecond / smallDummyHeader.samplingRate_seconds; 1976 dummyProfileLength = overallSecond / smallDummyHeader.samplingRate_seconds;
1937 } 1977 }
1938 logbook_writeDummy((void *) &smallDummyHeader,sizeof(smallDummyHeader)); 1978 logbook_writeDummy((void *) &smallDummyHeader,sizeof(smallDummyHeader));
1939 logbook_createDummyProfile(maxDepth, lastDecostop_m, minTemp, dummyProfileLength, depthArray, temperatureArray); 1979 logbook_createDummyProfile(pHeader,dummyProfileLength, depthArray, temperatureArray, ppo2Array );
1940 1980
1941 for (index = 0; index < dummyProfileLength; index++) 1981 for (index = 0; index < dummyProfileLength; index++)
1942 { 1982 {
1943 logbook_writeDummySample(depthArray[index], temperatureArray[index]); 1983 logbook_writeDummySample(depthArray[index], temperatureArray[index]);
1944 } 1984 }