comparison Discovery/Src/logbook.c @ 465:2c2df051e554 Improve_Logtansfer

Compare profile length from header and sample data to identify valid profiles In previous version sample data was used without checking if it had meanwhile been overwritten. The workarounds introduced in the last versions have now been replaced by a comparison of the profile length stored in header / sample ring. In case of an inconsistency a dummy profile is provided
author ideenmodellierer
date Tue, 14 Apr 2020 19:22:56 +0200
parents 5dd996ed8611
children 73da921869d9
comparison
equal deleted inserted replaced
464:05c5c3d10902 465:2c2df051e554
89 static SDivisor divisorBackup; 89 static SDivisor divisorBackup;
90 90
91 static SSmallHeader smallDummyHeader; 91 static SSmallHeader smallDummyHeader;
92 static uint16_t dummyWriteIdx; 92 static uint16_t dummyWriteIdx;
93 static uint16_t dummyReadIdx; 93 static uint16_t dummyReadIdx;
94 static uint8_t dummyMemoryBuffer[1000*4]; 94 static uint8_t dummyMemoryBuffer[5000];
95 95
96 96
97 /* Private function prototypes -----------------------------------------------*/ 97 /* Private function prototypes -----------------------------------------------*/
98 static void clear_divisor(void); 98 static void clear_divisor(void);
99 static void logbook_SetAverageDepth(float average_depth_meter); 99 static void logbook_SetAverageDepth(float average_depth_meter);
979 int32_t temperatureFirst = 0; 979 int32_t temperatureFirst = 0;
980 int32_t cnsLast = 0; 980 int32_t cnsLast = 0;
981 int16_t decostepDepthVal = 0; 981 int16_t decostepDepthVal = 0;
982 int16_t decostepDepthLast = 0; 982 int16_t decostepDepthLast = 0;
983 uint16_t tankVal = 0; 983 uint16_t tankVal = 0;
984 uint32_t small_profileLength = 0;
984 985
985 SManualGas manualGasVal; 986 SManualGas manualGasVal;
986 SManualGas manualGasLast; 987 SManualGas manualGasLast;
987 manualGasLast.percentageO2 = 0; 988 manualGasLast.percentageO2 = 0;
988 manualGasLast.percentageHe = 0; 989 manualGasLast.percentageHe = 0;
1038 //We start with fist gasid 1039 //We start with fist gasid
1039 gasidLast = firstgasid; 1040 gasidLast = firstgasid;
1040 1041
1041 1042
1042 //uint16_t* ppo2, uint16_t* cns# 1043 //uint16_t* ppo2, uint16_t* cns#
1043 uint32_t totalNumberOfBytes = 0; 1044 uint32_t totalNumberOfBytes = 0;
1044 uint32_t bytesRead = 0; 1045 uint32_t bytesRead = 0;
1045 ext_flash_open_read_sample( StepBackwards,&totalNumberOfBytes); 1046 ext_flash_open_read_sample( StepBackwards,&totalNumberOfBytes);
1046 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader)); 1047 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader));
1047 bytesRead += sizeof(SSmallHeader); 1048 bytesRead += sizeof(SSmallHeader);
1048 1049
1049 clear_divisor(); 1050 clear_divisor();
1050 1051
1051 iNum = 0; 1052 iNum = 0;
1052 int counter = 0; 1053 int counter = 0;
1053 temperatureLast = -1000; 1054 temperatureLast = -1000;
1054 if(totalNumberOfBytes > 2) /* read real data */ 1055
1056 small_profileLength = (smallHeader.profileLength[2] << 16) + (smallHeader.profileLength[1] << 8) + smallHeader.profileLength[0];
1057
1058 if(totalNumberOfBytes == small_profileLength) /* sizes provided by header and small header are the same => real data */
1055 { 1059 {
1056 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) 1060 while ((bytesRead < totalNumberOfBytes) && (iNum < length))
1057 { 1061 {
1058 ext_flash_set_entry_point(); 1062 ext_flash_set_entry_point();
1059 divisorBackup = divisor; 1063 divisorBackup = divisor;
1458 *********************************************************************************/ 1462 *********************************************************************************/
1459 SLogbookHeaderOSTC3 * logbook_build_ostc3header(SLogbookHeader* pHead) 1463 SLogbookHeaderOSTC3 * logbook_build_ostc3header(SLogbookHeader* pHead)
1460 { 1464 {
1461 convert_Type data,data2; 1465 convert_Type data,data2;
1462 uint16_t dummyLength = 0; 1466 uint16_t dummyLength = 0;
1463 1467 uint8_t returnEmptyHeader = 0;
1464 memcpy(headerOSTC3.diveHeaderStart, &pHead->diveHeaderStart, 2); 1468
1465 memcpy(headerOSTC3.pBeginProfileData, &pHead->pBeginProfileData, 3); 1469 uint32_t headerProfileLength, sampleProfileLength, sampleProfileStart;
1466 memcpy(headerOSTC3.pEndProfileData, &pHead->pEndProfileData, 3); 1470
1467 1471
1468 1472 if(pHead->diveHeaderStart != 0xFAFA)
1469 data.u8bit.byteHigh = 0; 1473 {
1470 data.u8bit.byteLow = pHead->pBeginProfileData[0]; 1474 returnEmptyHeader = 1;
1471 data.u8bit.byteMidLow = pHead->pBeginProfileData[1];
1472 data.u8bit.byteMidHigh = pHead->pBeginProfileData[2];
1473
1474 data2.u8bit.byteHigh = 0;
1475 data2.u8bit.byteLow = pHead->pEndProfileData[0];
1476 data2.u8bit.byteMidLow = pHead->pEndProfileData[1];
1477 data2.u8bit.byteMidHigh = pHead->pEndProfileData[2];
1478
1479 if( (pHead->pBeginProfileData[0] == 0) /* no sample data available => use dummy */
1480 &&(pHead->pBeginProfileData[1] == 0)
1481 &&(pHead->pBeginProfileData[2] == 0))
1482 {
1483 dummyLength = logbook_fillDummySampleBuffer(pHead);
1484
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 */
1487 } 1475 }
1488 else 1476 else
1489 { 1477 {
1490 /* check if sample address information are corrupted by address range. */ 1478 memcpy(headerOSTC3.diveHeaderStart, &pHead->diveHeaderStart, 2);
1491 /* TODO: Workaround. Better solution would be to check end of ring for 0xFF pattern */ 1479 memcpy(headerOSTC3.pBeginProfileData, &pHead->pBeginProfileData, 3);
1492 if((data.u32bit > data2.u32bit) && (data.u32bit < (SAMPLESTOP - 0x9000))) 1480 memcpy(headerOSTC3.pEndProfileData, &pHead->pEndProfileData, 3);
1481
1482 data.u8bit.byteHigh = 0;
1483 data.u8bit.byteLow = pHead->pBeginProfileData[0];
1484 data.u8bit.byteMidLow = pHead->pBeginProfileData[1];
1485 data.u8bit.byteMidHigh = pHead->pBeginProfileData[2];
1486
1487 sampleProfileStart = data.u32bit;
1488
1489 data2.u8bit.byteHigh = 0;
1490 data2.u8bit.byteLow = pHead->pEndProfileData[0];
1491 data2.u8bit.byteMidLow = pHead->pEndProfileData[1];
1492 data2.u8bit.byteMidHigh = pHead->pEndProfileData[2];
1493
1494 data.u8bit.byteHigh = 0;
1495 data.u8bit.byteLow = pHead->profileLength[0];
1496 data.u8bit.byteMidLow = pHead->profileLength[1];
1497 data.u8bit.byteMidHigh = pHead->profileLength[2];
1498
1499 if(data.u32bit != 0xFFFFFF) /* if the profile in use ? */
1493 { 1500 {
1494 data2.u32bit = data.u32bit + DEFAULT_SAMPLES; 1501 if(data2.u32bit < sampleProfileStart) /* Wrap around of sample ring detected */
1495 pHead->pEndProfileData[0] = data2.u8bit.byteLow; 1502 {
1496 pHead->pEndProfileData[1] = data2.u8bit.byteMidLow; 1503 if(ext_flash_SampleOverrunValid() == 0) /* Wrap around does not seem to be valid => fallback */
1497 pHead->pEndProfileData[2] = data2.u8bit.byteMidHigh; 1504 {
1498 data.u32bit = DEFAULT_SAMPLES; 1505 sampleProfileStart = 0;
1506 }
1507 }
1508 if( sampleProfileStart == 0) /* should never happen unless OSTC with older debug version is in use (or invalid overrun) */
1509 {
1510 sampleProfileLength = 1;
1511 headerProfileLength = 2;
1512 }
1513 else
1514 {
1515 headerProfileLength = (pHead->profileLength[2] << 16) + (pHead->profileLength[1] << 8) + pHead->profileLength[0];
1516 sampleProfileLength = ext_flash_read_profilelength_small_header(sampleProfileStart);
1517 }
1518
1519 if(sampleProfileLength != headerProfileLength)
1520 {
1521 dummyLength = logbook_fillDummySampleBuffer(pHead);
1522
1523 data2.u32bit = sampleProfileStart + dummyLength; /* calc new end address (which is equal to dummyLength) */
1524 data.u32bit = dummyLength; /* data is used below to represent the length */
1525 }
1526
1527 data.u32bit += 3;
1528 headerOSTC3.profileLength[0] = data.u8bit.byteLow;
1529 headerOSTC3.profileLength[1] = data.u8bit.byteMidLow;
1530 headerOSTC3.profileLength[2] = data.u8bit.byteMidHigh;
1531
1532 memcpy(headerOSTC3.gasordil, pHead->gasordil, 20);
1533
1534 if(pHead->logbookProfileVersion == LOGBOOK_VERSION)
1535 {
1536 headerOSTC3.logbookProfileVersion = LOGBOOK_VERSION_OSTC3;
1537 memcpy(headerOSTC3.personalDiveCount, &pHead->personalDiveCount, 2);
1538 headerOSTC3.safetyDistance_10cm = 0;
1539
1540 for(int i=0;i<5;i++)
1541 {
1542 if(!pHead->gasordil[i].note.ub.active)
1543 headerOSTC3.gasordil[3 + (i*4)] = 0;
1544 else if(pHead->gasordil[i].note.ub.first)
1545 {
1546 /* depth = 0, note = 1 */
1547 headerOSTC3.gasordil[2 + (i*4)] = 0;
1548 headerOSTC3.gasordil[3 + (i*4)] = 1;
1549 }
1550 else if( pHead->gasordil[i].depth_meter)
1551 {
1552 /* note = 3 */
1553 headerOSTC3.gasordil[3 + (i*4)] = 3;
1554 }
1555 }
1556 }
1557 else
1558 {
1559 headerOSTC3.logbookProfileVersion = 0xFF;
1560 headerOSTC3.personalDiveCount[0] = 0xFF;
1561 headerOSTC3.personalDiveCount[1] = 0xFF;
1562 headerOSTC3.safetyDistance_10cm = 0xFF;
1563 }
1564
1565 headerOSTC3.dateYear = pHead->dateYear;
1566 headerOSTC3.dateMonth = pHead->dateMonth;
1567 headerOSTC3.dateDay = pHead->dateDay;
1568 headerOSTC3.timeHour = pHead->timeHour;
1569 headerOSTC3.timeMinute = pHead->timeMinute;
1570
1571 memcpy(headerOSTC3.maxDepth, &pHead->maxDepth, 2);
1572 memcpy(headerOSTC3.diveTimeMinutes, &pHead->diveTimeMinutes, 2);
1573
1574 headerOSTC3.diveTimeSeconds = pHead->diveTimeSeconds;
1575
1576 memcpy(headerOSTC3.minTemp, &pHead->minTemp, 2);
1577 memcpy(headerOSTC3.surfacePressure_mbar,&pHead->surfacePressure_mbar, 2);
1578 memcpy(headerOSTC3.desaturationTime, &pHead->desaturationTime, 2);
1579
1580 headerOSTC3.firmwareVersionHigh = pHead->firmwareVersionHigh;
1581 headerOSTC3.firmwareVersionLow = pHead->firmwareVersionLow;
1582
1583 memcpy(headerOSTC3.batteryVoltage, &pHead->batteryVoltage, 2);
1584
1585 headerOSTC3.samplingRate = pHead->samplingRate;
1586
1587 memcpy(headerOSTC3.cnsAtBeginning, &pHead->cnsAtBeginning, 2);
1588
1589 headerOSTC3.gfAtBeginning = pHead->gfAtBeginning;
1590 headerOSTC3.gfAtEnd = pHead->gfAtEnd;
1591
1592 memcpy(headerOSTC3.setpoint, pHead->setpoint, 10);
1593
1594 headerOSTC3.salinity = pHead->salinity;
1595
1596 memcpy(headerOSTC3.maxCNS, &pHead->maxCNS, 2);
1597 memcpy(headerOSTC3.averageDepth_mbar, &pHead->averageDepth_mbar, 2);
1598 memcpy(headerOSTC3.total_diveTime_seconds, &pHead->total_diveTime_seconds, 2);
1599
1600 headerOSTC3.gfLow_or_Vpm_conservatism = pHead->gfLow_or_Vpm_conservatism;
1601 headerOSTC3.gfHigh = pHead->gfHigh;
1602 headerOSTC3.decoModel = pHead->decoModel;
1603
1604 memcpy(headerOSTC3.diveNumber, &pHead->diveNumber, 2);
1605
1606 headerOSTC3.diveMode = pHead->diveMode;
1607 headerOSTC3.CCRmode = pHead->CCRmode;
1608
1609 memcpy(headerOSTC3.n2CompartDesatTime_min,pHead->n2CompartDesatTime_min, 16);
1610 memcpy(headerOSTC3.n2Compartments, pHead->n2Compartments, 64);
1611 memcpy(headerOSTC3.heCompartDesatTime_min,pHead->heCompartDesatTime_min, 16);
1612 memcpy(headerOSTC3.heCompartments, pHead->heCompartments, 64);
1613
1614 headerOSTC3.lastDecostop_m = pHead->lastDecostop_m;
1615
1616 memcpy(headerOSTC3.hwHudBattery_mV, &pHead->hwHudBattery_mV, 2);
1617
1618 headerOSTC3.hwHudLastStatus = pHead->hwHudLastStatus;
1619
1620 memcpy(headerOSTC3.batteryGaugeRegisters,&pHead->batteryGaugeRegisters, 6);
1621
1622
1623 memcpy(headerOSTC3.diveHeaderEnd, &pHead->diveHeaderEnd, 2);
1499 } 1624 }
1500 else 1625 else
1501 { 1626 {
1502 data.u8bit.byteHigh = 0; 1627 returnEmptyHeader = 1;
1503 data.u8bit.byteLow = pHead->profileLength[0];
1504 data.u8bit.byteMidLow = pHead->profileLength[1];
1505 data.u8bit.byteMidHigh = pHead->profileLength[2];
1506 } 1628 }
1507 } 1629 }
1508 if(data.u32bit != 0xFFFFFF) 1630 if(returnEmptyHeader) /* profile not in use => return array full of 0xFF */
1509 data.u32bit += 3; 1631 {
1510 1632 memset(&headerOSTC3, 0xFF, sizeof(headerOSTC3));
1511 headerOSTC3.profileLength[0] = data.u8bit.byteLow; 1633 }
1512 headerOSTC3.profileLength[1] = data.u8bit.byteMidLow;
1513 headerOSTC3.profileLength[2] = data.u8bit.byteMidHigh;
1514
1515 memcpy(headerOSTC3.gasordil, pHead->gasordil, 20);
1516
1517 if(pHead->logbookProfileVersion == LOGBOOK_VERSION)
1518 {
1519 headerOSTC3.logbookProfileVersion = LOGBOOK_VERSION_OSTC3;
1520 memcpy(headerOSTC3.personalDiveCount, &pHead->personalDiveCount, 2);
1521 headerOSTC3.safetyDistance_10cm = 0;
1522
1523 for(int i=0;i<5;i++)
1524 {
1525 if(!pHead->gasordil[i].note.ub.active)
1526 headerOSTC3.gasordil[3 + (i*4)] = 0;
1527 else if(pHead->gasordil[i].note.ub.first)
1528 {
1529 /* depth = 0, note = 1 */
1530 headerOSTC3.gasordil[2 + (i*4)] = 0;
1531 headerOSTC3.gasordil[3 + (i*4)] = 1;
1532 }
1533 else if( pHead->gasordil[i].depth_meter)
1534 {
1535 /* note = 3 */
1536 headerOSTC3.gasordil[3 + (i*4)] = 3;
1537 }
1538 }
1539 }
1540 else
1541 {
1542 headerOSTC3.logbookProfileVersion = 0xFF;
1543 headerOSTC3.personalDiveCount[0] = 0xFF;
1544 headerOSTC3.personalDiveCount[1] = 0xFF;
1545 headerOSTC3.safetyDistance_10cm = 0xFF;
1546 }
1547
1548 headerOSTC3.dateYear = pHead->dateYear;
1549 headerOSTC3.dateMonth = pHead->dateMonth;
1550 headerOSTC3.dateDay = pHead->dateDay;
1551 headerOSTC3.timeHour = pHead->timeHour;
1552 headerOSTC3.timeMinute = pHead->timeMinute;
1553
1554
1555 memcpy(headerOSTC3.maxDepth, &pHead->maxDepth, 2);
1556 memcpy(headerOSTC3.diveTimeMinutes, &pHead->diveTimeMinutes, 2);
1557
1558 headerOSTC3.diveTimeSeconds = pHead->diveTimeSeconds;
1559
1560 memcpy(headerOSTC3.minTemp, &pHead->minTemp, 2);
1561 memcpy(headerOSTC3.surfacePressure_mbar,&pHead->surfacePressure_mbar, 2);
1562 memcpy(headerOSTC3.desaturationTime, &pHead->desaturationTime, 2);
1563
1564 headerOSTC3.firmwareVersionHigh = pHead->firmwareVersionHigh;
1565 headerOSTC3.firmwareVersionLow = pHead->firmwareVersionLow;
1566
1567 memcpy(headerOSTC3.batteryVoltage, &pHead->batteryVoltage, 2);
1568
1569 headerOSTC3.samplingRate = pHead->samplingRate;
1570
1571 memcpy(headerOSTC3.cnsAtBeginning, &pHead->cnsAtBeginning, 2);
1572
1573 headerOSTC3.gfAtBeginning = pHead->gfAtBeginning;
1574 headerOSTC3.gfAtEnd = pHead->gfAtEnd;
1575
1576 memcpy(headerOSTC3.setpoint, pHead->setpoint, 10);
1577
1578 headerOSTC3.salinity = pHead->salinity;
1579
1580 memcpy(headerOSTC3.maxCNS, &pHead->maxCNS, 2);
1581 memcpy(headerOSTC3.averageDepth_mbar, &pHead->averageDepth_mbar, 2);
1582 memcpy(headerOSTC3.total_diveTime_seconds,&pHead->total_diveTime_seconds, 2);
1583
1584 headerOSTC3.gfLow_or_Vpm_conservatism = pHead->gfLow_or_Vpm_conservatism;
1585 headerOSTC3.gfHigh = pHead->gfHigh;
1586 headerOSTC3.decoModel = pHead->decoModel;
1587
1588 memcpy(headerOSTC3.diveNumber, &pHead->diveNumber, 2);
1589
1590 headerOSTC3.diveMode = pHead->diveMode;
1591 headerOSTC3.CCRmode = pHead->CCRmode;
1592
1593 memcpy(headerOSTC3.n2CompartDesatTime_min,pHead->n2CompartDesatTime_min, 16);
1594 memcpy(headerOSTC3.n2Compartments, pHead->n2Compartments, 64);
1595 memcpy(headerOSTC3.heCompartDesatTime_min,pHead->heCompartDesatTime_min, 16);
1596 memcpy(headerOSTC3.heCompartments, pHead->heCompartments, 64);
1597
1598 headerOSTC3.lastDecostop_m = pHead->lastDecostop_m;
1599
1600 memcpy(headerOSTC3.hwHudBattery_mV, &pHead->hwHudBattery_mV, 2);
1601
1602 headerOSTC3.hwHudLastStatus = pHead->hwHudLastStatus;
1603
1604 memcpy(headerOSTC3.batteryGaugeRegisters,&pHead->batteryGaugeRegisters, 6);
1605
1606
1607 memcpy(headerOSTC3.diveHeaderEnd, &pHead->diveHeaderEnd, 2);
1608 1634
1609 return &headerOSTC3; 1635 return &headerOSTC3;
1610 } 1636 }
1611 1637
1612 1638
1616 * @version V0.0.1 1642 * @version V0.0.1
1617 * @date 31-Juli-2015 1643 * @date 31-Juli-2015
1618 *********************************************************************************/ 1644 *********************************************************************************/
1619 SLogbookHeaderOSTC3compact * logbook_build_ostc3header_compact(SLogbookHeader* pHead) 1645 SLogbookHeaderOSTC3compact * logbook_build_ostc3header_compact(SLogbookHeader* pHead)
1620 { 1646 {
1647 uint8_t returnEmptyHeader = 0;
1621 convert_Type data, data2; 1648 convert_Type data, data2;
1622 uint32_t dummyLength = 0; 1649 uint32_t dummyLength = 0;
1623 1650 uint32_t headerProfileLength, sampleProfileLength, sampleProfileStart;
1624 1651
1625 data.u8bit.byteHigh = 0; 1652 if(pHead->diveHeaderStart != 0xFAFA)
1626 data.u8bit.byteLow = pHead->pBeginProfileData[0]; 1653 {
1627 data.u8bit.byteMidLow = pHead->pBeginProfileData[1]; 1654 returnEmptyHeader = 1;
1628 data.u8bit.byteMidHigh = pHead->pBeginProfileData[2];
1629
1630 data2.u8bit.byteHigh = 0;
1631 data2.u8bit.byteLow = pHead->pEndProfileData[0];
1632 data2.u8bit.byteMidLow = pHead->pEndProfileData[1];
1633 data2.u8bit.byteMidHigh = pHead->pEndProfileData[2];
1634
1635 if( (pHead->pBeginProfileData[0] == 0) /* no sample data available => use dummy */
1636 &&(pHead->pBeginProfileData[1] == 0)
1637 &&(pHead->pBeginProfileData[2] == 0))
1638 {
1639 dummyLength = logbook_fillDummySampleBuffer(pHead);
1640
1641 data2.u32bit = data.u32bit + dummyLength; /* calc new end address (which is equal to dummyLength) */
1642 data.u32bit = data2.u32bit; /* data is used below to represent the length */
1643 } 1655 }
1644 else 1656 else
1645 { 1657 {
1646 /* check if sample address information are corrupted by address range. */ 1658 data.u8bit.byteHigh = 0;
1647 /* TODO: Workaround. Better solution would be to check end of ring for 0xFF pattern */ 1659 data.u8bit.byteLow = pHead->pBeginProfileData[0];
1648 if((data.u32bit > data2.u32bit) && (data.u32bit < (SAMPLESTOP - 0x9000))) 1660 data.u8bit.byteMidLow = pHead->pBeginProfileData[1];
1661 data.u8bit.byteMidHigh = pHead->pBeginProfileData[2];
1662
1663 sampleProfileStart = data.u32bit;
1664
1665 data2.u8bit.byteHigh = 0;
1666 data2.u8bit.byteLow = pHead->pEndProfileData[0];
1667 data2.u8bit.byteMidLow = pHead->pEndProfileData[1];
1668 data2.u8bit.byteMidHigh = pHead->pEndProfileData[2];
1669
1670 data.u8bit.byteHigh = 0;
1671 data.u8bit.byteLow = pHead->profileLength[0];
1672 data.u8bit.byteMidLow = pHead->profileLength[1];
1673 data.u8bit.byteMidHigh = pHead->profileLength[2];
1674
1675 if(data.u32bit != 0xFFFFFF)
1649 { 1676 {
1650 data2.u32bit = data.u32bit + DEFAULT_SAMPLES; 1677 if(data2.u32bit < sampleProfileStart) /* Wrap around of sample ring detected */
1651 pHead->pEndProfileData[0] = data2.u8bit.byteLow; 1678 {
1652 pHead->pEndProfileData[1] = data2.u8bit.byteMidLow; 1679 if(ext_flash_SampleOverrunValid() == 0) /* Wrap around does not seem to be valid => fallback */
1653 pHead->pEndProfileData[2] = data2.u8bit.byteMidHigh; 1680 {
1654 data.u32bit = DEFAULT_SAMPLES; 1681 sampleProfileStart = 0;
1682 }
1683 }
1684
1685 if( sampleProfileStart == 0) /* no sample data available => use dummy */
1686 {
1687 sampleProfileLength = 1;
1688 headerProfileLength = 2;
1689 }
1690 else
1691 {
1692 headerProfileLength = (pHead->profileLength[2] << 16) + (pHead->profileLength[1] << 8) + pHead->profileLength[0];
1693 sampleProfileLength = ext_flash_read_profilelength_small_header(sampleProfileStart);
1694 }
1695 if(sampleProfileLength != headerProfileLength)
1696 {
1697 dummyLength = logbook_fillDummySampleBuffer(pHead);
1698
1699 data2.u32bit = sampleProfileStart + dummyLength; /* calc new end address (which is equal to dummyLength) */
1700 data.u32bit = dummyLength; /* data is used below to represent the length */
1701 }
1702 data.u32bit += 3;
1703 headerOSTC3compact.profileLength[0] = data.u8bit.byteLow;
1704 headerOSTC3compact.profileLength[1] = data.u8bit.byteMidLow;
1705 headerOSTC3compact.profileLength[2] = data.u8bit.byteMidHigh;
1706
1707 headerOSTC3compact.dateYear = pHead->dateYear;
1708 headerOSTC3compact.dateMonth = pHead->dateMonth;
1709 headerOSTC3compact.dateDay = pHead->dateDay;
1710 headerOSTC3compact.timeHour = pHead->timeHour;
1711 headerOSTC3compact.timeMinute = pHead->timeMinute;
1712
1713 memcpy(headerOSTC3compact.maxDepth, &pHead->maxDepth, 2);
1714 memcpy(headerOSTC3compact.diveTimeMinutes, &pHead->diveTimeMinutes, 2);
1715
1716 headerOSTC3compact.diveTimeSeconds = pHead->diveTimeSeconds;
1717 headerOSTC3compact.totalDiveNumberLow = pHead->diveNumber & 0xFF;
1718 headerOSTC3compact.totalDiveNumberHigh = (uint8_t)(pHead->diveNumber/256);
1719 headerOSTC3compact.profileVersion = 0x24; // Logbook-Profile version, 0x24 = date and time is start not end
1655 } 1720 }
1656 else 1721 else
1657 { 1722 {
1658 data.u8bit.byteHigh = 0; 1723 returnEmptyHeader = 1;
1659 data.u8bit.byteLow = pHead->profileLength[0];
1660 data.u8bit.byteMidLow = pHead->profileLength[1];
1661 data.u8bit.byteMidHigh = pHead->profileLength[2];
1662 } 1724 }
1663 } 1725 }
1664 if(data.u32bit != 0xFFFFFF) 1726 if(returnEmptyHeader)
1665 {
1666 data.u32bit += 3;
1667
1668 headerOSTC3compact.profileLength[0] = data.u8bit.byteLow;
1669 headerOSTC3compact.profileLength[1] = data.u8bit.byteMidLow;
1670 headerOSTC3compact.profileLength[2] = data.u8bit.byteMidHigh;
1671
1672 headerOSTC3compact.dateYear = pHead->dateYear;
1673 headerOSTC3compact.dateMonth = pHead->dateMonth;
1674 headerOSTC3compact.dateDay = pHead->dateDay;
1675 headerOSTC3compact.timeHour = pHead->timeHour;
1676 headerOSTC3compact.timeMinute = pHead->timeMinute;
1677
1678 memcpy(headerOSTC3compact.maxDepth, &pHead->maxDepth, 2);
1679 memcpy(headerOSTC3compact.diveTimeMinutes, &pHead->diveTimeMinutes, 2);
1680
1681 headerOSTC3compact.diveTimeSeconds = pHead->diveTimeSeconds;
1682
1683
1684 headerOSTC3compact.totalDiveNumberLow = pHead->diveNumber & 0xFF;
1685 headerOSTC3compact.totalDiveNumberHigh = (uint8_t)(pHead->diveNumber/256);
1686 headerOSTC3compact.profileVersion = 0x24; // Logbook-Profile version, 0x24 = date and time is start not end
1687 }
1688 else
1689 { 1727 {
1690 memset(&headerOSTC3compact, 0xFF, sizeof(SLogbookHeaderOSTC3compact)); 1728 memset(&headerOSTC3compact, 0xFF, sizeof(SLogbookHeaderOSTC3compact));
1691 } 1729 }
1692 return &headerOSTC3compact; 1730 return &headerOSTC3compact;
1693 } 1731 }
1908 else 1946 else
1909 { 1947 {
1910 divisor.temperature--; 1948 divisor.temperature--;
1911 } 1949 }
1912 1950
1913 logbook_writeDummy((void *) &smallDummyHeader,sizeof(smallDummyHeader)); 1951 logbook_writeDummy((void *) sample,length);
1914 } 1952 }
1915 1953
1916 1954
1917 uint16_t logbook_fillDummySampleBuffer(SLogbookHeader* pHeader) 1955 uint16_t logbook_fillDummySampleBuffer(SLogbookHeader* pHeader)
1918 { 1956 {