comparison Discovery/Src/data_exchange_main.c @ 342:ea3fda8eb93e FlightMode_Improvment

Removed averaging of pressure and temperatur values On RTE side data was copied once a second while the average function is called several time a second => no real averaging. In generell a datta value should be processed only once (in RTE) and then only be consumption. Otherwise a risk of inconsistent computations could be raised
author ideenmodellierer
date Tue, 01 Oct 2019 19:13:41 +0200
parents b0045281cb2d
children 439874690f85
comparison
equal deleted inserted replaced
340:0756013e43b3 342:ea3fda8eb93e
691 data_old__lost_connection_to_slave_counter_total += 1; 691 data_old__lost_connection_to_slave_counter_total += 1;
692 } 692 }
693 } 693 }
694 } 694 }
695 695
696 #define AVERAGE_COUNT 4
697 static float getSampleDepth(SDataExchangeSlaveToMaster *d, SDiveState *ds) 696 static float getSampleDepth(SDataExchangeSlaveToMaster *d, SDiveState *ds)
698 { 697 {
699 static uint8_t c = 0; 698 float ambient = 0;
700 static float ambient[AVERAGE_COUNT] = {0}; 699 float surface = 0;
701 static float surface[AVERAGE_COUNT]= {0}; 700 float depth = 0;
702 static float depth[AVERAGE_COUNT]= {0}; 701 float density = 0;
703 702
704 ambient[c] = d->data[d->boolPressureData].pressure_mbar / 1000.0f; 703 ambient = d->data[d->boolPressureData].pressure_mbar / 1000.0f;
705 surface[c] = d->data[d->boolPressureData].surface_mbar / 1000.0f; 704 surface = d->data[d->boolPressureData].surface_mbar / 1000.0f;
706 float density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f; 705 density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f;
707 706
708 ds->lifeData.pressure_ambient_bar = (ambient[0] + ambient[1] + ambient[2] + ambient[3])/4.0f; 707 ds->lifeData.pressure_ambient_bar = ambient;
709 ds->lifeData.pressure_surface_bar = (surface[0] + surface[1] + surface[2] + surface[3])/4.0f; 708 ds->lifeData.pressure_surface_bar = surface;
710 depth[c] = (ambient[c] - surface[c]) / (0.09807f * density); 709 depth = (ambient - surface) / (0.09807f * density);
711 710 ds->lifeData.bool_temp1 = d->data[d->boolPressureData].SPARE1;
712 c++; 711
713 if (c == AVERAGE_COUNT) c = 0; 712 return depth;
714 713 }
715 return (depth[0] + depth[1] + depth[2] + depth[3])/4.0f; 714
716 }
717
718 #define TEMP_AVERAGE_COUNT 3
719 static float getTemperature(SDataExchangeSlaveToMaster *d) 715 static float getTemperature(SDataExchangeSlaveToMaster *d)
720 { 716 {
721 static uint8_t c = 0; 717 float temp = 0;
722 static float temp[TEMP_AVERAGE_COUNT] = {0}; 718 temp = d->data[d->boolPressureData].temperature;
723 719
724 temp[c] = d->data[d->boolPressureData].temperature; 720 return temp;
725
726 c++;
727 if (c == TEMP_AVERAGE_COUNT) c = 0;
728
729 return (temp[0] + temp[1] + temp[2])/3.0f;
730 } 721 }
731 722
732 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) 723 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag)
733 { 724 {
734 SDiveState *pStateReal = stateRealGetPointerWrite(); 725 SDiveState *pStateReal = stateRealGetPointerWrite();