GCC Code Coverage Report


Directory: ./
File: firmware/controllers/sensors/impl/map.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 20.0% 3 0 15
Functions: 50.0% 1 0 2
Branches: 7.7% 1 0 13
Decisions: 16.7% 1 - 6

Line Branch Decision Exec Source
1 /**
2 * @file map.cpp
3 *
4 * See also map_averaging.cpp
5 *
6 * @author Andrey Belomutskiy, (c) 2012-2020
7 */
8 #include "pch.h"
9
10 #if EFI_ANALOG_SENSORS
11
12 /**
13 * This function checks if Baro/MAP sensor value is inside of expected range
14 * @return unchanged mapKPa parameter or NaN
15 */
16 static float validateBaroMap(float mapKPa) {
17 // Highest interstate is the Eisenhower Tunnel at 11158 feet -> 66 kpa
18 // Lowest point is the Dead Sea, -1411 feet -> 106 kpa
19 if (std::isnan(mapKPa) || mapKPa > 110 || mapKPa < 60) {
20 warning(ObdCode::OBD_Barometric_Press_Circ, "Invalid start-up baro pressure = %.2fkPa", mapKPa);
21 return NAN;
22 }
23 return mapKPa;
24 }
25
26 #if EFI_PROD_CODE
27
28 static void printMAPInfo() {
29 #if EFI_ANALOG_SENSORS
30 efiPrintf("instant value=%.2fkPa", Sensor::getOrZero(SensorType::Map));
31
32 #if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
33 efiPrintf("map type=%d/%s MAP=%.2fkPa", engineConfiguration->map.sensor.type,
34 getAir_pressure_sensor_type_e(engineConfiguration->map.sensor.type),
35 Sensor::getOrZero(SensorType::Map));
36 #endif // EFI_MAP_AVERAGING
37
38 adc_channel_e mapAdc = engineConfiguration->map.sensor.hwChannel;
39 char pinNameBuffer[16];
40
41 efiPrintf("MAP %.2fv @%s",
42 adcGetRawVoltage("mapinfo", mapAdc).value_or(0),
43 getPinNameByAdcChannel("map", mapAdc, pinNameBuffer, sizeof(pinNameBuffer)));
44 if (engineConfiguration->map.sensor.type == MT_CUSTOM) {
45 efiPrintf("at %.2fv=%.2f at %.2fv=%.2f",
46 engineConfiguration->mapLowValueVoltage,
47 engineConfiguration->map.sensor.lowValue,
48 engineConfiguration->mapHighValueVoltage,
49 engineConfiguration->map.sensor.highValue);
50 }
51
52 if (Sensor::hasSensor(SensorType::BarometricPressure)) {
53 efiPrintf("baro type=%d value=%.2f", engineConfiguration->baroSensor.type, Sensor::get(SensorType::BarometricPressure).value_or(-1));
54 if (engineConfiguration->baroSensor.type == MT_CUSTOM) {
55 efiPrintf("min=%.2f@%.2f max=%.2f@%.2f",
56 engineConfiguration->baroSensor.lowValue,
57 engineConfiguration->mapLowValueVoltage,
58 engineConfiguration->baroSensor.highValue,
59 engineConfiguration->mapHighValueVoltage);
60 }
61 }
62 #endif /* EFI_ANALOG_SENSORS */
63 }
64 #endif /* EFI_PROD_CODE */
65
66 584 void initMapDecoder() {
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 584 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 584 times.
584 if (engineConfiguration->useFixedBaroCorrFromMap) {
68 // Read initial MAP sensor value and store it for Baro correction.
69 float storedInitialBaroPressure = Sensor::get(SensorType::MapSlow).value_or(STD_ATMOSPHERE);
70 efiPrintf("Get initial baro MAP pressure = %.2fkPa", storedInitialBaroPressure);
71 // validate if it's within a reasonable range (the engine should not be spinning etc.)
72 storedInitialBaroPressure = validateBaroMap(storedInitialBaroPressure);
73 if (!std::isnan(storedInitialBaroPressure)) {
74 efiPrintf("Using this fixed MAP pressure to override the baro correction!");
75
76 // TODO: do literally anything other than this
77 Sensor::setMockValue(SensorType::BarometricPressure, storedInitialBaroPressure);
78 } else {
79 efiPrintf("The baro pressure is invalid. The fixed baro correction will be disabled!");
80 }
81 }
82
83 #if EFI_PROD_CODE
84 addConsoleAction("mapinfo", printMAPInfo);
85 #endif
86 584 }
87
88 #else /* EFI_ANALOG_SENSORS */
89
90 void initMapDecoder() {
91 }
92
93 #endif /* EFI_ANALOG_SENSORS */
94