comparison Discovery/Src/data_exchange_main.c @ 696:cc542448fb28

Merge
author heinrichsweikamp
date Fri, 19 Aug 2022 11:30:24 +0200
parents 52d68cf9994c
children 6d7c812fc173
comparison
equal deleted inserted replaced
661:87bee7cc77b3 696:cc542448fb28
70 #include "tCCR.h" 70 #include "tCCR.h"
71 #include "timer.h" 71 #include "timer.h"
72 #include "buehlmann.h" 72 #include "buehlmann.h"
73 #include "externLogbookFlash.h" 73 #include "externLogbookFlash.h"
74 74
75 //#define TESTBENCH 75 /* #define TESTBENCH */
76 76
77 /* Exported variables --------------------------------------------------------*/ 77 /* Exported variables --------------------------------------------------------*/
78 static uint8_t wasPowerOn = 0; 78 static uint8_t wasPowerOn = 0;
79 static confirmbit8_Type requestNecessary = { .uw = 0 }; 79 static confirmbit8_Type requestNecessary = { .uw = 0 };
80 static uint8_t wasUpdateNotPowerOn = 0; 80 static uint8_t wasUpdateNotPowerOn = 0;
91 static uint8_t data_old__lost_connection_to_slave_counter_temp = 0; 91 static uint8_t data_old__lost_connection_to_slave_counter_temp = 0;
92 static uint8_t data_old__lost_connection_to_slave_counter_retry = 0; 92 static uint8_t data_old__lost_connection_to_slave_counter_retry = 0;
93 static uint32_t data_old__lost_connection_to_slave_counter_total = 0; 93 static uint32_t data_old__lost_connection_to_slave_counter_total = 0;
94 94
95 static uint8_t DeviceDataUpdated = 0; 95 static uint8_t DeviceDataUpdated = 0;
96
97 static uint16_t externalInterface_Cmd = 0;
96 98
97 /* Private types -------------------------------------------------------------*/ 99 /* Private types -------------------------------------------------------------*/
98 #define UNKNOWN_TIME_HOURS 1 100 #define UNKNOWN_TIME_HOURS 1
99 #define UNKNOWN_TIME_MINUTES 0 101 #define UNKNOWN_TIME_MINUTES 0
100 #define UNKNOWN_TIME_SECOND 0 102 #define UNKNOWN_TIME_SECOND 0
179 static uint8_t setEndDiveWasSend = 0; 181 static uint8_t setEndDiveWasSend = 0;
180 182
181 if(getDeviceDataWasSend) 183 if(getDeviceDataWasSend)
182 { 184 {
183 dataOut.getDeviceDataNow = 0; 185 dataOut.getDeviceDataNow = 0;
184 requestNecessary.ub.devicedata = 1;
185 } 186 }
186 getDeviceDataWasSend = 0; 187 getDeviceDataWasSend = 0;
187 if(dataOut.getDeviceDataNow) 188 if(dataOut.getDeviceDataNow)
188 { 189 {
189 getDeviceDataWasSend = 1; 190 getDeviceDataWasSend = 1;
191 requestNecessary.ub.devicedata = 1;
190 } 192 }
191 193
192 if(setEndDiveWasSend) 194 if(setEndDiveWasSend)
193 { 195 {
194 dataOut.setEndDive = 0; 196 dataOut.setEndDive = 0;
201 } 203 }
202 204
203 if(setAccidentFlagWasSend) 205 if(setAccidentFlagWasSend)
204 { 206 {
205 dataOut.setAccidentFlag = 0; 207 dataOut.setAccidentFlag = 0;
206 requestNecessary.ub.accident = 1;
207 } 208 }
208 setAccidentFlagWasSend = 0; 209 setAccidentFlagWasSend = 0;
209 if(dataOut.setAccidentFlag) 210 if(dataOut.setAccidentFlag)
210 { 211 {
211 setAccidentFlagWasSend = 1; 212 setAccidentFlagWasSend = 1;
213 requestNecessary.ub.accident = 1;
212 } 214 }
213 215
214 if(setDateWasSend) 216 if(setDateWasSend)
215 { 217 {
216 dataOut.setDateNow = 0; 218 dataOut.setDateNow = 0;
217 requestNecessary.ub.date = 1;
218 } 219 }
219 setDateWasSend = 0; 220 setDateWasSend = 0;
220 if(dataOut.setDateNow) 221 if(dataOut.setDateNow)
221 { 222 {
222 setDateWasSend = 1; 223 setDateWasSend = 1;
224 requestNecessary.ub.date = 1;
223 } 225 }
224 226
225 if(setTimeWasSend) 227 if(setTimeWasSend)
226 { 228 {
227 dataOut.setTimeNow = 0; 229 dataOut.setTimeNow = 0;
228 requestNecessary.ub.time = 1;
229 } 230 }
230 setTimeWasSend = 0; 231 setTimeWasSend = 0;
231 if(dataOut.setTimeNow) 232 if(dataOut.setTimeNow)
232 { 233 {
233 setTimeWasSend = 1; 234 setTimeWasSend = 1;
235 requestNecessary.ub.time = 1;
234 } 236 }
235 237
236 if(calibrateCompassWasSend) 238 if(calibrateCompassWasSend)
237 { 239 {
238 dataOut.calibrateCompassNow = 0; 240 dataOut.calibrateCompassNow = 0;
239 requestNecessary.ub.compass = 1;
240 } 241 }
241 calibrateCompassWasSend = 0; 242 calibrateCompassWasSend = 0;
242 if(dataOut.calibrateCompassNow) 243 if(dataOut.calibrateCompassNow)
243 { 244 {
244 calibrateCompassWasSend = 1; 245 calibrateCompassWasSend = 1;
245 } 246 }
246 247
247 if(clearDecoWasSend) 248 if(clearDecoWasSend)
248 { 249 {
249 dataOut.clearDecoNow = 0; 250 dataOut.clearDecoNow = 0;
251 requestNecessary.ub.compass = 1;
252 }
253 if(dataOut.clearDecoNow)
254 {
255 clearDecoWasSend = 1;
250 requestNecessary.ub.clearDeco = 1; 256 requestNecessary.ub.clearDeco = 1;
251 } 257 }
252 if(dataOut.clearDecoNow)
253 {
254 clearDecoWasSend = 1;
255 }
256 258
257 if(setButtonSensitivityWasSend) 259 if(setButtonSensitivityWasSend)
258 { 260 {
259 dataOut.setButtonSensitivityNow = 0; 261 dataOut.setButtonSensitivityNow = 0;
260 requestNecessary.ub.button = 1;
261 } 262 }
262 setButtonSensitivityWasSend = 0; 263 setButtonSensitivityWasSend = 0;
263 if(dataOut.setButtonSensitivityNow) 264 if(dataOut.setButtonSensitivityNow)
264 { 265 {
265 setButtonSensitivityWasSend = 1; 266 setButtonSensitivityWasSend = 1;
267 requestNecessary.ub.button = 1;
266 } 268 }
267 } 269 }
268 270
269 271
270 uint8_t DataEX_call(void) 272 uint8_t DataEX_call(void)
386 dataOut.data.divetimeToCreateLogbook = settings->divetimeToCreateLogbook; 388 dataOut.data.divetimeToCreateLogbook = settings->divetimeToCreateLogbook;
387 dataOut.data.timeoutDiveReachedZeroDepth = settings->timeoutDiveReachedZeroDepth; 389 dataOut.data.timeoutDiveReachedZeroDepth = settings->timeoutDiveReachedZeroDepth;
388 390
389 dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar; 391 dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar;
390 dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad; 392 dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad;
393
394
395
396 if(settings->ppo2sensors_source == O2_SENSOR_SOURCE_ANALOG)
397 {
398 externalInterface_Cmd |= EXT_INTERFACE_ADC_ON | EXT_INTERFACE_33V_ON;
399 }
400
401 #ifdef ENABLE_SENTINEL_MODE
402 if(settings->ppo2sensors_source == O2_SENSOR_SOURCE_SENTINEL)
403 {
404 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_SENTINEL;
405 externalInterface_Cmd &= (~EXT_INTERFACE_ADC_ON);
406 }
407 #endif
408
409 if(settings->ext_uart_protocol)
410 {
411 externalInterface_Cmd |= (settings->ext_uart_protocol << 8);
412 }
413 if(settings->co2_sensor_active)
414 {
415 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_CO2;
416 }
417 dataOut.data.externalInterface_Cmd = externalInterface_Cmd;
418 externalInterface_Cmd = 0;
391 419
392 if((hardwareDataGetPointer()->primarySerial <= 32) || (((hardwareDataGetPointer()->primarySerial == 72) && (hardwareDataGetPointer()->secondarySerial == 15)))) 420 if((hardwareDataGetPointer()->primarySerial <= 32) || (((hardwareDataGetPointer()->primarySerial == 72) && (hardwareDataGetPointer()->secondarySerial == 15))))
393 { 421 {
394 dataOut.revisionHardware = 0x00; 422 dataOut.revisionHardware = 0x00;
395 dataOut.revisionCRCx0x7A = 0x7A; 423 dataOut.revisionCRCx0x7A = 0x7A;
771 return temp; 799 return temp;
772 } 800 }
773 801
774 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) 802 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag)
775 { 803 {
804 static uint16_t getDeviceDataAfterStartOfMainCPU = 20;
805
776 SDiveState *pStateReal = stateRealGetPointerWrite(); 806 SDiveState *pStateReal = stateRealGetPointerWrite();
777 static uint16_t getDeviceDataAfterStartOfMainCPU = 20;
778 uint8_t idx; 807 uint8_t idx;
808 float meter = 0;
809 SSettings *pSettings;
810
811
779 812
780 // wireless - �ltere daten aufr�umen 813 // wireless - �ltere daten aufr�umen
781 #if 0 814 #if 0
782 for(int i=0;i<(2*NUM_GASES+1);i++) 815 for(int i=0;i<(2*NUM_GASES+1);i++)
783 { 816 {
834 dataOut.getDeviceDataNow = 1; 867 dataOut.getDeviceDataNow = 1;
835 getDeviceDataAfterStartOfMainCPU = 10*60*10; /* * 100ms = 60 second => update device data every 10 minutes */ 868 getDeviceDataAfterStartOfMainCPU = 10*60*10; /* * 100ms = 60 second => update device data every 10 minutes */
836 } 869 }
837 } 870 }
838 871
839 /* new 151207 hw */ 872 if((requestNecessary.uw != 0) && (dataIn.confirmRequest.uw != 0))
840 if(requestNecessary.uw != 0)
841 { 873 {
842 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0) 874 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0)
843 { 875 {
844 requestNecessary.ub.button = 0; 876 requestNecessary.ub.button = 0;
845 } 877 }
846 878 if(((dataIn.confirmRequest.uw) & CRCLEARDECO) != 0)
847 if(requestNecessary.ub.button == 1) 879 {
880 requestNecessary.ub.clearDeco = 0;
881 }
882 if(((dataIn.confirmRequest.uw) & CRDATE) != 0)
883 {
884 requestNecessary.ub.date = 0;
885 }
886 if(((dataIn.confirmRequest.uw) & CRTIME) != 0)
887 {
888 requestNecessary.ub.time = 0;
889 }
890 if(((dataIn.confirmRequest.uw) & CRCOMPASS) != 0)
891 {
892 requestNecessary.ub.compass = 0;
893 }
894 if(((dataIn.confirmRequest.uw) & CRDEVICEDATA) != 0)
895 {
896 requestNecessary.ub.devicedata = 0;
897 }
898 if(((dataIn.confirmRequest.uw) & CRBATTERY) != 0)
899 {
900 requestNecessary.ub.batterygauge = 0;
901 }
902 if(((dataIn.confirmRequest.uw) & CRACCIDENT) != 0)
903 {
904 requestNecessary.ub.accident = 0;
905 }
906
907 if(requestNecessary.ub.button == 1) /* send button values to RTE */
848 { 908 {
849 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); 909 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness);
850 } 910 }
851 } 911 }
852 requestNecessary.uw = 0; // clear all
853
854 float meter = 0;
855 SSettings *pSettings;
856 912
857 /* uint8_t IAmStolenPleaseKillMe; 913 /* uint8_t IAmStolenPleaseKillMe;
858 */ 914 */
859 pSettings = settingsGetPointer(); 915 pSettings = settingsGetPointer();
860 916
881 { 937 {
882 if(pStateReal->data_old__lost_connection_to_slave == 0) 938 if(pStateReal->data_old__lost_connection_to_slave == 0)
883 { 939 {
884 for(idx = 0; idx < 3; idx++) 940 for(idx = 0; idx < 3; idx++)
885 { 941 {
886 pStateReal->lifeData.sensorVoltage_mV[idx] = dataIn.data[0].extADC_voltage[idx]; 942 pStateReal->lifeData.sensorVoltage_mV[idx] = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].extADC_voltage[idx];
887 if(pStateReal->lifeData.sensorVoltage_mV[idx] < IGNORE_O2_VOLTAGE_LEVEL_MV) 943 if(pStateReal->lifeData.sensorVoltage_mV[idx] < IGNORE_O2_VOLTAGE_LEVEL_MV)
888 { 944 {
889 pStateReal->lifeData.sensorVoltage_mV[idx] = 0.0; 945 pStateReal->lifeData.sensorVoltage_mV[idx] = 0.0;
890 pStateReal->lifeData.ppO2Sensor_bar[idx] = 0; 946 pStateReal->lifeData.ppO2Sensor_bar[idx] = 0;
891 } 947 }
907 pStateReal->pressure_uTick_local_new = HAL_GetTick(); 963 pStateReal->pressure_uTick_local_new = HAL_GetTick();
908 964
909 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr; 965 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr;
910 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr; 966 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr;
911 } 967 }
912 dataOut.setAccidentFlag = 0;
913 968
914 if(pStateReal->data_old__lost_connection_to_slave == 0) 969 if(pStateReal->data_old__lost_connection_to_slave == 0)
915 { 970 {
916 //Start of diveMode? 971 //Start of diveMode?
917 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE) 972 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE)
969 { 1024 {
970 if(meter > pStateReal->lifeData.max_depth_meter) 1025 if(meter > pStateReal->lifeData.max_depth_meter)
971 pStateReal->lifeData.max_depth_meter = meter; 1026 pStateReal->lifeData.max_depth_meter = meter;
972 } 1027 }
973 1028
974 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP) 1029 if(requestNecessary.ub.clearDeco == 0) /* No "reset deco" is send to RTE ? */
975 pStateReal->decoMissed_at_the_end_of_dive = 1; 1030 {
976 if(dataIn.accidentFlags & ACCIDENT_CNS) 1031 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP)
977 pStateReal->cnsHigh_at_the_end_of_dive = 1; 1032 {
978 1033 pStateReal->decoMissed_at_the_end_of_dive = 1;
1034 }
1035 else
1036 {
1037 pStateReal->decoMissed_at_the_end_of_dive = 0;
1038 }
1039 if(dataIn.accidentFlags & ACCIDENT_CNS)
1040 {
1041 pStateReal->cnsHigh_at_the_end_of_dive = 1;
1042 }
1043 else
1044 {
1045 pStateReal->cnsHigh_at_the_end_of_dive = 0;
1046 }
1047 }
979 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds; 1048 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds;
980 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time; 1049 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time;
981 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth; 1050 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth;
982 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds; 1051 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds;
983 1052
1028 } 1097 }
1029 1098
1030 /* sensorErrors 1099 /* sensorErrors
1031 */ 1100 */
1032 pStateReal->sensorErrorsRTE = dataIn.sensorErrors; 1101 pStateReal->sensorErrorsRTE = dataIn.sensorErrors;
1102
1103 /* data from CO2 sensor */
1104 pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm;
1105 pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_signalStrength;
1033 } 1106 }
1034 1107
1035 /* apnea specials 1108 /* apnea specials
1036 */ 1109 */
1037 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea) 1110 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea)
1203 uint8_t retval; 1276 uint8_t retval;
1204 retval = hw_Info.extADC; 1277 retval = hw_Info.extADC;
1205 1278
1206 return retval; 1279 return retval;
1207 } 1280 }
1281
1282 void DataEX_setExtInterface_Cmd(uint16_t Cmd)
1283 {
1284 externalInterface_Cmd = Cmd;
1285 return;
1286 }
1287