diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index c7d7434c73..0766a48625 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -211,6 +211,10 @@ static void sendErrorCode(ts_channel_s *tsChannel, uint8_t code) { sr5WriteCrcPacket(tsChannel, code, nullptr, 0); } +void TunerStudio::sendErrorCode(ts_channel_s* tsChannel, uint8_t code) { + ::sendErrorCode(tsChannel, code); +} + static void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode) { tsState.pageCommandCounter++; @@ -460,7 +464,7 @@ static bool isKnownCommand(char command) { || command == TS_GET_CONFIG_ERROR; } -TunerStudioBase tsInstance; +TunerStudio tsInstance(&tsLogger); static void tsProcessOne(ts_channel_s* tsChannel) { validateStack("communication", STACK_USAGE_COMMUNICATION, 128); @@ -616,24 +620,6 @@ void handleQueryCommand(ts_channel_s *tsChannel, ts_response_format_e mode) { sr5SendResponse(tsChannel, mode, (const uint8_t *)signature, strlen(signature) + 1); } -/** - * @brief 'Output' command sends out a snapshot of current values - * Gauges refresh - */ -static void handleOutputChannelsCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) { - if (offset + count > sizeof(TunerStudioOutputChannels)) { - scheduleMsg(&tsLogger, "TS: Version Mismatch? Too much outputs requested %d/%d/%d", offset, count, - sizeof(TunerStudioOutputChannels)); - sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE); - return; - } - - tsState.outputChannelsCommandCounter++; - prepareTunerStudioOutputs(); - // this method is invoked too often to print any debug information - sr5SendResponse(tsChannel, mode, ((const uint8_t *) &tsOutputChannels) + offset, count); -} - /** * rusEfi own test command */ @@ -659,10 +645,10 @@ static void handleTestCommand(ts_channel_s *tsChannel) { extern CommandHandler console_line_callback; -static void handleGetVersion(ts_channel_s *tsChannel, ts_response_format_e mode) { +static void handleGetVersion(ts_channel_s *tsChannel) { static char versionBuffer[32]; chsnprintf(versionBuffer, sizeof(versionBuffer), "rusEFI v%d@%s", getRusEfiVersion(), VCS_VERSION); - sr5SendResponse(tsChannel, mode, (const uint8_t *) versionBuffer, strlen(versionBuffer) + 1); + sr5SendResponse(tsChannel, TS_CRC, (const uint8_t *) versionBuffer, strlen(versionBuffer) + 1); } static void handleGetText(ts_channel_s *tsChannel) { @@ -743,14 +729,14 @@ int TunerStudioBase::handleCrcCommand(ts_channel_s *tsChannel, char *data, int i switch(command) { case TS_OUTPUT_COMMAND: - handleOutputChannelsCommand(tsChannel, TS_CRC, offset, count); + cmdOutputChannels(tsChannel, offset, count); break; case TS_HELLO_COMMAND: tunerStudioDebug("got Query command"); handleQueryCommand(tsChannel, TS_CRC); break; case TS_GET_FIRMWARE_VERSION: - handleGetVersion(tsChannel, TS_CRC); + handleGetVersion(tsChannel); break; #if EFI_FILE_LOGGING || EFI_SIMULATOR case TS_SD_R_COMMAND: diff --git a/firmware/console/binary/tunerstudio.mk b/firmware/console/binary/tunerstudio.mk index eae9121f0b..ab0961b22d 100644 --- a/firmware/console/binary/tunerstudio.mk +++ b/firmware/console/binary/tunerstudio.mk @@ -1,5 +1,6 @@ TUNERSTUDIO_SRC_CPP = $(PROJECT_DIR)/console/binary/tunerstudio_io.cpp \ $(PROJECT_DIR)/console/binary/tunerstudio.cpp \ + $(PROJECT_DIR)/console/binary/tunerstudio_commands.cpp \ $(PROJECT_DIR)/console/binary/bluetooth.cpp \ $(PROJECT_DIR)/console/binary/signature.cpp diff --git a/firmware/console/binary/tunerstudio_commands.cpp b/firmware/console/binary/tunerstudio_commands.cpp new file mode 100644 index 0000000000..913703e535 --- /dev/null +++ b/firmware/console/binary/tunerstudio_commands.cpp @@ -0,0 +1,29 @@ +#include "global.h" + +#include "tunerstudio_impl.h" +#include "tunerstudio.h" +#include "tunerstudio_io.h" + +#include "status_loop.h" + +#if EFI_TUNER_STUDIO + +/** + * @brief 'Output' command sends out a snapshot of current values + * Gauges refresh + */ +void TunerStudio::cmdOutputChannels(ts_channel_s *tsChannel, uint16_t offset, uint16_t count) { + if (offset + count > sizeof(TunerStudioOutputChannels)) { + scheduleMsg(tsLogger, "TS: Version Mismatch? Too much outputs requested %d/%d/%d", offset, count, + sizeof(TunerStudioOutputChannels)); + sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE); + return; + } + + tsState.outputChannelsCommandCounter++; + prepareTunerStudioOutputs(); + // this method is invoked too often to print any debug information + sr5SendResponse(tsChannel, TS_CRC, ((const uint8_t *) &tsOutputChannels) + offset, count); +} + +#endif // EFI_TUNER_STUDIO diff --git a/firmware/console/binary/tunerstudio_impl.h b/firmware/console/binary/tunerstudio_impl.h index 14459d4d11..d5e2a121f0 100644 --- a/firmware/console/binary/tunerstudio_impl.h +++ b/firmware/console/binary/tunerstudio_impl.h @@ -1,8 +1,28 @@ #pragma once +#include + class ts_channel_s; class TunerStudioBase { public: int handleCrcCommand(ts_channel_s *tsChannel, char *data, int incomingPacketSize); + +protected: + virtual void cmdOutputChannels(ts_channel_s *tsChannel, uint16_t offset, uint16_t count) = 0; +}; + +class TunerStudio : public TunerStudioBase { +public: + TunerStudio(Logging* logger) + : tsLogger(logger) + { + } + + void cmdOutputChannels(ts_channel_s *tsChannel, uint16_t offset, uint16_t count) override; + +private: + void sendErrorCode(ts_channel_s* tsChannel, uint8_t code); + + Logging* tsLogger; }; diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 74e7c0db1d..ac3050a250 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -598,7 +598,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ // Low pressure is directly in kpa tsOutputChannels->lowFuelPressure = Sensor::get(SensorType::FuelPressureLow).Value; // High pressure is in bar, aka 100 kpa - tsOutputChannels->highFuelPressure = Sensor::get(SensorType::FuelPressureHigh).Value * 0.01f; + tsOutputChannels->highFuelPressure = KPA2BAR(Sensor::get(SensorType::FuelPressureHigh).Value); // 288 tsOutputChannels->injectionOffset = engine->engineState.injectionOffset; diff --git a/firmware/controllers/engine_cycle/high_pressure_fuel_pump.cpp b/firmware/controllers/engine_cycle/high_pressure_fuel_pump.cpp index 7481cf65de..2d82e50ab5 100644 --- a/firmware/controllers/engine_cycle/high_pressure_fuel_pump.cpp +++ b/firmware/controllers/engine_cycle/high_pressure_fuel_pump.cpp @@ -10,6 +10,7 @@ #include "high_pressure_fuel_pump.h" #include "spark_logic.h" +#include "map.h" #if EFI_HPFP @@ -58,7 +59,11 @@ static void scheduleNextCycle(HpfpActor *actor) { void hpfpPlainPinTurnOn(HpfpActor *current) { RegisteredNamedOutputPin *output = &enginePins.hpfpValve; - output->setHigh(); + int highPressureKpa = Sensor::get(SensorType::FuelPressureHigh).Value; + // very basic control strategy + if (highPressureKpa < BAR2KPA(50)) { + output->setHigh(); + } scheduleNextCycle(current); } diff --git a/firmware/controllers/sensors/map.h b/firmware/controllers/sensors/map.h index 4a433d1139..8c9789bf5a 100644 --- a/firmware/controllers/sensors/map.h +++ b/firmware/controllers/sensors/map.h @@ -31,10 +31,11 @@ float validateMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX); #define PSI2KPA(psi) (KPA_PER_PSI * (psi)) #define BAR2KPA(bar) (100 * (bar)) +#define KPA2BAR(kpa) (0.01f * (kpa)) // PSI (relative to atmosphere) to kPa (relative to vacuum) #define PSI2KPA_RELATIVE(psi) (101.32500411216164f + PSI2KPA(psi)) -#define INHG2KPA(inhg) ((inhg) * 3.386375) -#define KPA2INHG(kpa) ((kpa) / 3.386375) +#define INHG2KPA(inhg) ((inhg) * 3.386375f) +#define KPA2INHG(kpa) ((kpa) / 3.386375f) diff --git a/firmware/controllers/sensors/sensor_type.h b/firmware/controllers/sensors/sensor_type.h index 84d092f551..7676548f52 100644 --- a/firmware/controllers/sensors/sensor_type.h +++ b/firmware/controllers/sensors/sensor_type.h @@ -26,8 +26,8 @@ enum class SensorType : unsigned char { OilPressure, - FuelPressureLow, - FuelPressureHigh, + FuelPressureLow, // in kPa + FuelPressureHigh, // in kPa FuelPressureInjector, // This is the "resolved" position, potentially composited out of the following two