Mercurial > public > ostc4
comparison Discovery/Src/data_exchange_main.c @ 406:439874690f85 Improment_NVM
Bugfix Min max values for device data checks:
Devicedata was set to it lower limit in case of a lower invalid value and upper limit in case a bigger value was detected. This could cause the history memory to be set to a min / max limit and never beeing updated again => Implemented a selection to specify which limit shall be used as default.
Minor change: "header" was used as global as well as as local variable => changed name for global variant to gheader.
Operation hours were not updated =>adde check for opeartion hours
author | ideenmodellierer |
---|---|
date | Sun, 12 Jan 2020 17:57:11 +0100 |
parents | ea3fda8eb93e |
children | b11e50415982 |
comparison
equal
deleted
inserted
replaced
405:73db1565220b | 406:439874690f85 |
---|---|
88 | 88 |
89 static uint8_t data_old__lost_connection_to_slave_counter_temp = 0; | 89 static uint8_t data_old__lost_connection_to_slave_counter_temp = 0; |
90 static uint8_t data_old__lost_connection_to_slave_counter_retry = 0; | 90 static uint8_t data_old__lost_connection_to_slave_counter_retry = 0; |
91 static uint32_t data_old__lost_connection_to_slave_counter_total = 0; | 91 static uint32_t data_old__lost_connection_to_slave_counter_total = 0; |
92 | 92 |
93 static uint8_t DeviceDataUpdated = 0; | |
94 | |
93 /* Private types -------------------------------------------------------------*/ | 95 /* Private types -------------------------------------------------------------*/ |
96 #define UNKNOWN_TIME_HOURS 1 | |
97 #define UNKNOWN_TIME_MINUTES 0 | |
98 #define UNKNOWN_TIME_SECOND 0 | |
99 #define UNKNOWN_DATE_DAY 1 | |
100 #define UNKNOWN_DATE_MONTH 1 | |
101 #define UNKNOWN_DATE_YEAR 16 | |
94 | 102 |
95 /* Private function prototypes -----------------------------------------------*/ | 103 /* Private function prototypes -----------------------------------------------*/ |
96 static uint8_t DataEX_check_header_and_footer_ok(void); | 104 static uint8_t DataEX_check_header_and_footer_ok(void); |
97 static uint8_t DataEX_check_header_and_footer_shifted(void); | 105 static uint8_t DataEX_check_header_and_footer_shifted(void); |
98 static uint8_t DataEX_check_header_and_footer_devicedata(void); | 106 static uint8_t DataEX_check_header_and_footer_devicedata(void); |
521 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) | 529 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) |
522 { | 530 { |
523 RTC_DateTypeDef sdatestructure; | 531 RTC_DateTypeDef sdatestructure; |
524 RTC_TimeTypeDef stimestructure; | 532 RTC_TimeTypeDef stimestructure; |
525 | 533 |
526 stimestructure.Hours = 1; | 534 stimestructure.Hours = UNKNOWN_TIME_HOURS; |
527 stimestructure.Minutes = 0; | 535 stimestructure.Minutes = UNKNOWN_TIME_MINUTES; |
528 stimestructure.Seconds = 0; | 536 stimestructure.Seconds = UNKNOWN_TIME_SECOND; |
529 | 537 |
530 sdatestructure.Date = 1; | 538 sdatestructure.Date = UNKNOWN_DATE_DAY; |
531 sdatestructure.Month = 1; | 539 sdatestructure.Month = UNKNOWN_DATE_MONTH; |
532 sdatestructure.Year = 16; | 540 sdatestructure.Year = UNKNOWN_DATE_YEAR; |
533 setWeekday(&sdatestructure); | 541 setWeekday(&sdatestructure); |
534 | 542 |
535 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); | 543 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); |
536 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); | 544 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); |
537 } | 545 } |
538 | 546 |
539 | 547 |
540 static uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite) | 548 static uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite) |
541 { | 549 { |
550 uint8_t retval = 0; | |
542 RTC_DateTypeDef sdatestructure; | 551 RTC_DateTypeDef sdatestructure; |
543 RTC_TimeTypeDef stimestructure; | 552 RTC_TimeTypeDef stimestructure; |
544 | 553 |
545 // from lineWrite to structure | 554 // from lineWrite to structure |
546 translateDate(lineWrite->date_rtc_dr, &sdatestructure); | 555 translateDate(lineWrite->date_rtc_dr, &sdatestructure); |
547 translateTime(lineWrite->time_rtc_tr, &stimestructure); | 556 translateTime(lineWrite->time_rtc_tr, &stimestructure); |
548 | 557 |
549 if( (sdatestructure.Year >= 15) | 558 /* Check if date is out of range */ |
559 if(!( (sdatestructure.Year >= 15) | |
550 && (sdatestructure.Year <= 30) | 560 && (sdatestructure.Year <= 30) |
551 && (sdatestructure.Month <= 12)) | 561 && (sdatestructure.Month <= 12))) |
552 return 0; | 562 { |
553 | 563 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); |
554 | 564 retval = 1; |
555 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | 565 } |
556 return 1; | 566 return retval; |
557 } | 567 } |
558 | 568 |
559 | 569 |
560 static uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to) | 570 static uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to, uint8_t defaulttofrom) |
561 { | 571 { |
562 if(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to) | 572 uint8_t retval = 0; |
563 return 0; | 573 RTC_DateTypeDef sdatestructure; |
564 | 574 |
565 if(lineWrite->value_int32 < from) | 575 /* Is value out of valid range? */ |
566 lineWrite->value_int32 = from; | 576 if(!(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to)) |
567 else | 577 { |
568 lineWrite->value_int32 = to; | 578 if(defaulttofrom) |
569 | 579 { |
570 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | 580 lineWrite->value_int32 = from; |
571 return 0; | 581 } |
582 else | |
583 { | |
584 lineWrite->value_int32 = to; | |
585 } | |
586 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | |
587 } | |
588 | |
589 /* This is just a repair function to restore metric if a corruption occurred in an older fw version */ | |
590 if(((lineWrite->value_int32 == to) && defaulttofrom ) | |
591 || ((lineWrite->value_int32 == from) && !defaulttofrom )) | |
592 { | |
593 translateDate(lineWrite->date_rtc_dr, &sdatestructure); | |
594 if(sdatestructure.Year == UNKNOWN_DATE_YEAR) | |
595 { | |
596 if(defaulttofrom) | |
597 { | |
598 lineWrite->value_int32 = from; | |
599 } | |
600 else | |
601 { | |
602 lineWrite->value_int32 = to; | |
603 } | |
604 } | |
605 } | |
606 return retval; | |
572 } | 607 } |
573 | 608 |
574 | 609 |
575 static void DataEX_check_DeviceData(void) | 610 static void DataEX_check_DeviceData(void) |
576 { | 611 { |
583 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation); | 618 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation); |
584 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum); | 619 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum); |
585 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum); | 620 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum); |
586 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum); | 621 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum); |
587 | 622 |
588 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000); | 623 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000,1); |
589 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000); | 624 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000,1); |
590 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000); | 625 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000,1); |
591 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000); | 626 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000,1); |
592 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000); | 627 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000,1); |
593 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100); | 628 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100,1); |
594 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100); | 629 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100,0); |
595 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, -1*1000, 6*1000); | 630 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, 2*1000, 6*1000,0); |
596 } | 631 } |
597 | 632 |
598 | 633 |
599 static void DataEX_merge_DeviceData_and_store(void) | 634 static void DataEX_merge_DeviceData_and_store(void) |
600 { | 635 { |
629 } | 664 } |
630 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | 665 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) |
631 { | 666 { |
632 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles); | 667 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles); |
633 } | 668 } |
669 if(DeviceData->hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) | |
670 { | |
671 DataEX_helper_copy_deviceData(&DeviceData->hoursOfOperation, &DeviceDataFlash.hoursOfOperation); | |
672 } | |
634 | 673 |
635 /* min values */ | 674 /* min values */ |
636 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | 675 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) |
637 { | 676 { |
638 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | 677 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); |
639 } | 678 } |
640 // Voltage minimum, keep limit to 2.0 Volt; hw 09.09.2015 | |
641 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | 679 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) |
642 { | 680 { |
643 if(DeviceDataFlash.voltageMinimum.value_int32 > 2000) // do not copy back 2000 and below | |
644 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum); | 681 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum); |
645 } | 682 } |
646 if(DeviceData->voltageMinimum.value_int32 < 2000) | |
647 DeviceData->voltageMinimum.value_int32 = 2000; | |
648 | 683 |
649 DataEX_check_DeviceData (); | 684 DataEX_check_DeviceData (); |
650 ext_flash_write_devicedata(); | 685 ext_flash_write_devicedata(); |
651 } | 686 } |
652 | 687 |