code style, GPS fixes (test, firmware) (#4822)

* tidy NMEA

* const in nmea

* correct gps test output

* fix GPS UART print statements

* cleanup feature toggles in settings

* fix comment typos, misc whitespace
This commit is contained in:
Nathan Schulte 2022-11-23 05:01:34 -06:00 committed by GitHub
parent d64aaaf707
commit fd1115d01a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 58 additions and 70 deletions

View File

@ -15,7 +15,7 @@
#ifndef EFI_EMBED_INI_MSD
#define EFI_EMBED_INI_MSD FALSE
#endif
#include "../stm32f4ems/efifeatures.h"
#pragma once

View File

@ -10,7 +10,7 @@
extern "C"
{
#endif /* __cplusplus */
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -29,7 +29,7 @@ static long hex2int(const char *a, int len) {
for (i = 0; i < len; i++)
if (a[i] <= 57)
val += (a[i] - 48) * (1 << (4 * (len - 1 - i))); // it's number
val += (a[i] - 48) * (1 << (4 * (len - 1 - i))); // it's decimal number
else
val += (a[i] - 87) * (1 << (4 * (len - 1 - i))); // it's a-f -> work only with low case hex
return val;
@ -68,7 +68,7 @@ static void gps_convert_deg_to_dec(float *latitude, char ns, float *longitude, c
}
// in string collect all char till comma and convert to float
static int str_till_comma(char *a, char *dStr) {
static int str_till_comma(const char * const a, char * const dStr) {
int i = 0, sLen = strlen(a);
if (sLen > GPS_MAX_STRING)
@ -100,8 +100,8 @@ Unit M=Meters
Age of DGPS Corr s Age of Differential Corrections
DGPS Ref Station ID of DGPS Reference Station
*/
void nmea_parse_gpgga(char *nmea, loc_t *loc) {
char *p = nmea;
void nmea_parse_gpgga(char const * const nmea, loc_t *loc) {
char const * p = (char *)nmea;
char dStr[GPS_MAX_STRING];
p = strchr(p, ',') + 1; //skip time - we read date&time if Valid in GxRMC
@ -175,14 +175,14 @@ Magnetic Variation ° Magnetic Variation
Magnetic Variation E=East,W=West
Mode Indicator N A=Autonomous, D=Differential, E=Dead Reckoning, N=None
Navigational Status S=Safe C=Caution U=Unsafe V=Not valid
*/
void nmea_parse_gprmc(char *nmea, loc_t *loc) {
char *p = nmea;
void nmea_parse_gprmc(char const * const nmea, loc_t *loc) {
char const * p = (char *)nmea;
char dStr[GPS_MAX_STRING];
struct tm timp;
p = strchr(p, ',') + 1; //read time
p = strchr(p, ',') + 1; // read time
str_till_comma(p, dStr);
if (strlen(dStr) > 5) {
timp.tm_hour = str2int(dStr,2);
@ -190,7 +190,7 @@ void nmea_parse_gprmc(char *nmea, loc_t *loc) {
timp.tm_sec = str2int(dStr+4,2);
}
p = strchr(p, ',') + 1; //read field Valid status
p = strchr(p, ',') + 1; // read field Valid status
str_till_comma(p, dStr);
if (dStr[0] == 'V') { // if field is invalid
@ -217,7 +217,7 @@ void nmea_parse_gprmc(char *nmea, loc_t *loc) {
break;
}
p = strchr(p, ',') + 1; // longitude
p = strchr(p, ',') + 1; // longitude
str_till_comma(p, dStr); // str to float till comma saved modified string
loc->longitude = atoff(dStr);
@ -242,7 +242,7 @@ void nmea_parse_gprmc(char *nmea, loc_t *loc) {
str_till_comma(p, dStr); // str to float till comma saved modified string
loc->course = atoff(dStr);
p = strchr(p, ',') + 1; //read date
p = strchr(p, ',') + 1; // read date
str_till_comma(p, dStr);
if (strlen(dStr) > 5) {
timp.tm_mday = str2int(dStr,2);
@ -280,7 +280,7 @@ nmea_message_type nmea_get_message_type(const char *message) {
return NMEA_UNKNOWN;
}
int nmea_valid_checksum(const char *message) {
int nmea_valid_checksum(char const * message) {
char p;
int sum = 0;
const char* starPtr = strrchr(message, '*');
@ -302,8 +302,7 @@ int nmea_valid_checksum(const char *message) {
}
// Compute the GPS location using decimal scale
void gps_location(loc_t *coord, char *buffer) {
void gps_location(loc_t *coord, char const * const buffer) {
coord->type = nmea_get_message_type(buffer);
switch (coord->type) {
@ -318,5 +317,4 @@ void gps_location(loc_t *coord, char *buffer) {
// unknown message type
break;
}
}

View File

@ -39,6 +39,6 @@ typedef struct GPSlocation loc_t;
nmea_message_type nmea_get_message_type(const char *);
int nmea_valid_checksum(const char *);
void nmea_parse_gpgga(char *, loc_t *);
void nmea_parse_gprmc(char *, loc_t *);
void gps_location(loc_t *, char *);
void nmea_parse_gpgga(char const * const, loc_t *);
void nmea_parse_gprmc(char const * const, loc_t *);
void gps_location(loc_t *, char const * const);

View File

@ -34,8 +34,8 @@ using time_t = uint32_t;
#define FOUR_STROKE_CYCLE_DURATION 720
// gasoline E0
#define STOICH_RATIO 14.7f
#define CONST_PI 3.14159265358979323846
#define STOICH_RATIO 14.7f
#define CONST_PI 3.14159265358979323846
// time in seconds

View File

@ -17,6 +17,7 @@
#include "rtc_helper.h"
#include "fuel_math.h"
// CAN Bus ID for broadcast
#define CAN_FIAT_MOTOR_INFO 0x561
#define CAN_MAZDA_RX_RPM_SPEED 0x201
@ -432,7 +433,7 @@ void canDashboardBMWE90(CanCycle cycle)
msg[1] = 0x41;
msg[2] = 0x61;
msg[3] = 0x8F;
msg[4] = 0xFC;
msg[4] = 0xFC;
}
{ //Ebrake light

View File

@ -8,7 +8,7 @@
#include "pch.h"
#if !EFI_UNIT_TEST
#if ! EFI_UNIT_TEST
#include "eficonsole.h"
#include "trigger_decoder.h"
@ -23,21 +23,21 @@
#include "can_hw.h"
#include "rusefi.h"
#include "hardware.h"
#endif /* EFI_PROD_CODE */
#endif // EFI_PROD_CODE
#if EFI_ELECTRONIC_THROTTLE_BODY
#include "electronic_throttle.h"
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
#endif // EFI_ELECTRONIC_THROTTLE_BODY
#if EFI_INTERNAL_FLASH
#include "flash_main.h"
#endif /* EFI_INTERNAL_FLASH */
#endif // EFI_INTERNAL_FLASH
#if EFI_ENGINE_SNIFFER
#include "engine_sniffer.h"
extern int waveChartUsedSize;
extern WaveChart waveChart;
#endif /* EFI_ENGINE_SNIFFER */
#endif // EFI_ENGINE_SNIFFER
void printSpiState(const engine_configuration_s *engineConfiguration) {
efiPrintf("spi 1=%s/2=%s/3=%s/4=%s",
@ -139,11 +139,10 @@ void printConfiguration(const engine_configuration_s *engineConfiguration) {
efiPrintf("digitalPotentiometer CS%d %s", i,
hwPortname(engineConfiguration->digitalPotentiometerChipSelect[i]));
}
#if EFI_PROD_CODE
printSpiState(engineConfiguration);
#endif /* EFI_PROD_CODE */
#endif // EFI_PROD_CODE
}
static void doPrintConfiguration() {
@ -255,7 +254,6 @@ static void setRpmHardLimit(int value) {
static void setCrankingIACExtra(float percent) {
engineConfiguration->crankingIACposition = percent;
efiPrintf("cranking_iac %.2f", percent);
}
static void setCrankingFuel(float timeMs) {
@ -614,7 +612,7 @@ static void setAnalogInputPin(const char *sensorStr, const char *pinName) {
}
incrementGlobalConfigurationVersion();
}
#endif
#endif // HAL_USE_ADC
static void setLogicInputPin(const char *indexStr, const char *pinName) {
int index = atoi(indexStr);
@ -638,7 +636,7 @@ static void showPinFunction(const char *pinName) {
efiPrintf("Pin %s: [%s]", pinName, getPinFunction(pin));
}
#endif /* EFI_PROD_CODE */
#endif // EFI_PROD_CODE
static void setSpiMode(int index, bool mode) {
switch (index) {
@ -687,8 +685,8 @@ static void enableOrDisable(const char *param, bool isEnabled) {
} else if (strEqualCaseInsensitive(param, "auto_idle")) {
#if EFI_IDLE_CONTROL
setIdleMode(isEnabled ? IM_MANUAL : IM_AUTO);
#endif /* EFI_IDLE_CONTROL */
#endif /* EFI_PROD_CODE */
#endif // EFI_IDLE_CONTROL
#endif // EFI_PROD_CODE
} else if (strEqualCaseInsensitive(param, "stepperidle")) {
engineConfiguration->useStepperIdle = isEnabled;
} else if (strEqualCaseInsensitive(param, "two_wire_batch_injection")) {
@ -748,7 +746,7 @@ static void enableOrDisable(const char *param, bool isEnabled) {
} else {
disableTriggerStimulator();
}
#endif
#endif // EFI_EMULATE_POSITION_SENSORS
} else if (strEqualCaseInsensitive(param, "engine_control")) {
engineConfiguration->isEngineControlEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "map_avg")) {
@ -789,7 +787,6 @@ void scheduleStopEngine(void) {
doScheduleStopEngine();
}
#if ! EFI_UNIT_TEST
const plain_get_short_s getS_plain[] = {
{"idle_pid_min", (uint16_t *)&engineConfiguration->idleRpmPid.minValue},
{"idle_pid_max", (uint16_t *)&engineConfiguration->idleRpmPid.maxValue},
@ -824,8 +821,6 @@ static plain_get_integer_s getI_plain[] = {
// {"idle_rpm", setTargetIdleRpm},
};
#endif /* EFI_UNIT_TEST */
static plain_get_integer_s *findInt(const char *name) {
plain_get_integer_s *currentI = &getI_plain[0];
while (currentI < getI_plain + efi::size(getI_plain)) {
@ -838,7 +833,6 @@ static plain_get_integer_s *findInt(const char *name) {
}
static void getValue(const char *paramStr) {
#if ! EFI_UNIT_TEST
{
plain_get_integer_s *known = findInt(paramStr);
if (known != nullptr) {
@ -856,16 +850,12 @@ static void getValue(const char *paramStr) {
}
}
#endif /* EFI_UNIT_TEST */
if (strEqualCaseInsensitive(paramStr, "isCJ125Enabled")) {
efiPrintf("isCJ125Enabled=%d", engineConfiguration->isCJ125Enabled);
#if EFI_PROD_CODE
} else if (strEqualCaseInsensitive(paramStr, "bor")) {
showBor();
#endif /* EFI_PROD_CODE */
#endif // EFI_PROD_CODE
} else if (strEqualCaseInsensitive(paramStr, "tps_min")) {
efiPrintf("tps_min=%d", engineConfiguration->tpsMin);
} else if (strEqualCaseInsensitive(paramStr, "tps_max")) {
@ -933,15 +923,15 @@ const command_f_s commandsF[] = {
{"idle_p", setIdlePFactor},
{"idle_i", setIdleIFactor},
{"idle_d", setIdleDFactor},
#endif /* EFI_IDLE_CONTROL */
#endif /* EFI_PROD_CODE */
#endif // EFI_IDLE_CONTROL
#endif // EFI_PROD_CODE
#if EFI_ELECTRONIC_THROTTLE_BODY && (!EFI_UNIT_TEST)
#if EFI_ELECTRONIC_THROTTLE_BODY
{"etb_p", setEtbPFactor},
{"etb_i", setEtbIFactor},
{"etb_d", setEtbDFactor},
{"etb", setThrottleDutyCycle},
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
#endif // EFI_ELECTRONIC_THROTTLE_BODY
// {"", },
// {"", },
@ -988,16 +978,16 @@ const command_i_s commandsI[] = {{"ignition_mode", setIgnitionMode},
#if EFI_CAN_SUPPORT
{"can_mode", setCanType},
{"can_vss", setCanVss},
#endif /* EFI_CAN_SUPPORT */
#endif // EFI_CAN_SUPPORT
#if EFI_IDLE_CONTROL
{"idle_position", setManualIdleValvePosition},
{"idle_rpm", setTargetIdleRpm},
#endif /* EFI_IDLE_CONTROL */
#endif /* EFI_PROD_CODE */
#endif // EFI_IDLE_CONTROL
#endif // EFI_PROD_CODE
#if EFI_ELECTRONIC_THROTTLE_BODY
{"etb_o", setEtbOffset},
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
#endif // EFI_ELECTRONIC_THROTTLE_BODY
// {"", },
// {"", },
@ -1039,7 +1029,7 @@ static void setValue(const char *paramStr, const char *valueStr) {
} else if (strEqualCaseInsensitive(paramStr, "alt_p")) {
setAltPFactor(valueF);
} else
#endif /* EFI_ALTERNATOR_CONTROL */
#endif // EFI_ALTERNATOR_CONTROL
if (strEqualCaseInsensitive(paramStr, "warning_period")) {
engineConfiguration->warningPeriod = valueI;
} else if (strEqualCaseInsensitive(paramStr, "dwell")) {
@ -1058,7 +1048,7 @@ static void setValue(const char *paramStr, const char *valueStr) {
#if EFI_EMULATE_POSITION_SENSORS
} else if (strEqualCaseInsensitive(paramStr, CMD_RPM)) {
setTriggerEmulatorRPM(valueI);
#endif /* EFI_EMULATE_POSITION_SENSORS */
#endif // EFI_EMULATE_POSITION_SENSORS
} else if (strEqualCaseInsensitive(paramStr, "vvt_offset")) {
engineConfiguration->vvtOffsets[0] = valueF;
} else if (strEqualCaseInsensitive(paramStr, "vvt_mode")) {
@ -1091,7 +1081,7 @@ static void setValue(const char *paramStr, const char *valueStr) {
void initSettings(void) {
#if EFI_SIMULATOR
printf("initSettings\n");
#endif
#endif // EFI_SIMULATOR
// todo: start saving values into flash right away?
@ -1159,30 +1149,30 @@ void initSettings(void) {
#if HAL_USE_ADC
addConsoleActionSS("set_analog_input_pin", setAnalogInputPin);
#endif
#endif // HAL_USE_ADC
addConsoleActionSS(CMD_LOGIC_PIN, setLogicInputPin);
addConsoleActionI("set_pot_spi", setPotSpi);
#endif /* EFI_PROD_CODE */
#endif // EFI_PROD_CODE
}
#endif /* !EFI_UNIT_TEST */
#endif // ! EFI_UNIT_TEST
void setEngineType(int value) {
{
#if EFI_PROD_CODE
chibios_rt::CriticalSectionLocker csl;
#endif /* EFI_PROD_CODE */
#endif // EFI_PROD_CODE
engineConfiguration->engineType = (engine_type_e)value;
resetConfigurationExt((engine_type_e)value);
engine->resetEngineSnifferIfInTestMode();
#if EFI_INTERNAL_FLASH
#if EFI_INTERNAL_FLASH
writeToFlashNow();
#endif /* EFI_INTERNAL_FLASH */
#endif // EFI_INTERNAL_FLASH
}
incrementGlobalConfigurationVersion();
#if ! EFI_UNIT_TEST
doPrintConfiguration();
#endif /* EFI_UNIT_TEST */
#endif // ! EFI_UNIT_TEST
}

View File

@ -49,8 +49,8 @@ static void printGpsInfo() {
float sec = getTimeNowMs() / 1000.0;
efiPrintf("communication speed: %.2f", gpsMesagesCount / sec);
print("GPS latitude = %.2f\r\n", GPSdata.latitude);
print("GPS longitude = %.2f\r\n", GPSdata.longitude);
efiPrintf("GPS latitude = %.2f\r\n", GPSdata.latitude);
efiPrintf("GPS longitude = %.2f\r\n", GPSdata.longitude);
}
static struct tm curTm;
@ -83,7 +83,7 @@ static THD_FUNCTION(GpsThreadEntryPoint, arg) {
if (count >= 1)
gps_str[--count] = '\0'; // delete 0xD
// scheduleMsg(&logger, "got GPS [%s]", gps_str);
// scheduleMsg(&logger, "got GPS [%s]", gps_str);
// 'gps_str' string completed
onGpsMessage(gps_str);

View File

@ -1,7 +1,7 @@
rem
rem this takes about 12 minutes to run unfortunatelly, current implementation is pretty inefficient :( See comments around 'nextChart()' method
rem pa
rem
rem
set port=%1
echo "Port (optional): %port%"

View File

@ -116,4 +116,3 @@ efitimems_t getTimeNowMs();
efitimesec_t getTimeNowS();
#endif /* __cplusplus */

View File

@ -286,7 +286,7 @@ TEST(misc, testGpsParser) {
ASSERT_EQ( 0, GPSdata.course) << "3 course";
ASSERT_EQ( 2006, GPSdata.GPStm.tm_year + 1900) << "3 GPS yy";
ASSERT_EQ( 12, GPSdata.GPStm.tm_mon) << "3 GPS mm";
ASSERT_EQ( 26, GPSdata.GPStm.tm_mday) << "3 GPS yy";
ASSERT_EQ( 26, GPSdata.GPStm.tm_mday) << "3 GPS dd";
ASSERT_EQ( 11, GPSdata.GPStm.tm_hour) << "3 GPS hh";
ASSERT_EQ( 16, GPSdata.GPStm.tm_min) << "3 GPS mm";
ASSERT_EQ( 9, GPSdata.GPStm.tm_sec) << "3 GPS ss";