From 0e833c4e355265fa65d42ced66d08b2a77341cf8 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 30 Aug 2016 22:02:21 -0400 Subject: [PATCH] auto-sync --- firmware/console/binary/tunerstudio.cpp | 18 +++++++++++------- firmware/controllers/algo/engine.cpp | 3 +++ firmware/controllers/algo/event_registry.cpp | 1 + firmware/controllers/math/engine_math.cpp | 3 +++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index cb30e17aab..947f141e4f 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -89,8 +89,7 @@ EXTERN_ENGINE ; -// todo: eliminate this magic constant, read from some relevant offset -#define LIVE_TUNING 6200 +extern persistent_config_container_s persistentState; extern short currentPageId; @@ -242,10 +241,15 @@ void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode, tsSendResponse(tsChannel, mode, NULL, 0); } -void yellowMagic(int currentPageId, int offset, int count) { - if (offset > LIVE_TUNING) { +static void onlineTuneBytes(int currentPageId, int offset, int count) { + if (offset > sizeof(engine_configuration_s)) { + int maxSize = sizeof(engine_configuration_s) - offset; + if (count > maxSize) { + warning(CUSTOM_OBD_99, "TS overflow %d %d", offset, count); + return; + } scheduleMsg(&tsLogger, "applying soft change from %d length %d", offset, count); - memcpy(((char*) engineConfiguration) + offset, ((char*) &configWorkingCopy.engineConfiguration) + offset, + memcpy(((char*) &persistentState.persistentConfiguration) + offset, ((char*) &configWorkingCopy) + offset, count); } } @@ -283,7 +287,7 @@ void handleWriteChunkCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint8_t * addr = (uint8_t *) (getWorkingPageAddr(currentPageId) + offset); memcpy(addr, content, count); - yellowMagic(currentPageId, offset, count); + onlineTuneBytes(currentPageId, offset, count); tsSendResponse(tsChannel, mode, NULL, 0); } @@ -339,7 +343,7 @@ void handleWriteValueCommand(ts_channel_s *tsChannel, ts_response_format_e mode, getWorkingPageAddr(currentPageId)[offset] = value; - yellowMagic(currentPageId, offset, 1); + onlineTuneBytes(currentPageId, offset, 1); // scheduleMsg(logger, "va=%d", configWorkingCopy.boardConfiguration.idleValvePin); } diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 7f9647d63c..884bfe343e 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -98,6 +98,9 @@ Engine::Engine(persistent_config_s *config) { isEngineChartEnabled = false; sensorChartMode = SC_OFF; actualLastInjection = 0; + fuelScheduleForThisEngineCycle = NULL; + isAlternatorControlEnabled = false; + wallFuelCorrection = 0; /** * it's important for fixAngle() that engineCycle field never has zero */ diff --git a/firmware/controllers/algo/event_registry.cpp b/firmware/controllers/algo/event_registry.cpp index 78703c8224..36d6215eda 100644 --- a/firmware/controllers/algo/event_registry.cpp +++ b/firmware/controllers/algo/event_registry.cpp @@ -28,6 +28,7 @@ InjectionEvent::InjectionEvent() { isSimultanious = false; isOverlapping = false; injectorIndex = 0; + output = NULL; } event_trigger_position_s::event_trigger_position_s() { diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index a6870a28d2..a629677105 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -40,6 +40,9 @@ extern engine_pins_s enginePins; * @return number of milliseconds in one crank shaft revolution */ floatms_t getCrankshaftRevolutionTimeMs(int rpm) { + if (rpm == 0) { + return NAN; + } return 360 * getOneDegreeTimeMs(rpm); }