diff --git a/.github/workflows/build-firmware.yaml b/.github/workflows/build-firmware.yaml index d3e4f72105..71269b7d2a 100644 --- a/.github/workflows/build-firmware.yaml +++ b/.github/workflows/build-firmware.yaml @@ -124,7 +124,14 @@ jobs: - name: Package Bundle if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} - run: bash misc/jenkins/compile_other_versions/prepare_bundle.sh ${{matrix.build-target}} + run: bash misc/jenkins/compile_other_versions/prepare_bundle.sh ${{matrix.build-target}} ${{matrix.ini-file}} + + - name: Attach console junit results + if: always() + uses: actions/upload-artifact@v2 + with: + name: console ${{matrix.build-target}} junit + path: ./java_console/build/*.txt - name: Upload bundle if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} @@ -186,6 +193,13 @@ jobs: if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} run: bash misc/jenkins/compile_other_versions/prepare_bundle.sh default + - name: Attach console junit results + if: always() + uses: actions/upload-artifact@v2 + with: + name: console primary junit + path: ./java_console/build/*.txt + - name: Upload primary bundle if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} uses: actions/upload-artifact@v2 diff --git a/.github/workflows/build-rusEFI-console.yaml b/.github/workflows/build-rusEFI-console.yaml index 2161b3499c..376ad20c46 100644 --- a/.github/workflows/build-rusEFI-console.yaml +++ b/.github/workflows/build-rusEFI-console.yaml @@ -17,13 +17,20 @@ jobs: - name: Test Compiler run: javac -version + - name: Install Tools + run: sudo apt-get install ncftp + - name: Build console working-directory: ./java_console - run: ant + run: ant server_jar - - name: Upload console junit results + - name: Attach console junit results if: always() uses: actions/upload-artifact@v2 with: name: console junit path: ./java_console/build/*.txt + + - name: Upload rusEFI server + working-directory: ./java_console + run: ./upload_server.sh ${{ secrets.RUSEFI_BUILD_FTP_USER }} ${{ secrets.RUSEFI_BUILD_FTP_PASS }} ${{ secrets.RUSEFI_FTP_SERVER }} diff --git a/.github/workflows/build-tsplugin-body.yaml b/.github/workflows/build-tsplugin-body.yaml index 125b765135..2dc5c9964f 100644 --- a/.github/workflows/build-tsplugin-body.yaml +++ b/.github/workflows/build-tsplugin-body.yaml @@ -26,4 +26,4 @@ jobs: - name: Upload plugin body working-directory: ./java_tools/ts_plugin - run: ./upload.sh ${{ secrets.RUSEFI_BUILD_FTP_USER }} ${{ secrets.RUSEFI_BUILD_FTP_PASS }} ${{ secrets.RUSEFI_FTP_SERVER }} + run: ./upload_plugin.sh ${{ secrets.RUSEFI_BUILD_FTP_USER }} ${{ secrets.RUSEFI_BUILD_FTP_PASS }} ${{ secrets.RUSEFI_FTP_SERVER }} diff --git a/android/app/src/main/java/com/rusefi/app/AndroidSerial.java b/android/app/src/main/java/com/rusefi/app/AndroidSerial.java index fe3f243bf5..f3742b1dfd 100644 --- a/android/app/src/main/java/com/rusefi/app/AndroidSerial.java +++ b/android/app/src/main/java/com/rusefi/app/AndroidSerial.java @@ -34,7 +34,12 @@ public class AndroidSerial implements IoStream { public AndroidSerial(UsbSerialPort usbSerialPort, Logger logger) { this.usbSerialPort = usbSerialPort; - dataBuffer = IncomingDataBuffer.createDataBuffer(this, logger); + dataBuffer = IncomingDataBuffer.createDataBuffer("", this, logger); + } + + @Override + public String getLoggingPrefix() { + return ""; } @Override @@ -45,7 +50,7 @@ public class AndroidSerial implements IoStream { @Override public void setInputListener(DataListener listener) { ByteReader reader = buffer -> usbSerialPort.read(buffer, 5000); - ByteReader.runReaderLoop(listener, reader, Logger.CONSOLE); + ByteReader.runReaderLoop("", listener, reader, Logger.CONSOLE); } @Override diff --git a/android/dependencies.gradle b/android/dependencies.gradle index 8cec38f18c..e22d7c6fc6 100644 --- a/android/dependencies.gradle +++ b/android/dependencies.gradle @@ -1,4 +1,5 @@ ext.libs = [ junit : "junit:junit:4.13", - annotations: "org.jetbrains:annotations:16.0.1" + annotations: "org.jetbrains:annotations:16.0.1", + javaxJson : "javax.json:javax.json-api:1.1.4" ] \ No newline at end of file diff --git a/firmware/config/boards/kinetis/config/controllers/algo/engine_configuration_generated_structures.h b/firmware/config/boards/kinetis/config/controllers/algo/engine_configuration_generated_structures.h index f4dfed30cb..a11a77a25b 100644 --- a/firmware/config/boards/kinetis/config/controllers/algo/engine_configuration_generated_structures.h +++ b/firmware/config/boards/kinetis/config/controllers/algo/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on kinetis_gen_config.bat integration/rusefi_config.txt Wed Jul 15 01:37:11 UTC 2020 +// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on kinetis_gen_config.bat integration/rusefi_config.txt Sun Jul 19 16:19:41 UTC 2020 // by class com.rusefi.output.CHeaderConsumer // begin #pragma once @@ -3530,4 +3530,4 @@ struct persistent_config_s { typedef struct persistent_config_s persistent_config_s; // end -// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on kinetis_gen_config.bat integration/rusefi_config.txt Wed Jul 15 01:37:11 UTC 2020 +// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on kinetis_gen_config.bat integration/rusefi_config.txt Sun Jul 19 16:19:41 UTC 2020 diff --git a/firmware/config/boards/kinetis/config/controllers/algo/rusefi_generated.h b/firmware/config/boards/kinetis/config/controllers/algo/rusefi_generated.h index 7afbbc1e6a..0cd2634110 100644 --- a/firmware/config/boards/kinetis/config/controllers/algo/rusefi_generated.h +++ b/firmware/config/boards/kinetis/config/controllers/algo/rusefi_generated.h @@ -1075,8 +1075,8 @@ #define showHumanReadableWarning_offset 976 #define showSdCardWarning_offset 76 #define SIGNATURE_BOARD kin -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 716980676 +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 1773501990 #define silentTriggerError_offset 1464 #define slowAdcAlpha_offset 2088 #define sparkDwellRpmBins_offset 332 @@ -1344,7 +1344,7 @@ #define ts_show_spi true #define ts_show_trigger_comparator true #define ts_show_tunerstudio_port true -#define TS_SIGNATURE "rusEFI 2020.07.15.kin.716980676" +#define TS_SIGNATURE "rusEFI 2020.07.19.kin.1773501990" #define TS_SINGLE_WRITE_COMMAND 'W' #define tunerStudioSerialSpeed_offset 728 #define twoWireBatchIgnition_offset 1476 diff --git a/firmware/controllers/date_stamp.h b/firmware/controllers/date_stamp.h index d1814ab68b..cbe2827ecf 100644 --- a/firmware/controllers/date_stamp.h +++ b/firmware/controllers/date_stamp.h @@ -1,2 +1,2 @@ #pragma once -#define VCS_DATE 20200715 +#define VCS_DATE 20200719 diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index c581fe24f1..898ed58aad 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -24,6 +24,10 @@ #include "global.h" #include "os_access.h" +#if EFI_PRINTF_FUEL_DETAILS + bool printFuelDebug = false; +#endif // EFI_PRINTF_FUEL_DETAILS + #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT #include "main_trigger_callback.h" @@ -105,12 +109,6 @@ void InjectorOutputPin::open() { printf("overlapping, no need to touch pin %s %d\r\n", name, (int)getTimeNowUs()); #endif /* FUEL_MATH_EXTREME_LOGGING */ } else { -#if FUEL_MATH_EXTREME_LOGGING - const char * w = currentLogicValue == true ? "err" : ""; -// scheduleMsg(&sharedLogger, "^ %spin=%s eventIndex %d %d", w, output->name, -// getRevolutionCounter(), getTimeNowUs()); -#endif /* FUEL_MATH_EXTREME_LOGGING */ - setHigh(); } } @@ -139,7 +137,7 @@ void InjectorOutputPin::close() { overlappingCounter--; if (overlappingCounter > 0) { #if FUEL_MATH_EXTREME_LOGGING - printf("was overlapping, no need to touch pin %s %d\r\n", name, (int)getTimeNowUs()); + printf("was overlapping, no need to touch pin %s %d\r\n", name, (int)getTimeNowUs()); #endif /* FUEL_MATH_EXTREME_LOGGING */ } else { setLow(); @@ -161,7 +159,7 @@ void turnInjectionPinLow(InjectionEvent *event) { event->isScheduled = false; for (int i = 0;ioutputs[i]; - if (output != NULL) { + if (output) { output->close(); } } @@ -172,6 +170,7 @@ void turnInjectionPinLow(InjectionEvent *event) { ENGINE(injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX)); } +// todo: rename to 'scheduleInjectorOpenAndClose'? void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event, int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) { @@ -184,7 +183,12 @@ void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event, size_t injectorIndex = event->outputs[0]->injectorIndex; const floatms_t injectionDuration = ENGINE(wallFuel[injectorIndex]).adjust(ENGINE(injectionDuration) PASS_ENGINE_PARAMETER_SUFFIX); #if EFI_PRINTF_FUEL_DETAILS - printf("fuel injectionDuration=%.2f adjusted=%.2f\t\n", ENGINE(injectionDuration), injectionDuration); + if (printFuelDebug) { + printf("fuel index=%d injectionDuration=%.2fms adjusted=%.2fms\n", + injEventIndex, + ENGINE(injectionDuration), + injectionDuration); + } #endif /*EFI_PRINTF_FUEL_DETAILS */ bool isCranking = ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE); @@ -229,21 +233,26 @@ void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event, if (prevOutputName == outputName && engineConfiguration->injectionMode != IM_SIMULTANEOUS && engineConfiguration->injectionMode != IM_SINGLE_POINT) { - warning(CUSTOM_OBD_SKIPPED_FUEL, "looks like skipped fuel event %d %s", getRevolutionCounter(), outputName); + warning(CUSTOM_OBD_SKIPPED_FUEL, "looks like skipped fuel event revCounter=%d %s", getRevolutionCounter(), outputName); } prevOutputName = outputName; } -#if EFI_UNIT_TEST || EFI_SIMULATOR || EFI_PRINTF_FUEL_DETAILS - InjectorOutputPin *output = event->outputs[0]; - printf("fuelout %s duration %d total=%d\t\n", output->name, (int)durationUs, - (int)MS2US(getCrankshaftRevolutionTimeMs(GET_RPM_VALUE))); +#if EFI_PRINTF_FUEL_DETAILS + if (printFuelDebug) { + InjectorOutputPin *output = event->outputs[0]; + printf("handleFuelInjectionEvent fuelout %s injection_duration %dus engineCycleDuration=%.1fms\t\n", output->name, (int)durationUs, + (int)MS2US(getCrankshaftRevolutionTimeMs(GET_RPM_VALUE)) / 1000.0); + } #endif /*EFI_PRINTF_FUEL_DETAILS */ if (event->isScheduled) { -#if EFI_UNIT_TEST || EFI_SIMULATOR - printf("still used1 %s %d\r\n", output->name, (int)getTimeNowUs()); -#endif /* EFI_UNIT_TEST || EFI_SIMULATOR */ +#if EFI_PRINTF_FUEL_DETAILS + if (printFuelDebug) { + InjectorOutputPin *output = event->outputs[0]; + printf("handleFuelInjectionEvent still used %s now=%.1fms\r\n", output->name, (int)getTimeNowUs() / 1000.0); + } +#endif /*EFI_PRINTF_FUEL_DETAILS */ return; // this InjectionEvent is still needed for an extremely long injection scheduled previously } diff --git a/firmware/controllers/generated/engine_configuration_generated_structures.h b/firmware/controllers/generated/engine_configuration_generated_structures.h index 4306a7efe1..75d323740c 100644 --- a/firmware/controllers/generated/engine_configuration_generated_structures.h +++ b/firmware/controllers/generated/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:00 UTC 2020 +// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:31 UTC 2020 // by class com.rusefi.output.CHeaderConsumer // begin #pragma once @@ -3530,4 +3530,4 @@ struct persistent_config_s { typedef struct persistent_config_s persistent_config_s; // end -// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:00 UTC 2020 +// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:31 UTC 2020 diff --git a/firmware/controllers/generated/fsio_enums_generated.def b/firmware/controllers/generated/fsio_enums_generated.def index db2d4d4a12..0c408da060 100644 --- a/firmware/controllers/generated/fsio_enums_generated.def +++ b/firmware/controllers/generated/fsio_enums_generated.def @@ -1,4 +1,4 @@ -// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:00 UTC 2020 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:31 UTC 2020 // by class com.rusefi.output.FileFsioSettingsConsumer FSIO_SETTING_FANONTEMPERATURE = 1000, diff --git a/firmware/controllers/generated/fsio_getters.def b/firmware/controllers/generated/fsio_getters.def index deda82a1f2..e76d70e27b 100644 --- a/firmware/controllers/generated/fsio_getters.def +++ b/firmware/controllers/generated/fsio_getters.def @@ -1,4 +1,4 @@ -// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:00 UTC 2020 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:31 UTC 2020 // by class com.rusefi.output.FileFsioSettingsConsumer case FSIO_SETTING_FANONTEMPERATURE: diff --git a/firmware/controllers/generated/fsio_names.def b/firmware/controllers/generated/fsio_names.def index 8c05942e09..e6e4374c3c 100644 --- a/firmware/controllers/generated/fsio_names.def +++ b/firmware/controllers/generated/fsio_names.def @@ -1,4 +1,4 @@ -// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:00 UTC 2020 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:31 UTC 2020 // by class com.rusefi.output.FileFsioSettingsConsumer static LENameOrdinalPair lefanOnTemperature(FSIO_SETTING_FANONTEMPERATURE, "cfg_fanOnTemperature"); diff --git a/firmware/controllers/generated/fsio_strings.def b/firmware/controllers/generated/fsio_strings.def index ea70e154b8..4ef82ae79c 100644 --- a/firmware/controllers/generated/fsio_strings.def +++ b/firmware/controllers/generated/fsio_strings.def @@ -1,4 +1,4 @@ -// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:00 UTC 2020 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:31 UTC 2020 // by class com.rusefi.output.FileFsioSettingsConsumer case FSIO_SETTING_FANONTEMPERATURE: diff --git a/firmware/controllers/generated/rusefi_generated.h b/firmware/controllers/generated/rusefi_generated.h index 15cf891dd0..8046404fd0 100644 --- a/firmware/controllers/generated/rusefi_generated.h +++ b/firmware/controllers/generated/rusefi_generated.h @@ -1075,8 +1075,8 @@ #define showHumanReadableWarning_offset 976 #define showSdCardWarning_offset 76 #define SIGNATURE_BOARD all -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 3884096862 +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 2760614588 #define silentTriggerError_offset 1464 #define slowAdcAlpha_offset 2088 #define sparkDwellRpmBins_offset 332 @@ -1344,7 +1344,7 @@ #define ts_show_spi true #define ts_show_trigger_comparator false #define ts_show_tunerstudio_port true -#define TS_SIGNATURE "rusEFI 2020.07.15.all.3884096862" +#define TS_SIGNATURE "rusEFI 2020.07.19.all.2760614588" #define TS_SINGLE_WRITE_COMMAND 'W' #define tunerStudioSerialSpeed_offset 728 #define twoWireBatchIgnition_offset 1476 diff --git a/firmware/controllers/generated/signature_all.h b/firmware/controllers/generated/signature_all.h index 9df142a374..4ed180ecfb 100644 --- a/firmware/controllers/generated/signature_all.h +++ b/firmware/controllers/generated/signature_all.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD all -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 3884096862 -#define TS_SIGNATURE "rusEFI 2020.07.15.all.3884096862" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 2760614588 +#define TS_SIGNATURE "rusEFI 2020.07.19.all.2760614588" diff --git a/firmware/controllers/generated/signature_frankenso_na6.h b/firmware/controllers/generated/signature_frankenso_na6.h index 94dc381bb6..a663d4ba48 100644 --- a/firmware/controllers/generated/signature_frankenso_na6.h +++ b/firmware/controllers/generated/signature_frankenso_na6.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD frankenso_na6 -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 956690877 -#define TS_SIGNATURE "rusEFI 2020.07.15.frankenso_na6.956690877" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 2047659615 +#define TS_SIGNATURE "rusEFI 2020.07.19.frankenso_na6.2047659615" diff --git a/firmware/controllers/generated/signature_kin.h b/firmware/controllers/generated/signature_kin.h index 9207a1fbca..82bdbc029b 100644 --- a/firmware/controllers/generated/signature_kin.h +++ b/firmware/controllers/generated/signature_kin.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD kin -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 716980676 -#define TS_SIGNATURE "rusEFI 2020.07.15.kin.716980676" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 1773501990 +#define TS_SIGNATURE "rusEFI 2020.07.19.kin.1773501990" diff --git a/firmware/controllers/generated/signature_mre_f4.h b/firmware/controllers/generated/signature_mre_f4.h index 7e36590ab0..68b06b0897 100644 --- a/firmware/controllers/generated/signature_mre_f4.h +++ b/firmware/controllers/generated/signature_mre_f4.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD mre_f4 -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 2927381456 -#define TS_SIGNATURE "rusEFI 2020.07.15.mre_f4.2927381456" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 3983897650 +#define TS_SIGNATURE "rusEFI 2020.07.19.mre_f4.3983897650" diff --git a/firmware/controllers/generated/signature_mre_f7.h b/firmware/controllers/generated/signature_mre_f7.h index af5aee3e1b..ffd2dcf731 100644 --- a/firmware/controllers/generated/signature_mre_f7.h +++ b/firmware/controllers/generated/signature_mre_f7.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD mre_f7 -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 2927381456 -#define TS_SIGNATURE "rusEFI 2020.07.15.mre_f7.2927381456" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 3983897650 +#define TS_SIGNATURE "rusEFI 2020.07.19.mre_f7.3983897650" diff --git a/firmware/controllers/generated/signature_prometheus_405.h b/firmware/controllers/generated/signature_prometheus_405.h index 8eb816a4d0..d7ac8ccf95 100644 --- a/firmware/controllers/generated/signature_prometheus_405.h +++ b/firmware/controllers/generated/signature_prometheus_405.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD prometheus_405 -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 312362458 -#define TS_SIGNATURE "rusEFI 2020.07.15.prometheus_405.312362458" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 1368881720 +#define TS_SIGNATURE "rusEFI 2020.07.19.prometheus_405.1368881720" diff --git a/firmware/controllers/generated/signature_prometheus_469.h b/firmware/controllers/generated/signature_prometheus_469.h index 5cfb55af2d..187ab769b8 100644 --- a/firmware/controllers/generated/signature_prometheus_469.h +++ b/firmware/controllers/generated/signature_prometheus_469.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD prometheus_469 -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 312362458 -#define TS_SIGNATURE "rusEFI 2020.07.15.prometheus_469.312362458" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 1368881720 +#define TS_SIGNATURE "rusEFI 2020.07.19.prometheus_469.1368881720" diff --git a/firmware/controllers/generated/signature_proteus_f4.h b/firmware/controllers/generated/signature_proteus_f4.h index 2d6bff82db..460cc5c298 100644 --- a/firmware/controllers/generated/signature_proteus_f4.h +++ b/firmware/controllers/generated/signature_proteus_f4.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD proteus_f4 -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 1779690641 -#define TS_SIGNATURE "rusEFI 2020.07.15.proteus_f4.1779690641" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 689623923 +#define TS_SIGNATURE "rusEFI 2020.07.19.proteus_f4.689623923" diff --git a/firmware/controllers/generated/signature_proteus_f7.h b/firmware/controllers/generated/signature_proteus_f7.h index edebc0f0b9..eb4b908979 100644 --- a/firmware/controllers/generated/signature_proteus_f7.h +++ b/firmware/controllers/generated/signature_proteus_f7.h @@ -3,6 +3,6 @@ // #define SIGNATURE_BOARD proteus_f7 -#define SIGNATURE_DATE 2020.07.15 -#define SIGNATURE_HASH 1779690641 -#define TS_SIGNATURE "rusEFI 2020.07.15.proteus_f7.1779690641" +#define SIGNATURE_DATE 2020.07.19 +#define SIGNATURE_HASH 689623923 +#define TS_SIGNATURE "rusEFI 2020.07.19.proteus_f7.689623923" diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index 1efbf8f304..9518586ec5 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -155,7 +155,7 @@ AirmassResult getSpeedDensityAirmass(float map DECLARE_ENGINE_PARAMETER_SUFFIX) return {}; } #if EFI_PRINTF_FUEL_DETAILS - printf("map=%.2f adjustedMap=%.2f airMass=%.2f\t\n", + printf("getSpeedDensityAirmass map=%.2f adjustedMap=%.2f airMass=%.2f\t\n", map, adjustedMap, engine->engineState.sd.adjustedManifoldAirPressure); #endif /*EFI_PRINTF_FUEL_DETAILS */ diff --git a/firmware/controllers/system/timer/signal_executor_sleep.cpp b/firmware/controllers/system/timer/signal_executor_sleep.cpp index 99478fea69..22a488b126 100644 --- a/firmware/controllers/system/timer/signal_executor_sleep.cpp +++ b/firmware/controllers/system/timer/signal_executor_sleep.cpp @@ -31,6 +31,10 @@ #include "efi_gpio.h" #endif /* EFI_SIMULATOR */ +#if EFI_PRINTF_FUEL_DETAILS +bool printSchedulerDebug = true; +#endif // EFI_PRINTF_FUEL_DETAILS + #if EFI_SIGNAL_EXECUTOR_SLEEP void SleepExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) { @@ -43,14 +47,15 @@ void SleepExecutor::scheduleByTimestampNt(scheduling_s* scheduling, efitick_t ti static void timerCallback(scheduling_s *scheduling) { #if EFI_PRINTF_FUEL_DETAILS - if (scheduling->action.getCallback() == (schfunc_t)&turnInjectionPinLow) { - printf("executing cb=turnInjectionPinLow p=%d sch=%d now=%d\r\n", (int)scheduling->action.getArgument(), (int)scheduling, + if (printSchedulerDebug) { + if (scheduling->action.getCallback() == (schfunc_t)&turnInjectionPinLow) { + printf("executing cb=turnInjectionPinLow p=%d sch=%d now=%d\r\n", (int)scheduling->action.getArgument(), (int)scheduling, (int)getTimeNowUs()); - } else { + } else { // printf("exec cb=%d p=%d\r\n", (int)scheduling->callback, (int)scheduling->param); + } } - -#endif /* EFI_SIMULATOR */ +#endif // EFI_PRINTF_FUEL_DETAILS scheduling->action.execute(); } diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index c5ab037088..ec5f5ce49f 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -108,6 +108,7 @@ EXTERN_ENGINE; #if ! EFI_PROD_CODE bool printTriggerDebug = false; +bool printTriggerTrace = false; float actualSynchGap; #endif /* ! EFI_PROD_CODE */ @@ -281,7 +282,7 @@ static trigger_value_e eventType[6] = { TV_FALL, TV_RISE, TV_FALL, TV_RISE, TV_F (isFirstEvent ? 0 : (nowNt) - toothed_previous_time) #if EFI_UNIT_TEST -#define PRINT_INC_INDEX if (printTriggerDebug) {\ +#define PRINT_INC_INDEX if (printTriggerTrace) {\ printf("nextTriggerEvent index=%d\r\n", currentCycle.current_index); \ } #else @@ -430,7 +431,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg if (needToSkipFall(type) || needToSkipRise(type) || (!considerEventForGap())) { #if EFI_UNIT_TEST - if (printTriggerDebug) { + if (printTriggerTrace) { printf("%s isLessImportant %s now=%d index=%d\r\n", getTrigger_type_e(engineConfiguration->trigger.type), getTrigger_event_e(signal), @@ -447,7 +448,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg } else { #if EFI_UNIT_TEST - if (printTriggerDebug) { + if (printTriggerTrace) { printf("%s event %s %d\r\n", getTrigger_type_e(engineConfiguration->trigger.type), getTrigger_event_e(signal), @@ -462,8 +463,8 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg // scheduleMsg(&logger, "from %.2f to %.2f %d %d", triggerConfig->syncRatioFrom, triggerConfig->syncRatioTo, toothDurations[0], shaftPositionState->toothDurations[1]); // scheduleMsg(&logger, "ratio %.2f", 1.0 * toothDurations[0]/ shaftPositionState->toothDurations[1]); #else - if (printTriggerDebug) { - printf("ratio %.2f: current=%d previous=%d\r\n", 1.0 * toothDurations[0] / toothDurations[1], + if (printTriggerTrace) { + printf("decodeTriggerEvent ratio %.2f: current=%d previous=%d\r\n", 1.0 * toothDurations[0] / toothDurations[1], toothDurations[0], toothDurations[1]); } #endif @@ -559,7 +560,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg } } #else - if (printTriggerDebug) { + if (printTriggerTrace) { float gap = 1.0 * toothDurations[0] / toothDurations[1]; for (int i = 0;igetSize()); @@ -598,8 +599,8 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg isSynchronizationPoint = !shaft_is_synchronized || (currentCycle.current_index >= endOfCycleIndex); #if EFI_UNIT_TEST - if (printTriggerDebug) { - printf("isSynchronizationPoint=%d index=%d size=%d\r\n", + if (printTriggerTrace) { + printf("decodeTriggerEvent decodeTriggerEvent isSynchronizationPoint=%d index=%d size=%d\r\n", isSynchronizationPoint, currentCycle.current_index, triggerShape->getSize()); @@ -609,8 +610,8 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg } #if EFI_UNIT_TEST - if (printTriggerDebug) { - printf("%s isSynchronizationPoint=%d index=%d %s\r\n", + if (printTriggerTrace) { + printf("decodeTriggerEvent %s isSynchronizationPoint=%d index=%d %s\r\n", getTrigger_type_e(engineConfiguration->trigger.type), isSynchronizationPoint, currentCycle.current_index, getTrigger_event_e(signal)); diff --git a/firmware/controllers/trigger/trigger_simulator.cpp b/firmware/controllers/trigger/trigger_simulator.cpp index a21b89a726..a6a1680bd6 100644 --- a/firmware/controllers/trigger/trigger_simulator.cpp +++ b/firmware/controllers/trigger/trigger_simulator.cpp @@ -52,7 +52,7 @@ void TriggerStimulatorHelper::feedSimulatedEvent(const TriggerStateCallback trig // pin_state_t new3rdWheelState = multiChannelStateSequence->getChannelState(2, stateIndex); if (printTriggerDebug) { - printf("feedSimulatedEvent: %d>%d primary %d>%d secondary %d>%d\r\n", prevIndex, stateIndex, primaryWheelState, newPrimaryWheelState, + printf("TriggerStimulator: simulatedEvent: %d>%d primary %d>%d secondary %d>%d\r\n", prevIndex, stateIndex, primaryWheelState, newPrimaryWheelState, secondaryWheelState, newSecondaryWheelState ); } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index e1af853833..5dcf9c94ec 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1121,7 +1121,7 @@ float[MAP_ACCEL_TAPER] mapAccelTaperMult;;"mult", 1, 0, 0.0, 300, output_pin_e dizzySparkOutputPin;+This implementation makes a pulse every time one of the coils is charged, using coil dwell for pulse width. See also tachOutputPin pin_output_mode_e dizzySparkOutputPinMode; - int crankingIACposition;+This is the IAC position during cranking, some engines start better if given more air during cranking to improve cylinder filling.;"percent", 1, 0, -100.0, 100, + int crankingIACposition;+This is the IAC position during cranking, some engines start better if given more air during cranking to improve cylinder filling.;"percent", 1, 0, -100.0, 100, 0 float tChargeMinRpmMinTps;;"mult", 1, 0, 0, 3, 4 float tChargeMinRpmMaxTps;;"mult", 1, 0, 0, 3, 4 float tChargeMaxRpmMinTps;;"mult", 1, 0, 0, 3, 4 diff --git a/firmware/svnversion.h b/firmware/svnversion.h index e82c704e8e..e81ad4d022 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,12 +1,12 @@ // This file was generated by Version2Header -// Sat Jul 11 22:38:12 EDT 2020 +// Sun Jul 19 01:43:06 EDT 2020 #ifndef GIT_HASH -#define GIT_HASH "f38365808f8f1e5d579ed6f559acd0ae828d96ab" +#define GIT_HASH "5e39d1ff305f1d5e2fe176e82bf2e1860723af98" #endif #ifndef VCS_VERSION -#define VCS_VERSION "24224" +#define VCS_VERSION "24365" #endif diff --git a/firmware/tunerstudio/generated/cache.zip b/firmware/tunerstudio/generated/cache.zip index 3811e02aff..70bddf0f72 100644 Binary files a/firmware/tunerstudio/generated/cache.zip and b/firmware/tunerstudio/generated/cache.zip differ diff --git a/firmware/tunerstudio/generated/rusefi.ini b/firmware/tunerstudio/generated/rusefi.ini index 9ef8291ce9..149e790070 100644 --- a/firmware/tunerstudio/generated/rusefi.ini +++ b/firmware/tunerstudio/generated/rusefi.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.all.3884096862" + signature = "rusEFI 2020.07.19.all.2760614588" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.all.3884096862" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.all.2760614588" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:00 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:31 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE", "INVALID", "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6","PE7","PE8","PE9","PE10","PE11","PE12","PE13","PE14","PE15", "PF0","PF1","PF2","PF3","PF4","PF5","PF6","PF7","PF8","PF9","PF10","PF11","PF12","PF13","PF14","PF15", "PG0","PG1","PG2","PG3","PG4","PG5","PG6","PG7","PG8","PG9","PG10","PG11","PG12","PG13","PG14","PG15", "PH0","PH1","PH2","PH3","PH4","PH5","PH6","PH7","PH8","PH9","PH10","PH11","PH12","PH13","PH14","PH15","TLE6240_1", "TLE6240_2", "TLE6240_3", "TLE6240_4", "TLE6240_5", "TLE6240_6", "TLE6240_7", "TLE6240_8", "TLE6240_9", "TLE6240_10", "TLE6240_11", "TLE6240_12", "TLE6240_13", "TLE6240_14", "TLE6240_15", "TLE6240_16", "MC33972_1", "MC33972_2", "MC33972_3", "MC33972_4", "MC33972_5", "MC33972_6", "MC33972_7", "MC33972_8", "MC33972_9", "MC33972_10", "MC33972_11", "MC33972_12", "MC33972_13", "MC33972_14", "MC33972_15", "MC33972_16", "MC33972_17", "MC33972_18", "MC33972_19", "MC33972_20", "MC33972_21", "MC33972_22", "TLE8888_1", "TLE8888_2", "TLE8888_3", "TLE8888_4", "TLE8888_5", "TLE8888_6", "TLE8888_7", "TLE8888_8", "TLE8888_9", "TLE8888_10", "TLE8888_11", "TLE8888_12", "TLE8888_13", "TLE8888_14", "TLE8888_15", "TLE8888_16", "TLE8888_17", "TLE8888_18", "TLE8888_19", "TLE8888_20", "TLE8888_21", "TLE8888_22", "TLE8888_23", "TLE8888_24", "TLE8888_25", "TLE8888_26", "TLE8888_27", "TLE8888_28", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini b/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini index 9e21cfc7e4..685ca88d84 100644 --- a/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini +++ b/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.frankenso_na6.956690877" + signature = "rusEFI 2020.07.19.frankenso_na6.2047659615" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.frankenso_na6.956690877" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.frankenso_na6.2047659615" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:05 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:35 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Injector 3Z","Injector 3Y","Injector 3W","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Coil 1H","INVALID","Coil 1F","INVALID","INVALID","INVALID","Injector 2M","INVALID","INVALID","INVALID","INVALID","INVALID","Injector 3U","INVALID","Injector 3X","INVALID","Injector 2N","Coil 1O","Coil 1P","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Injector 3V","Injector 3S","Injector 3T","Injector 2O","Injector 2P","INVALID","Coil 1L","INVALID","Coil 1I","INVALID","Coil 1M","INVALID","Coil 1G","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/firmware/tunerstudio/generated/rusefi_kinetis.ini b/firmware/tunerstudio/generated/rusefi_kinetis.ini index acb0237339..b6dff6b010 100644 --- a/firmware/tunerstudio/generated/rusefi_kinetis.ini +++ b/firmware/tunerstudio/generated/rusefi_kinetis.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.kin.716980676" + signature = "rusEFI 2020.07.19.kin.1773501990" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.kin.716980676" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.kin.1773501990" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on kinetis_gen_config.bat integration/rusefi_config.txt Wed Jul 15 01:37:11 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on kinetis_gen_config.bat integration/rusefi_config.txt Sun Jul 19 16:19:41 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE", "INVALID", "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "N/A", "N/A", "PA10", "PA11", "PA12", "PA13", "N/A", "N/A", "N/A", "N/A", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "N/A", "N/A", "N/A", "N/A", "PB12", "PB13", "N/A", "N/A", "N/A", "N/A", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "N/A", "N/A", "N/A", "N/A", "PC14", "PC15", "PC16", "PC17", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "PD15", "PD16", "N/A", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9", "PE10", "PE11", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "TLE6240_1", "TLE6240_2", "TLE6240_3", "TLE6240_4", "TLE6240_5", "TLE6240_6", "TLE6240_7", "TLE6240_8", "TLE6240_9", "TLE6240_10", "TLE6240_11", "TLE6240_12", "TLE6240_13", "TLE6240_14", "TLE6240_15", "TLE6240_16", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/firmware/tunerstudio/generated/rusefi_mre_f4.ini b/firmware/tunerstudio/generated/rusefi_mre_f4.ini index f26f8b356e..c243dada05 100644 --- a/firmware/tunerstudio/generated/rusefi_mre_f4.ini +++ b/firmware/tunerstudio/generated/rusefi_mre_f4.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.mre_f4.2927381456" + signature = "rusEFI 2020.07.19.mre_f4.3983897650" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.mre_f4.2927381456" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.mre_f4.3983897650" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:04 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:34 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE","INVALID","INVALID","INVALID","INVALID","INVALID","AUX AV10 reuse","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","AUX J2 PA15","AUX AV8 reuse","AUX AV9 reuse","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","AUX J2 PB8","AUX J2 PB9","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","AUX AV6 reuse","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","AUX J2 PC12","INVALID","INVALID","INVALID","INVALID","12 - Ignition 4","11 - Ignition 3","10 - Ignition 2","9 - Ignition 1","INVALID","13 - GP Out 6","14 - GP Out 5","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","35 - GP Out 1","7 - Lowside 1","3 - Lowside 2","42 - Injector 4","41 - Injector 3","38 - Injector 2","37 - Injector 1","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","34 - GP Out 2","33 - GP Out 3","43 - GP Out 4","INVALID","INVALID","INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/firmware/tunerstudio/generated/rusefi_mre_f7.ini b/firmware/tunerstudio/generated/rusefi_mre_f7.ini index f65f9ae752..0e7117ce5d 100644 --- a/firmware/tunerstudio/generated/rusefi_mre_f7.ini +++ b/firmware/tunerstudio/generated/rusefi_mre_f7.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.mre_f7.2927381456" + signature = "rusEFI 2020.07.19.mre_f7.3983897650" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.mre_f7.2927381456" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.mre_f7.3983897650" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:03 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:33 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE","INVALID","INVALID","INVALID","INVALID","INVALID","AUX AV10 reuse","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","AUX J2 PA15","AUX AV8 reuse","AUX AV9 reuse","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","AUX J2 PB8","AUX J2 PB9","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","AUX AV6 reuse","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","AUX J2 PC12","INVALID","INVALID","INVALID","INVALID","12 - Ignition 4","11 - Ignition 3","10 - Ignition 2","9 - Ignition 1","INVALID","13 - GP Out 6","14 - GP Out 5","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","35 - GP Out 1","7 - Lowside 1","3 - Lowside 2","42 - Injector 4","41 - Injector 3","38 - Injector 2","37 - Injector 1","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","34 - GP Out 2","33 - GP Out 3","43 - GP Out 4","INVALID","INVALID","INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/firmware/tunerstudio/generated/rusefi_prometheus_405.ini b/firmware/tunerstudio/generated/rusefi_prometheus_405.ini index ee8642a9bb..aa5faf48e1 100644 --- a/firmware/tunerstudio/generated/rusefi_prometheus_405.ini +++ b/firmware/tunerstudio/generated/rusefi_prometheus_405.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.prometheus_405.312362458" + signature = "rusEFI 2020.07.19.prometheus_405.1368881720" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.prometheus_405.312362458" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.prometheus_405.1368881720" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:07 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:38 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Injector 3Z","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/firmware/tunerstudio/generated/rusefi_prometheus_469.ini b/firmware/tunerstudio/generated/rusefi_prometheus_469.ini index 891baebf77..30fd444986 100644 --- a/firmware/tunerstudio/generated/rusefi_prometheus_469.ini +++ b/firmware/tunerstudio/generated/rusefi_prometheus_469.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.prometheus_469.312362458" + signature = "rusEFI 2020.07.19.prometheus_469.1368881720" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.prometheus_469.312362458" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.prometheus_469.1368881720" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:06 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:36 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Injector 3Z","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/firmware/tunerstudio/generated/rusefi_proteus_f4.ini b/firmware/tunerstudio/generated/rusefi_proteus_f4.ini index 0505c87579..d62e2d3e02 100644 --- a/firmware/tunerstudio/generated/rusefi_proteus_f4.ini +++ b/firmware/tunerstudio/generated/rusefi_proteus_f4.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.proteus_f4.1779690641" + signature = "rusEFI 2020.07.19.proteus_f4.689623923" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.proteus_f4.1779690641" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.proteus_f4.689623923" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:10 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:40 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Highside 2","Highside 1","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Lowside 8","Lowside 9","Lowside 10","Lowside 11","Lowside 12","Lowside 13","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Ign 5","Ign 4","Ign 3","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Ign 2","Ign 1","INVALID","INVALID","Lowside 1","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Highside 4","Highside 3","Lowside 14","Lowside 15","Lowside 16","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Ign 12","Ign 11","Ign 10","Ign 9","Ign 8","Ign 7","Ign 6","Lowside 2","Lowside 3","Lowside 4","Lowside 5","Lowside 6","Lowside 7","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/firmware/tunerstudio/generated/rusefi_proteus_f7.ini b/firmware/tunerstudio/generated/rusefi_proteus_f7.ini index f4a426216e..239aa8a006 100644 --- a/firmware/tunerstudio/generated/rusefi_proteus_f7.ini +++ b/firmware/tunerstudio/generated/rusefi_proteus_f7.ini @@ -45,12 +45,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.07.15.proteus_f7.1779690641" + signature = "rusEFI 2020.07.19.proteus_f7.689623923" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.07.15.proteus_f7.1779690641" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.07.19.proteus_f7.689623923" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -88,7 +88,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:09 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:39 UTC 2020 pageSize = 20000 page = 1 @@ -854,7 +854,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:1], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Highside 2","Highside 1","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Lowside 8","Lowside 9","Lowside 10","Lowside 11","Lowside 12","Lowside 13","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Ign 5","Ign 4","Ign 3","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Ign 2","Ign 1","INVALID","INVALID","Lowside 1","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Highside 4","Highside 3","Lowside 14","Lowside 15","Lowside 16","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","Ign 12","Ign 11","Ign 10","Ign 9","Ign 8","Ign 7","Ign 6","Lowside 2","Lowside 3","Lowside 4","Lowside 5","Lowside 6","Lowside 7","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:1], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/java_console/.idea/runConfigurations/TuneReadWriteTest_testCompareBinaryToTSTune.xml b/java_console/.idea/runConfigurations/TuneReadWriteTest_testCompareBinaryToTSTune.xml new file mode 100644 index 0000000000..dfa3bbb3de --- /dev/null +++ b/java_console/.idea/runConfigurations/TuneReadWriteTest_testCompareBinaryToTSTune.xml @@ -0,0 +1,21 @@ + + + + + + + + + + \ No newline at end of file diff --git a/java_console/.idea/runConfigurations/TuneReadWriteTest_testWriteAndReadTSTune.xml b/java_console/.idea/runConfigurations/TuneReadWriteTest_testWriteAndReadTSTune.xml new file mode 100644 index 0000000000..d52300921a --- /dev/null +++ b/java_console/.idea/runConfigurations/TuneReadWriteTest_testWriteAndReadTSTune.xml @@ -0,0 +1,21 @@ + + + + + + + + + + \ No newline at end of file diff --git a/java_console/autoupdate/src/com/rusefi/autoupdate/Autoupdate.java b/java_console/autoupdate/src/com/rusefi/autoupdate/Autoupdate.java index dbc997de98..eee86023dd 100644 --- a/java_console/autoupdate/src/com/rusefi/autoupdate/Autoupdate.java +++ b/java_console/autoupdate/src/com/rusefi/autoupdate/Autoupdate.java @@ -12,6 +12,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URLClassLoader; +import java.util.Arrays; import java.util.Date; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; @@ -42,7 +43,7 @@ public class Autoupdate { private static void startConsole(String[] args) { try { // we want to make sure that files are available to write so we use reflection to get lazy class initialization - System.out.println("Running rusEFI console"); + System.out.println("Running rusEFI console with " + Arrays.toString(args)); // since we are overriding file we cannot just use static java classpath while launching URLClassLoader jarClassLoader = AutoupdateUtil.getClassLoaderByJar(RUSEFI_CONSOLE_JAR); diff --git a/java_console/bin/broadcast.sh b/java_console/bin/broadcast.sh new file mode 100755 index 0000000000..d28ab62499 --- /dev/null +++ b/java_console/bin/broadcast.sh @@ -0,0 +1 @@ +java -jar console/rusefi_console.jar network_connector \ No newline at end of file diff --git a/java_console/bin/help.sh b/java_console/bin/help.sh new file mode 100644 index 0000000000..a4e0570083 --- /dev/null +++ b/java_console/bin/help.sh @@ -0,0 +1 @@ +java -jar console/rusefi_console.jar help \ No newline at end of file diff --git a/java_console/bin/set_auth_token.sh b/java_console/bin/set_auth_token.sh new file mode 100644 index 0000000000..f5f6a9fbfd --- /dev/null +++ b/java_console/bin/set_auth_token.sh @@ -0,0 +1 @@ +java -jar console/rusefi_console.jar set_auth_token $1 \ No newline at end of file diff --git a/java_console/bin/switch_to_dfu.sh b/java_console/bin/switch_to_dfu.sh new file mode 100755 index 0000000000..45c9727db2 --- /dev/null +++ b/java_console/bin/switch_to_dfu.sh @@ -0,0 +1 @@ +java -jar console/rusefi_console.jar reboot_dfu \ No newline at end of file diff --git a/java_console/bin/update_bundle.sh b/java_console/bin/update_bundle.sh new file mode 100644 index 0000000000..6a70d573ba --- /dev/null +++ b/java_console/bin/update_bundle.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cd console +java -jar rusefi_autoupdate.jar version \ No newline at end of file diff --git a/java_console/build.xml b/java_console/build.xml index ecda8bacd1..8b321d3275 100644 --- a/java_console/build.xml +++ b/java_console/build.xml @@ -1,6 +1,7 @@ + @@ -95,6 +96,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/java_console/certificate/readme.md b/java_console/certificate/readme.md new file mode 100644 index 0000000000..fc2bc7b949 --- /dev/null +++ b/java_console/certificate/readme.md @@ -0,0 +1,9 @@ + +Test certificate generated with the following command + +``keytool -genkey -keyalg RSA -alias selfsigned -keystore test.jks -storepass password -validity 360 -keysize 2048`` + + +Converted using + +keytool -importkeystore -srckeystore test.jks -destkeystore test_pkcs12.jks -deststoretype pkcs12 \ No newline at end of file diff --git a/java_console/certificate/test.jks b/java_console/certificate/test.jks new file mode 100644 index 0000000000..d89ae400be Binary files /dev/null and b/java_console/certificate/test.jks differ diff --git a/java_console/certificate/test_pkcs12.jks b/java_console/certificate/test_pkcs12.jks new file mode 100644 index 0000000000..d470421a08 Binary files /dev/null and b/java_console/certificate/test_pkcs12.jks differ diff --git a/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java b/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java index 19f1771d62..debd001b61 100644 --- a/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java +++ b/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java @@ -16,7 +16,7 @@ public class IniFileModel { public static final String INI_FILE_PATH = System.getProperty("ini_file_path", ".."); private static final String SECTION_PAGE = "page"; private static final String FIELD_TYPE_SCALAR = "scalar"; - private static final String FIELD_TYPE_STRING = "string"; + public static final String FIELD_TYPE_STRING = "string"; private static final String FIELD_TYPE_ARRAY = "array"; private static final String FIELD_TYPE_BITS = "bits"; diff --git a/java_console/inifile/src/main/java/com/opensr5/ini/field/ArrayIniField.java b/java_console/inifile/src/main/java/com/opensr5/ini/field/ArrayIniField.java index f78c45c848..f1a7e95832 100644 --- a/java_console/inifile/src/main/java/com/opensr5/ini/field/ArrayIniField.java +++ b/java_console/inifile/src/main/java/com/opensr5/ini/field/ArrayIniField.java @@ -13,13 +13,15 @@ public class ArrayIniField extends IniField { private final int cols; private final int rows; private final double multiplier; + private final String digits; - public ArrayIniField(String name, int offset, FieldType type, int cols, int rows, String unit, double multiplier) { + public ArrayIniField(String name, int offset, FieldType type, int cols, int rows, String unit, double multiplier, String digits) { super(name, offset); this.type = type; this.cols = cols; this.rows = rows; this.multiplier = multiplier; + this.digits = digits; } public FieldType getType() { @@ -34,6 +36,11 @@ public class ArrayIniField extends IniField { return rows; } + @Override + public String getDigits() { + return digits; + } + @Override public int getSize() { return type.getStorageSize() * cols * rows; @@ -90,6 +97,7 @@ public class ArrayIniField extends IniField { int offset = Integer.parseInt(list.get(3)); String size = list.get(4); String unit = list.get(5); + String digits = list.get(10); double multiplier = Double.parseDouble(list.get(6)); size = size.replaceAll("[\\]\\[x]", " ").trim(); @@ -106,6 +114,6 @@ public class ArrayIniField extends IniField { throw new IllegalStateException("Unexpected " + size); } - return new ArrayIniField(name, offset, type, cols, rows, unit, multiplier); + return new ArrayIniField(name, offset, type, cols, rows, unit, multiplier, digits); } } diff --git a/java_console/inifile/src/main/java/com/opensr5/ini/field/IniField.java b/java_console/inifile/src/main/java/com/opensr5/ini/field/IniField.java index f63d8fe58b..031bf93c3c 100644 --- a/java_console/inifile/src/main/java/com/opensr5/ini/field/IniField.java +++ b/java_console/inifile/src/main/java/com/opensr5/ini/field/IniField.java @@ -20,6 +20,10 @@ public abstract class IniField { return null; } + public String getDigits() { + return null; + } + public int getOffset() { return offset; } diff --git a/java_console/inifile/src/main/java/com/opensr5/ini/field/ScalarIniField.java b/java_console/inifile/src/main/java/com/opensr5/ini/field/ScalarIniField.java index e03bd15e79..d4228f8b6a 100644 --- a/java_console/inifile/src/main/java/com/opensr5/ini/field/ScalarIniField.java +++ b/java_console/inifile/src/main/java/com/opensr5/ini/field/ScalarIniField.java @@ -13,17 +13,24 @@ import static com.rusefi.config.FieldType.*; public class ScalarIniField extends IniField { private final String unit; private final FieldType type; + private final String digits; private final double multiplier; - public ScalarIniField(String name, int offset, String unit, FieldType type, double multiplier) { + public ScalarIniField(String name, int offset, String unit, FieldType type, double multiplier, String digits) { super(name, offset); this.unit = unit; this.type = type; + this.digits = digits; if (multiplier == 0) throw new IllegalArgumentException("Multiplier should not be zero"); this.multiplier = multiplier; } + @Override + public String getDigits() { + return digits; + } + @Override public String getUnits() { return unit; @@ -86,10 +93,11 @@ public class ScalarIniField extends IniField { String name = list.get(0); FieldType type = FieldType.parseTs(list.get(2)); int offset = Integer.parseInt(list.get(3)); + String digits = list.get(9); String unit = list.get(4); double multiplier = Double.parseDouble(list.get(5)); - return new ScalarIniField(name, offset, unit, type, multiplier); + return new ScalarIniField(name, offset, unit, type, multiplier, digits); } } diff --git a/java_console/inifile/src/main/java/com/rusefi/config/Field.java b/java_console/inifile/src/main/java/com/rusefi/config/Field.java index 916fdf8cfd..5aff9e9a12 100644 --- a/java_console/inifile/src/main/java/com/rusefi/config/Field.java +++ b/java_console/inifile/src/main/java/com/rusefi/config/Field.java @@ -18,6 +18,7 @@ public class Field { private final String name; private final int offset; + private final int stringSize; private final FieldType type; private final int bitOffset; private final String[] options; @@ -36,8 +37,13 @@ public class Field { } public Field(String name, int offset, FieldType type, int bitOffset, String[] options) { + this(name, offset, 0, type, bitOffset, options); + } + + public Field(String name, int offset, int stringSize, FieldType type, int bitOffset, String... options) { this.name = name; this.offset = offset; + this.stringSize = stringSize; this.type = type; this.bitOffset = bitOffset; this.options = options; @@ -192,8 +198,21 @@ public class Field { return field; } + public static Field create(String name, int offset, int stringSize, FieldType type) { + return new Field(name, offset, stringSize, type, 0); + } + public static Field create(String name, int offset, FieldType type) { Field field = new Field(name, offset, type); return field; } + + public String getStringValue(ConfigurationImage image) { + if (type != STRING) + throw new IllegalStateException("Not a string parameter " + name); + ByteBuffer bb = image.getByteBuffer(offset, stringSize); + byte[] bytes = new byte[stringSize]; + bb.get(bytes); + return new String(bytes).trim(); + } } \ No newline at end of file diff --git a/java_console/inifile/src/main/java/com/rusefi/config/FieldType.java b/java_console/inifile/src/main/java/com/rusefi/config/FieldType.java index 4c7630e53e..9f76827dca 100644 --- a/java_console/inifile/src/main/java/com/rusefi/config/FieldType.java +++ b/java_console/inifile/src/main/java/com/rusefi/config/FieldType.java @@ -11,7 +11,9 @@ public enum FieldType { UINT16(2), BIT(/*bits are stored in 4 byte packs */4), - FLOAT(4); + FLOAT(4), + + STRING(0); // todo: this is used for text protocol parsing - constant should be reused between firmware and console public static final String INT_TYPE_STRING = "int"; @@ -70,6 +72,8 @@ public enum FieldType { } public int getStorageSize() { + if (this == STRING) + throw new UnsupportedOperationException("storage size is unclear on " + this); return storageSize; } } \ No newline at end of file diff --git a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Bibliography.java b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Bibliography.java index 1c9f404d29..58853152b4 100644 --- a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Bibliography.java +++ b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Bibliography.java @@ -3,6 +3,8 @@ package com.rusefi.tune.xml; import javax.xml.bind.annotation.XmlAttribute; public class Bibliography { + private String tuneComment = null; + @XmlAttribute public String getAuthor() { return "rusEFI"; @@ -10,7 +12,11 @@ public class Bibliography { @XmlAttribute public String getTuneComment() { - return "comments"; + return tuneComment; + } + + public void setTuneComment(String tuneComment) { + this.tuneComment = tuneComment; } @XmlAttribute diff --git a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Constant.java b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Constant.java index aa0f1c1a71..78671c9a41 100644 --- a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Constant.java +++ b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Constant.java @@ -7,14 +7,16 @@ public class Constant { private String name; private String units; private String value; + private String digits; public Constant() { } - public Constant(String name, String units, String value) { + public Constant(String name, String units, String value, String digits) { this.name = name; this.units = units; this.value = value; + this.digits = digits; } @XmlAttribute @@ -32,6 +34,15 @@ public class Constant { return value; } + @XmlAttribute + public String getDigits() { + return digits; + } + + public void setDigits(String digits) { + this.digits = digits; + } + public void setName(String name) { this.name = name; } diff --git a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Msq.java b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Msq.java index 0b5e94f72f..778a762e81 100644 --- a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Msq.java +++ b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Msq.java @@ -18,7 +18,9 @@ public class Msq { public List page = new ArrayList<>(); - private final VersionInfo versionInfo; + public final VersionInfo versionInfo; + + public Bibliography bibliography = new Bibliography(); public Msq() { versionInfo = new VersionInfo("rusEFI+2020"); @@ -36,7 +38,7 @@ public class Msq { @NotNull public static Msq create(int totalConfigSize, String tsSignature) { Msq tune = new Msq(); - tune.versionInfo.setTsSignature(tsSignature); + tune.versionInfo.setSignature(tsSignature); tune.page.add(new Page(null, null)); tune.page.add(new Page(0, totalConfigSize)); return tune; @@ -65,6 +67,8 @@ public class Msq { } public void writeXmlFile(String outputXmlFileName) throws JAXBException, IOException { + Objects.requireNonNull(versionInfo, "versionInfo"); + versionInfo.validate(); XmlUtil.writeXml(this, Msq.class, outputXmlFileName); } @@ -76,17 +80,7 @@ public class Msq { System.out.println("Msq: No page"); return; } - page.constant.add(new Constant(field.getName(), field.getUnits(), value)); - } - - @XmlElement - public Bibliography getBibliography() { - return new Bibliography(); - } - - @XmlElement - public VersionInfo getVersionInfo() { - return versionInfo; + page.constant.add(new Constant(field.getName(), field.getUnits(), value, field.getDigits())); } public Page findPage() { @@ -108,4 +102,8 @@ public class Msq { public UserComments getUserComments() { return new UserComments(); } + + public VersionInfo getVersionInfo() { + return versionInfo; + } } diff --git a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Page.java b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Page.java index 112f6d7690..d829a41b7e 100644 --- a/java_console/inifile/src/main/java/com/rusefi/tune/xml/Page.java +++ b/java_console/inifile/src/main/java/com/rusefi/tune/xml/Page.java @@ -37,6 +37,15 @@ public class Page { this.size = size; } + public Constant findParameter(String name) { + for (Constant parameter : constant) { + if (parameter.getName().equals(name)) { + return parameter; + } + } + return null; + } + @Override public String toString() { return "Page{" + diff --git a/java_console/inifile/src/main/java/com/rusefi/tune/xml/VersionInfo.java b/java_console/inifile/src/main/java/com/rusefi/tune/xml/VersionInfo.java index acbad9ae14..e0d710090c 100644 --- a/java_console/inifile/src/main/java/com/rusefi/tune/xml/VersionInfo.java +++ b/java_console/inifile/src/main/java/com/rusefi/tune/xml/VersionInfo.java @@ -1,10 +1,11 @@ package com.rusefi.tune.xml; import javax.xml.bind.annotation.XmlAttribute; +import java.util.Objects; public class VersionInfo { private String firmwareInfo; - private String tsSignature; + private String signature; public VersionInfo() { } @@ -30,14 +31,18 @@ public class VersionInfo { @XmlAttribute public String getSignature() { - return tsSignature; + return signature; } public void setFirmwareInfo(String firmwareInfo) { this.firmwareInfo = firmwareInfo; } - public void setTsSignature(String tsSignature) { - this.tsSignature = tsSignature; + public void setSignature(String signature) { + this.signature = signature; + } + + public void validate() { + Objects.requireNonNull(signature, "signature"); } } diff --git a/java_console/inifile/src/main/java/com/rusefi/xml/XmlUtil.java b/java_console/inifile/src/main/java/com/rusefi/xml/XmlUtil.java index e4818a8fdb..77a4e227b3 100644 --- a/java_console/inifile/src/main/java/com/rusefi/xml/XmlUtil.java +++ b/java_console/inifile/src/main/java/com/rusefi/xml/XmlUtil.java @@ -25,8 +25,10 @@ public class XmlUtil { System.out.println(xmlWriter.toString()); System.out.println("Writing " + fileName); - marshaller.marshal(instance, new FileWriter(fileName)); + FileWriter writer = new FileWriter(fileName); + marshaller.marshal(instance, writer); System.out.println("Marshalling finished " + fileName); + writer.close(); } public static T readModel(Class modelClass, String fileName) throws Exception { diff --git a/java_console/io/build.gradle b/java_console/io/build.gradle index 4389fdd5f5..5d99b5546f 100644 --- a/java_console/io/build.gradle +++ b/java_console/io/build.gradle @@ -9,6 +9,7 @@ configurations { } dependencies { + implementation libs.javaxJson implementation project(':inifile') implementation project(':models') implementation project(':logging-api') diff --git a/java_console/io/io.iml b/java_console/io/io.iml index e1018db598..c94a8e44b5 100644 --- a/java_console/io/io.iml +++ b/java_console/io/io.iml @@ -10,10 +10,10 @@ - + - + - + \ No newline at end of file diff --git a/java_console/io/src/main/java/com/opensr5/io/WriteStream.java b/java_console/io/src/main/java/com/opensr5/io/WriteStream.java index 4190fa18ab..fa5e27f26f 100644 --- a/java_console/io/src/main/java/com/opensr5/io/WriteStream.java +++ b/java_console/io/src/main/java/com/opensr5/io/WriteStream.java @@ -16,6 +16,14 @@ public interface WriteStream { write(new byte[]{value}); } + default void writeShort(int v) throws IOException { + byte[] array = new byte[2]; + + array[0] = (byte) ((v >>> 8) & 0xFF); + array[1] = (byte) ((v >>> 0) & 0xFF); + write(array); + } + default void writeInt(int v) throws IOException { byte[] array = new byte[4]; diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java index 4afdb431aa..c089b90a45 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -75,11 +75,33 @@ public class BinaryProtocol implements BinaryProtocolCommands { /** * Composite logging turns off after 10 seconds of RPM above 300 */ - private boolean needCompositeLogger = true; + private boolean needCompositeLogger; private boolean isCompositeLoggerEnabled; private long lastLowRpmTime = System.currentTimeMillis(); private List compositeLogs = new ArrayList<>(); + public static boolean DISABLE_LOCAL_CACHE; + + public static String findCommand(byte command) { + switch (command) { + case Fields.TS_CRC_CHECK_COMMAND: + return "CRC_CHECK"; + case Fields.TS_BURN_COMMAND: + return "BURN"; + case Fields.TS_HELLO_COMMAND: + return "HELLO"; + case Fields.TS_READ_COMMAND: + return "READ"; + case Fields.TS_GET_FIRMWARE_VERSION: + return "GET_FW_VERSION"; + case Fields.TS_CHUNK_WRITE_COMMAND: + return "WRITE_CHUNK"; + case Fields.TS_OUTPUT_COMMAND: + return "TS_OUTPUT_COMMAND"; + default: + return "command " + (char) + command + "/" + command; + } + } private void createCompositesIfNeeded() { if (!compositeLogs.isEmpty()) @@ -91,6 +113,10 @@ public class BinaryProtocol implements BinaryProtocolCommands { )); } + public IoStream getStream() { + return stream; + } + public boolean isClosed; public CommunicationLoggingListener communicationLoggingListener = CommunicationLoggingListener.VOID; @@ -121,9 +147,10 @@ public class BinaryProtocol implements BinaryProtocolCommands { incomingData = dataBuffer; Runtime.getRuntime().addShutdownHook(hook); + needCompositeLogger = linkManager.getCompositeLogicEnabled(); rpmListener = value -> { if (value <= COMPOSITE_OFF_RPM) { - needCompositeLogger = true; + needCompositeLogger = linkManager.getCompositeLogicEnabled(); lastLowRpmTime = System.currentTimeMillis(); } else if (System.currentTimeMillis() - lastLowRpmTime > HIGH_RPM_DELAY * Timeouts.SECOND) { logger.info("Time to turn off composite logging"); @@ -207,7 +234,7 @@ public class BinaryProtocol implements BinaryProtocolCommands { public void run() { while (!isClosed) { // FileLog.rlog("queue: " + LinkManager.COMMUNICATION_QUEUE.toString()); - if (linkManager.COMMUNICATION_QUEUE.isEmpty()) { + if (linkManager.COMMUNICATION_QUEUE.isEmpty() && linkManager.getNeedPullData()) { linkManager.submit(new Runnable() { @Override public void run() { @@ -339,7 +366,7 @@ public class BinaryProtocol implements BinaryProtocolCommands { if (!checkResponseCode(response, RESPONSE_OK) || response.length != requestSize + 1) { String code = (response == null || response.length == 0) ? "empty" : "code " + response[0]; String info = response == null ? "NO RESPONSE" : (code + " size " + response.length); - logger.error("readImage: Something is wrong, retrying... " + info); + logger.info("readImage: ERROR UNEXPECTED Something is wrong, retrying... " + info); continue; } @@ -360,6 +387,8 @@ public class BinaryProtocol implements BinaryProtocolCommands { } private ConfigurationImage getAndValidateLocallyCached() { + if (DISABLE_LOCAL_CACHE) + return null; ConfigurationImage localCached; try { localCached = ConfigurationImageFile.readFromFile(CONFIGURATION_RUSEFI_BINARY); @@ -370,7 +399,7 @@ public class BinaryProtocol implements BinaryProtocolCommands { if (localCached != null) { int crcOfLocallyCachedConfiguration = IoHelper.getCrc32(localCached.getContent()); - System.out.printf("Local cache CRC %x\n", crcOfLocallyCachedConfiguration); + System.out.printf(CONFIGURATION_RUSEFI_BINARY + " Local cache CRC %x\n", crcOfLocallyCachedConfiguration); byte packet[] = new byte[7]; packet[0] = COMMAND_CRC_CHECK_COMMAND; diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java index 96163020a8..e02449fe06 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java @@ -22,6 +22,7 @@ import static com.rusefi.binaryprotocol.IoHelper.*; @ThreadSafe public class IncomingDataBuffer { private static final int BUFFER_SIZE = 32768; + private static String loggingPrefix; /** * buffer for response bytes from controller */ @@ -33,7 +34,8 @@ public class IncomingDataBuffer { this.logger = logger; } - public static IncomingDataBuffer createDataBuffer(IoStream stream, Logger logger) { + public static IncomingDataBuffer createDataBuffer(String loggingPrefix, IoStream stream, Logger logger) { + IncomingDataBuffer.loggingPrefix = loggingPrefix; IncomingDataBuffer incomingData = new IncomingDataBuffer(logger); stream.setInputListener(incomingData::addData); return incomingData; @@ -49,13 +51,13 @@ public class IncomingDataBuffer { return null; int packetSize = swap16(getShort()); - logger.trace("Got packet size " + packetSize); + logger.trace( loggingPrefix + "Got packet size " + packetSize); if (packetSize < 0) return null; if (!allowLongResponse && packetSize > Math.max(BinaryProtocolCommands.BLOCKING_FACTOR, Fields.TS_OUTPUT_SIZE) + 10) return null; - isTimeout = waitForBytes(msg + " body", start, packetSize + 4); + isTimeout = waitForBytes(loggingPrefix + msg + " body", start, packetSize + 4); if (isTimeout) return null; @@ -148,28 +150,28 @@ public class IncomingDataBuffer { } public byte readByte() throws IOException { - boolean timeout = waitForBytes("readByte", System.currentTimeMillis(), 1); + boolean timeout = waitForBytes(loggingPrefix + "readByte", System.currentTimeMillis(), 1); if (timeout) throw new IOException("Timeout in readByte"); return (byte) getByte(); } public int readInt() throws EOFException { - boolean timeout = waitForBytes("readInt", System.currentTimeMillis(), 4); + boolean timeout = waitForBytes(loggingPrefix + "readInt", System.currentTimeMillis(), 4); if (timeout) throw new IllegalStateException("Timeout in readByte"); return swap32(getInt()); } public short readShort() throws EOFException { - boolean timeout = waitForBytes("readShort", System.currentTimeMillis(), 2); + boolean timeout = waitForBytes(loggingPrefix + "readShort", System.currentTimeMillis(), 2); if (timeout) throw new IllegalStateException("Timeout in readShort"); return (short) swap16(getShort()); } public int read(byte[] packet) { - boolean timeout = waitForBytes("read", System.currentTimeMillis(), packet.length); + boolean timeout = waitForBytes(loggingPrefix + "read", System.currentTimeMillis(), packet.length); if (timeout) throw new IllegalStateException("Timeout while waiting " + packet.length); getData(packet); diff --git a/java_console/io/src/main/java/com/rusefi/io/ByteReader.java b/java_console/io/src/main/java/com/rusefi/io/ByteReader.java index ecec38c3c8..1eea6bdf02 100644 --- a/java_console/io/src/main/java/com/rusefi/io/ByteReader.java +++ b/java_console/io/src/main/java/com/rusefi/io/ByteReader.java @@ -9,7 +9,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; public interface ByteReader { - static void runReaderLoop(DataListener listener, ByteReader reader, Logger logger) { + static void runReaderLoop(String loggingPrefix, DataListener listener, ByteReader reader, Logger logger) { /** * Threading of the whole input/output does not look healthy at all! * @@ -24,7 +24,7 @@ public interface ByteReader { threadExecutor.execute(() -> { Thread.currentThread().setName("TCP connector loop"); - logger.info("Running TCP connection loop"); + logger.info(loggingPrefix + "Running TCP connection loop"); byte inputBuffer[] = new byte[256]; while (true) { diff --git a/java_console/io/src/main/java/com/rusefi/io/IoStream.java b/java_console/io/src/main/java/com/rusefi/io/IoStream.java index 7ad5d2e6ef..1cd0227003 100644 --- a/java_console/io/src/main/java/com/rusefi/io/IoStream.java +++ b/java_console/io/src/main/java/com/rusefi/io/IoStream.java @@ -6,6 +6,8 @@ import com.opensr5.io.WriteStream; import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.binaryprotocol.IncomingDataBuffer; import com.rusefi.binaryprotocol.IoHelper; +import com.rusefi.io.tcp.BinaryProtocolServer; +import org.jetbrains.annotations.NotNull; import java.io.EOFException; import java.io.IOException; @@ -31,6 +33,18 @@ public interface IoStream extends WriteStream { return r.toString(); } + @NotNull + default BinaryProtocolServer.Packet readPacket() throws IOException { + short length = readShort(); + return BinaryProtocolServer.readPromisedBytes(getDataBuffer(), length); + } + + default void sendPacket(BinaryProtocolServer.Packet packet) throws IOException { + writeShort(packet.getPacket().length); + write(packet.getPacket()); + writeInt(packet.getCrc()); + } + default void sendPacket(byte[] plainPacket, Logger logger) throws IOException { byte[] packet; if (BinaryProtocol.PLAIN_PROTOCOL) { @@ -38,7 +52,8 @@ public interface IoStream extends WriteStream { } else { packet = IoHelper.makeCrc32Packet(plainPacket); } - logger.info("Sending packet " + printHexBinary(plainPacket)); + // todo: verbose mode printHexBinary(plainPacket)) + logger.info(getLoggingPrefix() + "Sending packet " + BinaryProtocol.findCommand(plainPacket[0]) + " length=" + plainPacket.length); write(packet); } @@ -51,6 +66,8 @@ public interface IoStream extends WriteStream { void close(); + String getLoggingPrefix(); + IncomingDataBuffer getDataBuffer(); default short readShort() throws EOFException { diff --git a/java_console/io/src/main/java/com/rusefi/io/LinkManager.java b/java_console/io/src/main/java/com/rusefi/io/LinkManager.java index a580d8d956..c0967491f8 100644 --- a/java_console/io/src/main/java/com/rusefi/io/LinkManager.java +++ b/java_console/io/src/main/java/com/rusefi/io/LinkManager.java @@ -6,7 +6,6 @@ import com.rusefi.Callable; import com.rusefi.NamedThreadFactory; import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.binaryprotocol.BinaryProtocolState; -import com.rusefi.binaryprotocol.IncomingDataBuffer; import com.rusefi.core.EngineState; import com.rusefi.io.serial.StreamConnector; import com.rusefi.io.serial.SerialIoStreamJSerialComm; @@ -14,6 +13,7 @@ import com.rusefi.io.tcp.TcpConnector; import com.rusefi.io.tcp.TcpIoStream; import org.jetbrains.annotations.NotNull; +import java.io.Closeable; import java.net.Socket; import java.util.Arrays; import java.util.Objects; @@ -25,7 +25,7 @@ import java.util.concurrent.*; * @author Andrey Belomutskiy * 3/3/14 */ -public class LinkManager { +public class LinkManager implements Closeable { @NotNull public static LogLevel LOG_LEVEL = LogLevel.INFO; @@ -42,6 +42,8 @@ public class LinkManager { private LinkConnector connector; private boolean isStarted; + private boolean compositeLogicEnabled = true; + private boolean needPullData = true; public LinkManager(Logger logger) { this.logger = logger; @@ -107,6 +109,24 @@ public class LinkManager { return commandQueue; } + public LinkManager setCompositeLogicEnabled(boolean compositeLogicEnabled) { + this.compositeLogicEnabled = compositeLogicEnabled; + return this; + } + + public boolean getCompositeLogicEnabled() { + return compositeLogicEnabled; + } + + public boolean getNeedPullData() { + return needPullData; + } + + public LinkManager setNeedPullData(boolean needPullData) { + this.needPullData = needPullData; + return this; + } + public enum LogLevel { INFO, DEBUG, @@ -188,7 +208,7 @@ public class LinkManager { int portPart = TcpConnector.getTcpPort(port); String hostname = TcpConnector.getHostname(port); socket = new Socket(hostname, portPart); - TcpIoStream tcpIoStream = new TcpIoStream(logger, socket); + TcpIoStream tcpIoStream = new TcpIoStream("[start] ", logger, socket); return tcpIoStream; } catch (Throwable e) { @@ -201,12 +221,10 @@ public class LinkManager { setConnector(new StreamConnector(this, port, logger, streamFactory)); isSimulationMode = true; } else { - Callable ioStreamCallable = () -> SerialIoStreamJSerialComm.openPort(port, logger); - - Callable ioStreamCallable1 = new Callable() { + Callable ioStreamCallable = new Callable() { @Override public IoStream call() { - IoStream stream = ioStreamCallable.call(); + IoStream stream = ((Callable) () -> SerialIoStreamJSerialComm.openPort(port, logger)).call(); if (stream == null) { // error already reported return null; @@ -214,7 +232,7 @@ public class LinkManager { return stream; } }; - setConnector(new StreamConnector(this, port, logger, ioStreamCallable1)); + setConnector(new StreamConnector(this, port, logger, ioStreamCallable)); } } @@ -246,7 +264,8 @@ public class LinkManager { connector.restart(); } - public void stop() { + @Override + public void close() { connector.stop(); } diff --git a/java_console/io/src/main/java/com/rusefi/io/commands/Command.java b/java_console/io/src/main/java/com/rusefi/io/commands/Command.java index 2667d1c6c7..a7ceadab6c 100644 --- a/java_console/io/src/main/java/com/rusefi/io/commands/Command.java +++ b/java_console/io/src/main/java/com/rusefi/io/commands/Command.java @@ -1,12 +1,11 @@ package com.rusefi.io.commands; import com.rusefi.io.IoStream; -import com.rusefi.io.tcp.BinaryProtocolServer; import java.io.IOException; public interface Command { byte getCommand(); - void handle(BinaryProtocolServer.Packet packet, IoStream stream) throws IOException; + void handle(IoStream stream) throws IOException; } diff --git a/java_console/io/src/main/java/com/rusefi/io/commands/HelloCommand.java b/java_console/io/src/main/java/com/rusefi/io/commands/HelloCommand.java index a1a34e4988..d058fbdd2b 100644 --- a/java_console/io/src/main/java/com/rusefi/io/commands/HelloCommand.java +++ b/java_console/io/src/main/java/com/rusefi/io/commands/HelloCommand.java @@ -40,7 +40,7 @@ public class HelloCommand implements Command { } @Override - public void handle(BinaryProtocolServer.Packet packet, IoStream stream) throws IOException { + public void handle(IoStream stream) throws IOException { stream.sendPacket((BinaryProtocolServer.TS_OK + tsSignature).getBytes(), logger); } } diff --git a/java_console/io/src/main/java/com/rusefi/io/serial/SerialIoStreamJSerialComm.java b/java_console/io/src/main/java/com/rusefi/io/serial/SerialIoStreamJSerialComm.java index 7e417a1b47..3ea85368c1 100644 --- a/java_console/io/src/main/java/com/rusefi/io/serial/SerialIoStreamJSerialComm.java +++ b/java_console/io/src/main/java/com/rusefi/io/serial/SerialIoStreamJSerialComm.java @@ -28,7 +28,12 @@ public class SerialIoStreamJSerialComm implements IoStream { this.sp = sp; this.port = port; this.logger = logger; - this.dataBuffer = IncomingDataBuffer.createDataBuffer(this, logger); + this.dataBuffer = IncomingDataBuffer.createDataBuffer("[serial] ", this, logger); + } + + @Override + public String getLoggingPrefix() { + return ""; } @Override diff --git a/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolProxy.java b/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolProxy.java index 28729b51fc..7a4230506a 100644 --- a/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolProxy.java +++ b/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolProxy.java @@ -1,26 +1,33 @@ package com.rusefi.io.tcp; import com.opensr5.Logger; +import com.rusefi.binaryprotocol.BinaryProtocol; +import com.rusefi.binaryprotocol.IncomingDataBuffer; import com.rusefi.io.IoStream; import java.io.ByteArrayInputStream; import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.IOException; import java.net.Socket; import java.util.function.Function; import static com.rusefi.binaryprotocol.BinaryProtocolCommands.COMMAND_PROTOCOL; +import static com.rusefi.config.generated.Fields.TS_PROTOCOL; public class BinaryProtocolProxy { - public static void createProxy(IoStream targetEcuSocket, int serverProxyPort) { + public static void createProxy(Logger logger, IoStream targetEcuSocket, int serverProxyPort) { Function clientSocketRunnableFactory = new Function() { @Override public Runnable apply(Socket clientSocket) { return new Runnable() { @Override public void run() { - runProxy(targetEcuSocket, clientSocket); + try { + TcpIoStream clientStream = new TcpIoStream("[[proxy]] ", logger, clientSocket); + runProxy(targetEcuSocket, clientStream); + } catch (IOException e) { + e.printStackTrace(); + } } }; } @@ -28,41 +35,31 @@ public class BinaryProtocolProxy { BinaryProtocolServer.tcpServerSocket(serverProxyPort, "proxy", clientSocketRunnableFactory, Logger.CONSOLE, null); } - private static void runProxy(IoStream targetEcu, Socket clientSocket) { + public static void runProxy(IoStream targetEcu, IoStream clientStream) throws IOException { /* * Each client socket is running on it's own thread */ - try { - DataInputStream clientInputStream = new DataInputStream(clientSocket.getInputStream()); - DataOutputStream clientOutputStream = new DataOutputStream(clientSocket.getOutputStream()); - while (true) { - byte firstByte = clientInputStream.readByte(); - if (firstByte == COMMAND_PROTOCOL) { - BinaryProtocolServer.handleProtocolCommand(clientSocket); - continue; - } - proxyClientRequestToController(clientInputStream, firstByte, targetEcu); - - proxyControllerResponseToClient(targetEcu, clientOutputStream); + while (true) { + byte firstByte = clientStream.getDataBuffer().readByte(); + if (firstByte == COMMAND_PROTOCOL) { + clientStream.write(TS_PROTOCOL.getBytes()); + continue; } - } catch (IOException e) { - e.printStackTrace(); + proxyClientRequestToController(clientStream.getDataBuffer(), firstByte, targetEcu); + + proxyControllerResponseToClient(targetEcu, clientStream); } } - private static void proxyControllerResponseToClient(IoStream targetInputStream, DataOutputStream clientOutputStream) throws IOException { - short length = targetInputStream.readShort(); - BinaryProtocolServer.Packet packet = BinaryProtocolServer.readPromisedBytes(targetInputStream.getDataBuffer(), length); + public static void proxyControllerResponseToClient(IoStream targetInputStream, IoStream clientOutputStream) throws IOException { + BinaryProtocolServer.Packet packet = targetInputStream.readPacket(); - System.out.println("Relaying controller response length=" + length); - clientOutputStream.writeShort(length); - clientOutputStream.write(packet.getPacket()); - clientOutputStream.writeInt(packet.getCrc()); - clientOutputStream.flush(); + System.out.println("Relaying controller response length=" + packet.getPacket().length); + clientOutputStream.sendPacket(packet); } - private static void proxyClientRequestToController(DataInputStream in, byte firstByte, IoStream targetOutputStream) throws IOException { + private static void proxyClientRequestToController(IncomingDataBuffer in, byte firstByte, IoStream targetOutputStream) throws IOException { byte secondByte = in.readByte(); int length = firstByte * 256 + secondByte; @@ -71,11 +68,8 @@ public class BinaryProtocolProxy { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet.getPacket())); byte command = (byte) dis.read(); - System.out.println("Relaying client command" + (char) command + "/" + command + " length=" + length); - // sending proxies packet to controller - targetOutputStream.write(firstByte); - targetOutputStream.write(secondByte); - targetOutputStream.write(packet.getPacket()); - targetOutputStream.writeInt(packet.getCrc()); + System.out.println("Relaying client command " + BinaryProtocol.findCommand(command)); + // sending proxied packet to controller + targetOutputStream.sendPacket(packet); } } diff --git a/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java b/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java index 4ae5c26784..15513c0545 100644 --- a/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java +++ b/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java @@ -3,13 +3,12 @@ package com.rusefi.io.tcp; import com.opensr5.ConfigurationImage; import com.opensr5.Logger; import com.rusefi.Listener; -import com.rusefi.binaryprotocol.BinaryProtocolCommands; -import com.rusefi.binaryprotocol.BinaryProtocolState; -import com.rusefi.binaryprotocol.IncomingDataBuffer; -import com.rusefi.binaryprotocol.IoHelper; +import com.rusefi.binaryprotocol.*; import com.rusefi.config.generated.Fields; +import com.rusefi.io.IoStream; import com.rusefi.io.LinkManager; import com.rusefi.io.commands.HelloCommand; +import com.rusefi.server.rusEFISSLContext; import java.io.*; import java.net.ServerSocket; @@ -20,7 +19,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import static com.rusefi.binaryprotocol.IoHelper.swap16; -import static com.rusefi.config.generated.Fields.*; +import static com.rusefi.config.generated.Fields.TS_PROTOCOL; +import static com.rusefi.config.generated.Fields.TS_RESPONSE_BURN_OK; /** * This class makes rusEfi console a proxy for other tuning software, this way we can have two tools connected via same @@ -37,6 +37,17 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { public AtomicInteger unknownCommands = new AtomicInteger(); + public static final Function SECURE_SOCKET_FACTORY = rusEFISSLContext::getSSLServerSocket; + + public static final Function PLAIN_SOCKET_FACTORY = port -> { + try { + return new ServerSocket(port); + } catch (IOException e) { + throw new IllegalStateException("Error binding server socket " + port, e); + } + }; + + public BinaryProtocolServer(Logger logger) { this.logger = logger; } @@ -64,35 +75,28 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { * * @param port server port to accept connections * @param threadName - * @param clientSocketRunnableFactory method to invoke on a new thread for each new client connection + * @param socketRunnableFactory method to invoke on a new thread for each new client connection * @param logger * @param serverSocketCreationCallback this callback is invoked once we open the server socket */ - public static void tcpServerSocket(int port, String threadName, Function clientSocketRunnableFactory, final Logger logger, Listener serverSocketCreationCallback) { - Runnable runnable = new Runnable() { - @SuppressWarnings("InfiniteLoopStatement") - @Override - public void run() { - ServerSocket serverSocket; - try { - serverSocket = new ServerSocket(port, 1); - } catch (IOException e) { - logger.error("Error binding server socket" + e); - return; - } - if (serverSocketCreationCallback != null) - serverSocketCreationCallback.onResult(null); + public static void tcpServerSocket(int port, String threadName, Function socketRunnableFactory, final Logger logger, Listener serverSocketCreationCallback) { + tcpServerSocket(logger, socketRunnableFactory, port, threadName, serverSocketCreationCallback, PLAIN_SOCKET_FACTORY); + } - try { - while (true) { - // Wait for a connection - final Socket clientSocket = serverSocket.accept(); - logger.info("Binary protocol proxy port connection"); - new Thread(clientSocketRunnableFactory.apply(clientSocket), "proxy connection").start(); - } - } catch (IOException e) { - throw new IllegalStateException(e); + public static void tcpServerSocket(Logger logger, Function clientSocketRunnableFactory, int port, String threadName, Listener serverSocketCreationCallback, Function nonSecureSocketFunction) { + ServerSocket serverSocket = nonSecureSocketFunction.apply(port); + if (serverSocketCreationCallback != null) + serverSocketCreationCallback.onResult(null); + Runnable runnable = () -> { + try { + while (true) { + // Wait for a connection + final Socket clientSocket = serverSocket.accept(); + logger.info("Binary protocol proxy port connection"); + new Thread(clientSocketRunnableFactory.apply(clientSocket), "proxy connection").start(); } + } catch (IOException e) { + throw new IllegalStateException(e); } }; new Thread(runnable, threadName).start(); @@ -100,7 +104,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { @SuppressWarnings("InfiniteLoopStatement") private void runProxy(LinkManager linkManager, Socket clientSocket) throws IOException { - TcpIoStream stream = new TcpIoStream(logger, clientSocket); + TcpIoStream stream = new TcpIoStream("[proxy] ", logger, clientSocket); IncomingDataBuffer in = stream.getDataBuffer(); @@ -126,10 +130,10 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { byte command = payload[0]; - System.out.println("Got [" + (char) command + "/" + command + "] command"); + System.out.println("Got command " + BinaryProtocol.findCommand(command)); if (command == Fields.TS_HELLO_COMMAND) { - new HelloCommand(logger, Fields.TS_SIGNATURE).handle(packet, stream); + new HelloCommand(logger, Fields.TS_SIGNATURE).handle(stream); } else if (command == COMMAND_PROTOCOL) { // System.out.println("Ignoring crc F command"); stream.sendPacket((TS_OK + TS_PROTOCOL).getBytes(), logger); @@ -155,7 +159,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1)); int offset = swap16(dis.readShort()); int count = swap16(dis.readShort()); - System.out.println("TS_OUTPUT_COMMAND offset=" + offset + "/count=" + count); + logger.info("TS_OUTPUT_COMMAND offset=" + offset + "/count=" + count); byte[] response = new byte[1 + count]; response[0] = (byte) TS_OK.charAt(0); @@ -171,7 +175,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { } else { unknownCommands.incrementAndGet(); new IllegalStateException().printStackTrace(); - logger.info("Error: unknown command " + (char) command + "/" + command); + logger.info("Error: unexpected " + BinaryProtocol.findCommand(command)); } } } @@ -207,11 +211,10 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { int crc = in.readInt(); int fromPacket = IoHelper.getCrc32(packet); if (crc != fromPacket) - throw new IllegalStateException("CRC mismatch " + crc + " vs " + fromPacket); + throw new IllegalStateException("CRC mismatch crc=" + Integer.toString(crc, 16) + " vs packet=" + Integer.toString(fromPacket, 16) + " len=" + packet.length + " data: " + IoStream.printHexBinary(packet)); return new Packet(packet, crc); } - public interface Handler { void handle() throws IOException; } diff --git a/java_console/io/src/main/java/com/rusefi/io/tcp/TcpIoStream.java b/java_console/io/src/main/java/com/rusefi/io/tcp/TcpIoStream.java index d6a91893c1..e0d71c23a8 100644 --- a/java_console/io/src/main/java/com/rusefi/io/tcp/TcpIoStream.java +++ b/java_console/io/src/main/java/com/rusefi/io/tcp/TcpIoStream.java @@ -20,10 +20,16 @@ public class TcpIoStream implements IoStream { private final InputStream input; private final OutputStream output; private final Logger logger; + private final String loggingPrefix; private boolean isClosed; private final IncomingDataBuffer dataBuffer; public TcpIoStream(Logger logger, Socket socket) throws IOException { + this("", logger, socket); + } + + public TcpIoStream(String loggingPrefix, Logger logger, Socket socket) throws IOException { + this.loggingPrefix = loggingPrefix; InputStream input = new BufferedInputStream(socket.getInputStream()); OutputStream output = socket.getOutputStream(); this.logger = logger; @@ -33,7 +39,12 @@ public class TcpIoStream implements IoStream { throw new NullPointerException("output"); this.output = output; this.input = input; - this.dataBuffer = IncomingDataBuffer.createDataBuffer(this, logger); + this.dataBuffer = IncomingDataBuffer.createDataBuffer(loggingPrefix, this, logger); + } + + @Override + public String getLoggingPrefix() { + return loggingPrefix; } @Override @@ -55,7 +66,7 @@ public class TcpIoStream implements IoStream { @Override public void setInputListener(final DataListener listener) { - ByteReader.runReaderLoop(listener, input::read, logger); + ByteReader.runReaderLoop(loggingPrefix, listener, input::read, logger); } @Override diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerInfo.java b/java_console/io/src/main/java/com/rusefi/server/ControllerInfo.java similarity index 71% rename from java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerInfo.java rename to java_console/io/src/main/java/com/rusefi/server/ControllerInfo.java index cac3469a77..b5481f6b55 100644 --- a/java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerInfo.java +++ b/java_console/io/src/main/java/com/rusefi/server/ControllerInfo.java @@ -1,9 +1,9 @@ package com.rusefi.server; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; -import java.io.StringReader; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + import java.util.Objects; /** @@ -58,25 +58,28 @@ public class ControllerInfo { } public static ControllerInfo valueOf(String jsonString) { - JsonReader reader = Json.createReader(new StringReader(jsonString)); - - JsonObject jsonObject = reader.readObject(); - String vehicleName = jsonObject.getString(VEHICLE_NAME); - String engineMake = jsonObject.getString(ENGINE_MAKE); - String engineCode = jsonObject.getString(ENGINE_CODE); - String signature = jsonObject.getString(SIGNATURE); + JSONParser parser = new JSONParser(); + JSONObject jsonObject; + try { + jsonObject = (JSONObject) parser.parse(jsonString); + } catch (ParseException e) { + throw new IllegalStateException(e); + } + String vehicleName = (String) jsonObject.get(VEHICLE_NAME); + String engineMake = (String) jsonObject.get(ENGINE_MAKE); + String engineCode = (String) jsonObject.get(ENGINE_CODE); + String signature = (String) jsonObject.get(SIGNATURE); return new ControllerInfo(vehicleName, engineCode, engineMake, signature); } public String toJson() { - JsonObject jsonObject = Json.createObjectBuilder() - .add(ENGINE_MAKE, engineMake) - .add(ENGINE_CODE, engineCode) - .add(VEHICLE_NAME, vehicleName) - .add(SIGNATURE, signature) - .build(); - return jsonObject.toString(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put(ENGINE_MAKE, engineMake); + jsonObject.put(ENGINE_CODE, engineCode); + jsonObject.put(VEHICLE_NAME, vehicleName); + jsonObject.put(SIGNATURE, signature); + return jsonObject.toJSONString(); } @Override diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/SessionDetails.java b/java_console/io/src/main/java/com/rusefi/server/SessionDetails.java similarity index 51% rename from java_tools/proxy_server/src/main/java/com/rusefi/server/SessionDetails.java rename to java_console/io/src/main/java/com/rusefi/server/SessionDetails.java index 2c2802434a..ea44980088 100644 --- a/java_tools/proxy_server/src/main/java/com/rusefi/server/SessionDetails.java +++ b/java_console/io/src/main/java/com/rusefi/server/SessionDetails.java @@ -1,16 +1,17 @@ package com.rusefi.server; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; -import java.io.StringReader; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + import java.util.Objects; import java.util.Random; public class SessionDetails { - public static final String ONE_TIME_TOKEN = "oneTime"; - public static final String AUTH_TOKEN = "authToken"; - public static final String CONTROLLER = "controller"; + private static final String ONE_TIME_TOKEN = "oneTime"; + private static final String AUTH_TOKEN = "authToken"; + private static final String CONTROLLER = "controller"; + private static final String HARDCODED_ONE_TIME_CODE = System.getProperty("ONE_TIME_CODE"); private final ControllerInfo controllerInfo; @@ -26,7 +27,7 @@ public class SessionDetails { } public static int createOneTimeCode() { - return new Random().nextInt(60000); + return HARDCODED_ONE_TIME_CODE == null ? new Random().nextInt(100000) : Integer.parseInt(HARDCODED_ONE_TIME_CODE); } public int getOneTimeToken() { @@ -42,27 +43,30 @@ public class SessionDetails { } public String toJson() { - JsonObject jsonObject = Json.createObjectBuilder() - .add(CONTROLLER, controllerInfo.toJson()) - .add(ONE_TIME_TOKEN, oneTimeToken) - .add(AUTH_TOKEN, authToken) - .build(); - return jsonObject.toString(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put(CONTROLLER, controllerInfo.toJson()); + jsonObject.put(ONE_TIME_TOKEN, oneTimeToken); + jsonObject.put(AUTH_TOKEN, authToken); + return jsonObject.toJSONString(); } public static SessionDetails valueOf(String jsonString) { - JsonReader reader = Json.createReader(new StringReader(jsonString)); + JSONParser parser = new JSONParser(); + JSONObject jsonObject; + try { + jsonObject = (JSONObject) parser.parse(jsonString); + } catch (ParseException e) { + throw new IllegalStateException(e); + } - JsonObject jsonObject = reader.readObject(); - String authToken = jsonObject.getString(AUTH_TOKEN); - int oneTimeCode = jsonObject.getInt(ONE_TIME_TOKEN); + String authToken = (String) jsonObject.get(AUTH_TOKEN); + long oneTimeCode = (Long)jsonObject.get(ONE_TIME_TOKEN); - ControllerInfo controllerInfo = ControllerInfo.valueOf(jsonObject.getString(CONTROLLER)); + ControllerInfo controllerInfo = ControllerInfo.valueOf((String) jsonObject.get(CONTROLLER)); - return new SessionDetails(controllerInfo, authToken, oneTimeCode); + return new SessionDetails(controllerInfo, authToken, (int) oneTimeCode); } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/java_console/io/src/main/java/com/rusefi/server/rusEFISSLContext.java b/java_console/io/src/main/java/com/rusefi/server/rusEFISSLContext.java new file mode 100644 index 0000000000..68ee54bee0 --- /dev/null +++ b/java_console/io/src/main/java/com/rusefi/server/rusEFISSLContext.java @@ -0,0 +1,128 @@ +package com.rusefi.server; + +import javax.net.ssl.*; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.ServerSocket; +import java.net.Socket; +import java.security.KeyStore; +import java.security.cert.X509Certificate; +import java.util.Objects; + +public class rusEFISSLContext { + private static final String TLS = "TLS"; + + // I assume that jenkins own setup is interfering with our attempts to change system properties :( + // also open question to get SSL context adjusted without touching system properties + private static boolean isJenkins = true;//System.getProperty("JENKINS_URL") != null; + +// private static KeyStore key; + + // todo: one day once rusEFI has a proper commercial certificate this should be removed + private static TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + public void checkClientTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + + public void checkServerTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + } + }; + + public static void init(String fileName, String password) throws MalformedURLException { + // system property setup does not work under Jenkins? + if (!isJenkins) + setupCertificates(new File(fileName), password); + + //key = getFromPath(fileName, "PKCS12", password); + } + + public static ServerSocket getSSLServerSocket(int port) { + try { + if (isJenkins) + return new ServerSocket(port); + return SSLServerSocketFactory.getDefault().createServerSocket(port); + } catch (IOException e) { + throw new IllegalStateException("Error binding secure server socket " + port, e); + } +// try { +// return getSSLServerSocketFactory(key, TLS).createServerSocket(port); +// } catch (Exception e) { +// throw new IllegalStateException(e); +// } + } + + public static Socket getSSLSocket(String host, int port) throws IOException { + if (isJenkins) + return new Socket(host, port); + return getSSLSocketFactory(null /*key*/, TLS).createSocket(host, port); + } + + /* + private static SSLServerSocketFactory getSSLServerSocketFactory(KeyStore trustKey, String sslAlgorithm) { + try { + TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + tmf.init(trustKey); + + SSLContext context = SSLContext.getInstance(sslAlgorithm); + context.init(null, tmf.getTrustManagers(), null); + + return context.getServerSocketFactory(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + */ + private static SSLSocketFactory getSSLSocketFactory(KeyStore trustKey, String sslAlgorithm) { + try { +// TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); +// tmf.init(trustKey); + + SSLContext context = SSLContext.getInstance(sslAlgorithm); + context.init(null, trustAllCerts/*tmf.getTrustManagers()*/, null); + + return context.getSocketFactory(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + public static void setupCertificates(File certificate, String password) throws MalformedURLException { + if (!certificate.exists()) + throw new IllegalStateException("Certificate not found " + certificate); + Objects.requireNonNull(password, "password"); + + String file = certificate.toURI().toURL().getFile(); + System.setProperty("javax.net.ssl.keyStore", file); + System.setProperty("javax.net.ssl.keyStorePassword", password); + System.setProperty("javax.net.ssl.trustStore", file); + System.setProperty("javax.net.ssl.trustStorePassword", password); + System.setProperty("javax.net.ssl.keyStoreType", "PKCS12"); + } +/* + private static KeyStore getFromPath(String path, String algorithm, String filePassword) { + try { + File f = new File(path); + + if (!f.exists()) + throw new RuntimeException("File not found: " + path); + + FileInputStream keyFile = new FileInputStream(f); + KeyStore keystore = KeyStore.getInstance(algorithm); + keystore.load(keyFile, filePassword.toCharArray()); + keyFile.close(); + + return keystore; + } catch (Exception e) { + throw new IllegalStateException(e); + } + } +*/ +} diff --git a/java_console/io/src/main/java/com/rusefi/tools/online/HttpUtil.java b/java_console/io/src/main/java/com/rusefi/tools/online/HttpUtil.java new file mode 100644 index 0000000000..0ef36bc09c --- /dev/null +++ b/java_console/io/src/main/java/com/rusefi/tools/online/HttpUtil.java @@ -0,0 +1,41 @@ +package com.rusefi.tools.online; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.IOException; + +public class HttpUtil { + // todo: migrate proxy http json API server to TLS + public static final String RUSEFI_PROXY_JSON_PROTOCOL = "http://"; + public static final int HTTP_PORT = 8001; + /** + * hostname of PROXY server, not primary rusEFI web server - those are two separate hosts at the moment + */ + public static String RUSEFI_PROXY_HOSTNAME = System.getProperty("RUSEFI_PROXY_URL", "proxy.rusefi.com"); + + public static String RUSEFI_ONLINE_JSON_API_PREFIX = "https://rusefi.com/online/api.php?method="; + public static final String RUSEFI_PROXY_JSON_API_PREFIX = RUSEFI_PROXY_JSON_PROTOCOL + RUSEFI_PROXY_HOSTNAME; + + public static T getJsonResponse(HttpResponse response) throws IOException, ParseException { + HttpEntity entity = response.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); + System.out.println("responseString=" + responseString); + + JSONParser parser = new JSONParser(); + return (T) parser.parse(responseString); + } + + public static HttpResponse executeGet(String url) throws IOException { + HttpClient httpclient = new DefaultHttpClient(); + System.out.println("Connecting to " + url); + HttpGet httpget = new HttpGet(url); + return httpclient.execute(httpget); + } +} diff --git a/java_console/io/src/main/java/com/rusefi/tools/online/ProxyClient.java b/java_console/io/src/main/java/com/rusefi/tools/online/ProxyClient.java index f8d0de730b..e8a835990a 100644 --- a/java_console/io/src/main/java/com/rusefi/tools/online/ProxyClient.java +++ b/java_console/io/src/main/java/com/rusefi/tools/online/ProxyClient.java @@ -1,16 +1,10 @@ package com.rusefi.tools.online; import com.rusefi.server.UserDetails; -import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.util.EntityUtils; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import java.io.IOException; @@ -18,23 +12,19 @@ import java.util.ArrayList; import java.util.List; public class ProxyClient { - public static final String LOCALHOST = "localhost"; public static final String LIST_PATH = "/list_online"; - @NotNull public static List getOnlineUsers(int httpPort) throws IOException { - HttpClient httpclient = new DefaultHttpClient(); - String url = "http://" + LOCALHOST + ":" + httpPort + LIST_PATH; - System.out.println("Connecting to " + url); - HttpGet httpget = new HttpGet(url); - HttpResponse httpResponse = httpclient.execute(httpget); + return getOnlineUsers(HttpUtil.RUSEFI_PROXY_JSON_API_PREFIX + ":" + httpPort + LIST_PATH); + } + + @NotNull + public static List getOnlineUsers(String url) throws IOException { + HttpResponse httpResponse = HttpUtil.executeGet(url); - HttpEntity entity = httpResponse.getEntity(); - String responseString = EntityUtils.toString(entity, "UTF-8"); - JSONParser parser = new JSONParser(); List userLists = new ArrayList<>(); try { - JSONArray array = (JSONArray) parser.parse(responseString); + JSONArray array = HttpUtil.getJsonResponse(httpResponse); for (int i = 0; i < array.size(); i++) { JSONObject element = (JSONObject) array.get(i); @@ -44,8 +34,9 @@ public class ProxyClient { System.out.println("object=" + array); } catch (ParseException e) { - throw new IllegalStateException(e); + throw new IOException(e); } return userLists; } + } diff --git a/java_console/models/src/main/java/com/rusefi/composite/CompositeParser.java b/java_console/models/src/main/java/com/rusefi/composite/CompositeParser.java index 8c605f5110..aad006a8ec 100644 --- a/java_console/models/src/main/java/com/rusefi/composite/CompositeParser.java +++ b/java_console/models/src/main/java/com/rusefi/composite/CompositeParser.java @@ -13,7 +13,7 @@ public class CompositeParser { public static List parse(byte[] response) { ByteBuffer byteBuffer = ByteBuffer.wrap(response); byteBuffer.order(ByteOrder.BIG_ENDIAN); - System.out.println("Got composite " + response.length); + System.out.println("Got composite length=" + response.length); int ptr = 1; List events = new ArrayList<>(); diff --git a/java_console/models/src/main/java/com/rusefi/config/generated/Fields.java b/java_console/models/src/main/java/com/rusefi/config/generated/Fields.java index bc5fa6e89f..4a8bc3e39c 100644 --- a/java_console/models/src/main/java/com/rusefi/config/generated/Fields.java +++ b/java_console/models/src/main/java/com/rusefi/config/generated/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config.generated; -// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Jul 15 01:37:00 UTC 2020 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sun Jul 19 16:19:31 UTC 2020 // by class com.rusefi.output.FileJavaFieldsConsumer import com.rusefi.config.*; @@ -1303,7 +1303,7 @@ public class Fields { public static final int TS_RESPONSE_COMMAND_OK = 7; public static final int TS_RESPONSE_OK = 0; public static final char TS_SET_LOGGER_SWITCH = 'l'; - public static final String TS_SIGNATURE = "rusEFI 2020.07.15.all.3884096862"; + public static final String TS_SIGNATURE = "rusEFI 2020.07.19.all.2760614588"; public static final char TS_SINGLE_WRITE_COMMAND = 'W'; public static final int tunerStudioSerialSpeed_offset = 728; public static final int twoWireBatchIgnition_offset = 1476; @@ -1970,9 +1970,9 @@ public class Fields { public static final Field ETBIO22_DIRECTIONPIN2 = Field.create("ETBIO22_DIRECTIONPIN2", 1093, FieldType.INT8, brain_pin_e); public static final Field ETBIO22_CONTROLPIN1 = Field.create("ETBIO22_CONTROLPIN1", 1094, FieldType.INT8, brain_pin_e); public static final Field ETBIO22_DISABLEPIN = Field.create("ETBIO22_DISABLEPIN", 1095, FieldType.INT8, brain_pin_e); - public static final Field ENGINEMAKE = Field.create("ENGINEMAKE", 1096, FieldType.INT); - public static final Field ENGINECODE = Field.create("ENGINECODE", 1128, FieldType.INT); - public static final Field VEHICLENAME = Field.create("VEHICLENAME", 1160, FieldType.INT); + public static final Field ENGINEMAKE = Field.create("ENGINEMAKE", 1096, 32, FieldType.STRING); + public static final Field ENGINECODE = Field.create("ENGINECODE", 1128, 32, FieldType.STRING); + public static final Field VEHICLENAME = Field.create("VEHICLENAME", 1160, 32, FieldType.STRING); public static final Field TCU_SOLENOID1 = Field.create("TCU_SOLENOID1", 1192, FieldType.INT8, output_pin_e); public static final Field TCU_SOLENOID2 = Field.create("TCU_SOLENOID2", 1193, FieldType.INT8, output_pin_e); public static final Field TCU_SOLENOID3 = Field.create("TCU_SOLENOID3", 1194, FieldType.INT8, output_pin_e); @@ -2394,28 +2394,28 @@ public class Fields { public static final Field MC33_T_BYPASS = Field.create("MC33_T_BYPASS", 4508, FieldType.INT16); public static final Field MC33_T_HOLD_OFF = Field.create("MC33_T_HOLD_OFF", 4510, FieldType.INT16); public static final Field MC33_T_HOLD_TOT = Field.create("MC33_T_HOLD_TOT", 4512, FieldType.INT16); - public static final Field WARNING_MESSAGE = Field.create("WARNING_MESSAGE", 6000, FieldType.INT); + public static final Field WARNING_MESSAGE = Field.create("WARNING_MESSAGE", 6000, 120, FieldType.STRING); public static final Field BOOSTTABLEOPENLOOP = Field.create("BOOSTTABLEOPENLOOP", 6248, FieldType.INT); public static final Field BOOSTTABLECLOSEDLOOP = Field.create("BOOSTTABLECLOSEDLOOP", 6328, FieldType.INT); public static final Field PEDALTOTPSTABLE = Field.create("PEDALTOTPSTABLE", 6400, FieldType.INT); - public static final Field FSIOFORMULAS1 = Field.create("FSIOFORMULAS1", 6672, FieldType.INT); - public static final Field FSIOFORMULAS2 = Field.create("FSIOFORMULAS2", 6872, FieldType.INT); - public static final Field FSIOFORMULAS3 = Field.create("FSIOFORMULAS3", 7072, FieldType.INT); - public static final Field FSIOFORMULAS4 = Field.create("FSIOFORMULAS4", 7272, FieldType.INT); - public static final Field FSIOFORMULAS5 = Field.create("FSIOFORMULAS5", 7472, FieldType.INT); - public static final Field FSIOFORMULAS6 = Field.create("FSIOFORMULAS6", 7672, FieldType.INT); - public static final Field FSIOFORMULAS7 = Field.create("FSIOFORMULAS7", 7872, FieldType.INT); - public static final Field FSIOFORMULAS8 = Field.create("FSIOFORMULAS8", 8072, FieldType.INT); - public static final Field FSIOFORMULAS9 = Field.create("FSIOFORMULAS9", 8272, FieldType.INT); - public static final Field FSIOFORMULAS10 = Field.create("FSIOFORMULAS10", 8472, FieldType.INT); - public static final Field FSIOFORMULAS11 = Field.create("FSIOFORMULAS11", 8672, FieldType.INT); - public static final Field FSIOFORMULAS12 = Field.create("FSIOFORMULAS12", 8872, FieldType.INT); - public static final Field FSIOFORMULAS13 = Field.create("FSIOFORMULAS13", 9072, FieldType.INT); - public static final Field FSIOFORMULAS14 = Field.create("FSIOFORMULAS14", 9272, FieldType.INT); - public static final Field FSIOFORMULAS15 = Field.create("FSIOFORMULAS15", 9472, FieldType.INT); - public static final Field FSIOFORMULAS16 = Field.create("FSIOFORMULAS16", 9672, FieldType.INT); - public static final Field TIMINGMULTIPLIER = Field.create("TIMINGMULTIPLIER", 9872, FieldType.INT); - public static final Field TIMINGADDITIVE = Field.create("TIMINGADDITIVE", 10072, FieldType.INT); + public static final Field FSIOFORMULAS1 = Field.create("FSIOFORMULAS1", 6672, 200, FieldType.STRING); + public static final Field FSIOFORMULAS2 = Field.create("FSIOFORMULAS2", 6872, 200, FieldType.STRING); + public static final Field FSIOFORMULAS3 = Field.create("FSIOFORMULAS3", 7072, 200, FieldType.STRING); + public static final Field FSIOFORMULAS4 = Field.create("FSIOFORMULAS4", 7272, 200, FieldType.STRING); + public static final Field FSIOFORMULAS5 = Field.create("FSIOFORMULAS5", 7472, 200, FieldType.STRING); + public static final Field FSIOFORMULAS6 = Field.create("FSIOFORMULAS6", 7672, 200, FieldType.STRING); + public static final Field FSIOFORMULAS7 = Field.create("FSIOFORMULAS7", 7872, 200, FieldType.STRING); + public static final Field FSIOFORMULAS8 = Field.create("FSIOFORMULAS8", 8072, 200, FieldType.STRING); + public static final Field FSIOFORMULAS9 = Field.create("FSIOFORMULAS9", 8272, 200, FieldType.STRING); + public static final Field FSIOFORMULAS10 = Field.create("FSIOFORMULAS10", 8472, 200, FieldType.STRING); + public static final Field FSIOFORMULAS11 = Field.create("FSIOFORMULAS11", 8672, 200, FieldType.STRING); + public static final Field FSIOFORMULAS12 = Field.create("FSIOFORMULAS12", 8872, 200, FieldType.STRING); + public static final Field FSIOFORMULAS13 = Field.create("FSIOFORMULAS13", 9072, 200, FieldType.STRING); + public static final Field FSIOFORMULAS14 = Field.create("FSIOFORMULAS14", 9272, 200, FieldType.STRING); + public static final Field FSIOFORMULAS15 = Field.create("FSIOFORMULAS15", 9472, 200, FieldType.STRING); + public static final Field FSIOFORMULAS16 = Field.create("FSIOFORMULAS16", 9672, 200, FieldType.STRING); + public static final Field TIMINGMULTIPLIER = Field.create("TIMINGMULTIPLIER", 9872, 200, FieldType.STRING); + public static final Field TIMINGADDITIVE = Field.create("TIMINGADDITIVE", 10072, 200, FieldType.STRING); public static final Field IGNITIONIATCORRTABLE = Field.create("IGNITIONIATCORRTABLE", 12832, FieldType.INT); public static final Field INJECTIONPHASE = Field.create("INJECTIONPHASE", 13984, FieldType.INT); public static final Field FUELTABLE = Field.create("FUELTABLE", 15136, FieldType.INT); diff --git a/java_console/models/src/main/java/com/rusefi/rusEFIVersion.java b/java_console/models/src/main/java/com/rusefi/rusEFIVersion.java index 24aaa413eb..0c7ac50f68 100644 --- a/java_console/models/src/main/java/com/rusefi/rusEFIVersion.java +++ b/java_console/models/src/main/java/com/rusefi/rusEFIVersion.java @@ -3,6 +3,6 @@ package com.rusefi; import java.util.concurrent.atomic.AtomicReference; public class rusEFIVersion { - public static final int CONSOLE_VERSION = 20200711; + public static final int CONSOLE_VERSION = 20200717; public static AtomicReference firmwareVersion = new AtomicReference<>("N/A"); } diff --git a/java_console/models/src/main/java/com/rusefi/stream/LogicdataStreamFile.java b/java_console/models/src/main/java/com/rusefi/stream/LogicdataStreamFile.java index 2f6369dfc8..01f446c761 100644 --- a/java_console/models/src/main/java/com/rusefi/stream/LogicdataStreamFile.java +++ b/java_console/models/src/main/java/com/rusefi/stream/LogicdataStreamFile.java @@ -40,8 +40,8 @@ public class LogicdataStreamFile extends StreamFile { private static final long SIGN_FLAG = 0x80000000L; - private static int numChannels = 6; - private static int reservedDurationInSamples = 10; + private static final int numChannels = 6; + private static final int reservedDurationInSamples = 10; private static int realDurationInSamples = 0; private static int scaledDurationInSamples = 0; diff --git a/java_console/rusefi.xml b/java_console/rusefi.xml index ff2ef4516c..1770605489 100644 --- a/java_console/rusefi.xml +++ b/java_console/rusefi.xml @@ -1,6 +1,6 @@ - + diff --git a/java_console/shared_ui/shared_ui.iml b/java_console/shared_ui/shared_ui.iml index ea663f3587..94a76fec0f 100644 --- a/java_console/shared_ui/shared_ui.iml +++ b/java_console/shared_ui/shared_ui.iml @@ -13,5 +13,6 @@ + \ No newline at end of file diff --git a/java_console/shared_ui/src/com/rusefi/tools/online/Online.java b/java_console/shared_ui/src/com/rusefi/tools/online/Online.java index 0d6182e7f2..8c4bdd48ed 100644 --- a/java_console/shared_ui/src/com/rusefi/tools/online/Online.java +++ b/java_console/shared_ui/src/com/rusefi/tools/online/Online.java @@ -3,7 +3,6 @@ package com.rusefi.tools.online; import com.rusefi.shared.FileUtil; import com.rusefi.tune.xml.Msq; import com.rusefi.ui.AuthTokenPanel; -import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; @@ -13,10 +12,8 @@ import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.util.EntityUtils; import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import javax.swing.*; @@ -28,28 +25,27 @@ public class Online { public static final String outputXmlFileName = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + "output.msq"; private static final String url = "https://rusefi.com/online/upload.php"; - public static UploadResult upload(File fileName, String authTokenValue) throws IOException { - HttpClient httpclient = new DefaultHttpClient(); - HttpPost httpPost = new HttpPost(url); - - FileBody uploadFilePart = new FileBody(fileName); - MultipartEntity reqEntity = new MultipartEntity(); - reqEntity.addPart("upload-file", uploadFilePart); - reqEntity.addPart("rusefi_token", new StringBody(authTokenValue)); - - httpPost.setEntity(reqEntity); - - HttpResponse response = httpclient.execute(httpPost); - System.out.println("response=" + response); - System.out.println("code " + response.getStatusLine().getStatusCode()); - - HttpEntity entity = response.getEntity(); - String responseString = EntityUtils.toString(entity, "UTF-8"); - System.out.println("responseString=" + responseString); - - JSONParser parser = new JSONParser(); + /** + * blocking call for http file upload + */ + public static UploadResult upload(File fileName, String authTokenValue) { try { - JSONObject object = (JSONObject) parser.parse(responseString); + HttpClient httpclient = new DefaultHttpClient(); + HttpPost httpPost = new HttpPost(url); + + FileBody uploadFilePart = new FileBody(fileName); + MultipartEntity reqEntity = new MultipartEntity(); + reqEntity.addPart("upload-file", uploadFilePart); + reqEntity.addPart("rusefi_token", new StringBody(authTokenValue)); + + httpPost.setEntity(reqEntity); + + HttpResponse response = httpclient.execute(httpPost); + System.out.println("response=" + response); + System.out.println("code " + response.getStatusLine().getStatusCode()); + + JSONObject object = HttpUtil.getJsonResponse(response); + System.out.println("object=" + object); JSONArray info = (JSONArray) object.get("info"); JSONArray error = (JSONArray) object.get("error"); @@ -61,7 +57,7 @@ public class Online { return new UploadResult(false, info); } - } catch (ParseException e) { + } catch (IOException | ParseException e) { return new UploadResult(true, "Error " + e); } } diff --git a/java_console/shared_ui/src/com/rusefi/tools/online/UploadResult.java b/java_console/shared_ui/src/com/rusefi/tools/online/UploadResult.java index bc05086756..6131d41cdc 100644 --- a/java_console/shared_ui/src/com/rusefi/tools/online/UploadResult.java +++ b/java_console/shared_ui/src/com/rusefi/tools/online/UploadResult.java @@ -21,7 +21,11 @@ public class UploadResult { return isError; } - public JSONArray getMessage() { + public JSONArray getMessageArray() { return message; } + + public String getFirstMessage() { + return message.get(0).toString(); + } } diff --git a/java_console/shared_ui/src/com/rusefi/ui/AuthTokenPanel.java b/java_console/shared_ui/src/com/rusefi/ui/AuthTokenPanel.java index 0309d80b65..e77e5b4a9b 100644 --- a/java_console/shared_ui/src/com/rusefi/ui/AuthTokenPanel.java +++ b/java_console/shared_ui/src/com/rusefi/ui/AuthTokenPanel.java @@ -129,7 +129,7 @@ public class AuthTokenPanel { } public boolean hasToken() { - return textField.getText().trim().length() > 0 && !textField.getText().contains(TOKEN_SUBSTRING); + return AutoTokenUtil.isToken(textField.getText()); } public String getToken() { diff --git a/java_console/ui/src/main/java/com/rusefi/Launcher.java b/java_console/ui/src/main/java/com/rusefi/Launcher.java index a97f89a535..37b7dcd581 100644 --- a/java_console/ui/src/main/java/com/rusefi/Launcher.java +++ b/java_console/ui/src/main/java/com/rusefi/Launcher.java @@ -26,7 +26,7 @@ public class Launcher extends rusEFIVersion { * @see StartupFrame if no parameters specified */ public static void main(final String[] args) throws Exception { - System.out.println("rusEfi UI console " + CONSOLE_VERSION); + System.out.println("rusEFI UI console " + CONSOLE_VERSION); System.out.println("Compiled " + new Date(ConsoleTools.classBuildTimeMillis())); System.out.println("\n\n"); PersistentConfiguration.registerShutdownHook(); diff --git a/java_console/ui/src/main/java/com/rusefi/sensor_logs/BinarySensorLogRestarter.java b/java_console/ui/src/main/java/com/rusefi/sensor_logs/BinarySensorLogRestarter.java index 6b804f2a2b..b61c661085 100644 --- a/java_console/ui/src/main/java/com/rusefi/sensor_logs/BinarySensorLogRestarter.java +++ b/java_console/ui/src/main/java/com/rusefi/sensor_logs/BinarySensorLogRestarter.java @@ -5,10 +5,10 @@ import com.rusefi.Timeouts; import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; import com.rusefi.tools.online.Online; +import com.rusefi.tools.online.UploadResult; import com.rusefi.ui.AuthTokenPanel; import java.io.File; -import java.io.IOException; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -57,11 +57,8 @@ public class BinarySensorLogRestarter implements SensorLog { UPLOAD_EXECUTOR.execute(new Runnable() { @Override public void run() { - try { - Online.upload(new File(fileName), AuthTokenPanel.getAuthToken()); - } catch (IOException e) { - e.printStackTrace(); - } + UploadResult result = Online.upload(new File(fileName), AuthTokenPanel.getAuthToken()); + System.out.println(result.toString()); } }); } diff --git a/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java b/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java index 880505bd44..3ad6109eae 100644 --- a/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java +++ b/java_console/ui/src/main/java/com/rusefi/tools/ConsoleTools.java @@ -21,6 +21,7 @@ import com.rusefi.io.LinkManager; import com.rusefi.io.serial.SerialIoStreamJSerialComm; import com.rusefi.io.tcp.BinaryProtocolServer; import com.rusefi.maintenance.ExecHelper; +import com.rusefi.server.BackendLauncher; import com.rusefi.tools.online.Online; import com.rusefi.tune.xml.Msq; import com.rusefi.ui.AuthTokenPanel; @@ -41,6 +42,7 @@ import static com.rusefi.binaryprotocol.IoHelper.getCrc32; public class ConsoleTools { public static final String SET_AUTH_TOKEN = "set_auth_token"; + public static final String RUS_EFI_NOT_DETECTED = "rusEFI not detected"; private static Map TOOLS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private static Map toolsHelp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); @@ -60,10 +62,15 @@ public class ConsoleTools { registerTool("compile_fsio_line", ConsoleTools::invokeCompileExpressionTool, "Convert a line to RPN form."); registerTool("compile_fsio_file", ConsoleTools::runCompileTool, "Convert all lines from a file to RPN form."); + registerTool("proxy_server", BackendLauncher::start, "NOT A USER TOOL"); + registerTool("network_connector", NetworkConnectorStartup::start, "Connect your rusEFI ECU to rusEFI Online"); + registerTool("network_authenticator", LocalApplicationProxy::start, "rusEFI Online Authenticator"); + registerTool("print_auth_token", args -> printAuthToken(), "Print current rusEFI Online authentication token."); registerTool(SET_AUTH_TOKEN, ConsoleTools::setAuthToken, "Set rusEFI authentication token."); registerTool("upload_tune", ConsoleTools::uploadTune, "Upload specified tune file using auth token from settings"); + registerTool("version", ConsoleTools::version, "Only print version"); registerTool("lightui", ConsoleTools::lightUI, "Start lightweight GUI for tiny screens"); @@ -73,6 +80,10 @@ public class ConsoleTools { registerTool(Fields.CMD_REBOOT_DFU, args -> sendCommand(Fields.CMD_REBOOT_DFU), "Sends a command to switch rusEFI controller into DFU mode."); } + private static void version(String[] strings) { + // version is printed by already, all we need is to do nothing + } + public static void main(String[] args) throws Exception { System.out.println(Arrays.toString(new File(".").list())); System.setProperty("ini_file_path", "../firmware/tunerstudio"); @@ -193,7 +204,7 @@ public class ConsoleTools { String autoDetectedPort = PortDetector.autoDetectSerial(null); if (autoDetectedPort == null) { - System.err.println("rusEFI not detected"); + System.err.println(RUS_EFI_NOT_DETECTED); return; } LinkManager linkManager = new LinkManager(FileLog.LOGGER); @@ -258,7 +269,7 @@ public class ConsoleTools { private static String autoDetectPort() { String autoDetectedPort = PortDetector.autoDetectSerial(null); if (autoDetectedPort == null) { - System.err.println("rusEFI not detected"); + System.err.println(RUS_EFI_NOT_DETECTED); return null; } return autoDetectedPort; @@ -303,7 +314,7 @@ public class ConsoleTools { static void detect(String[] strings) throws IOException, InterruptedException { String autoDetectedPort = autoDetectPort(); if (autoDetectedPort == null) { - System.out.println("rusEFI not detected"); + System.out.println(RUS_EFI_NOT_DETECTED); return; } IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort, FileLog.LOGGER); diff --git a/java_console/ui/src/main/java/com/rusefi/tools/NetworkConnectorStartup.java b/java_console/ui/src/main/java/com/rusefi/tools/NetworkConnectorStartup.java new file mode 100644 index 0000000000..b105ea2c31 --- /dev/null +++ b/java_console/ui/src/main/java/com/rusefi/tools/NetworkConnectorStartup.java @@ -0,0 +1,28 @@ +package com.rusefi.tools; + +import com.rusefi.auth.AutoTokenUtil; +import com.rusefi.autodetect.PortDetector; +import com.rusefi.proxy.NetworkConnector; +import com.rusefi.server.Backend; +import com.rusefi.ui.AuthTokenPanel; + +import java.io.IOException; + +public class NetworkConnectorStartup { + public static void start(String[] strings) throws IOException, InterruptedException { + String authToken = AuthTokenPanel.getAuthToken(); + if (!AutoTokenUtil.isToken(authToken)) { + System.err.println("Please configure authentication token using 'set_auth_token' command"); + return; + } + + String autoDetectedPort = PortDetector.autoDetectSerial(null); + if (autoDetectedPort == null) { + System.err.println(ConsoleTools.RUS_EFI_NOT_DETECTED); + return; + } + + NetworkConnector.runNetworkConnector(authToken, autoDetectedPort, Backend.SERVER_PORT_FOR_CONTROLLERS); + } + +} diff --git a/java_console/ui/src/test/java/com/rusefi/FullServerTest.java b/java_console/ui/src/test/java/com/rusefi/FullServerTest.java new file mode 100644 index 0000000000..80d5629d13 --- /dev/null +++ b/java_console/ui/src/test/java/com/rusefi/FullServerTest.java @@ -0,0 +1,115 @@ +package com.rusefi; + +import com.opensr5.ConfigurationImage; +import com.opensr5.Logger; +import com.opensr5.ini.field.ScalarIniField; +import com.rusefi.binaryprotocol.BinaryProtocol; +import com.rusefi.config.generated.Fields; +import com.rusefi.io.ConnectionStateListener; +import com.rusefi.io.LinkManager; +import com.rusefi.proxy.NetworkConnector; +import com.rusefi.server.*; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.Objects; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static com.rusefi.TestHelper.createIniField; +import static com.rusefi.TestHelper.prepareImage; +import static com.rusefi.Timeouts.READ_IMAGE_TIMEOUT; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class FullServerTest { + private final static Logger logger = Logger.CONSOLE; + + @Before + public void setTestCertificate() throws MalformedURLException { + ServerTest.commonServerTest(); + BinaryProtocol.DISABLE_LOCAL_CACHE = true; + } + + @Test + public void testRelayWorkflow() throws InterruptedException, IOException { + ScalarIniField iniField = TestHelper.createIniField(Fields.CYLINDERSCOUNT); + int value = 241; + int userId = 7; + + CountDownLatch controllerRegistered = new CountDownLatch(1); + + UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), userId); + int httpPort = 8003; + try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) { + @Override + protected void onRegister(ControllerConnectionState controllerConnectionState) { + super.onRegister(controllerConnectionState); + controllerRegistered.countDown(); + } + }; LinkManager clientManager = new LinkManager(logger)) { + int serverPortForControllers = 7001; + int serverPortForRemoteUsers = 7003; + + + // first start backend server + CountDownLatch controllerServerCreated = new CountDownLatch(1); + CountDownLatch applicationServerCreated = new CountDownLatch(1); + + backend.runControllerConnector(serverPortForControllers, parameter -> controllerServerCreated.countDown()); + + backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown()); + + assertTrue(controllerServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + + + // create virtual controller to which "rusEFI network connector" connects to + int controllerPort = 7002; + ConfigurationImage controllerImage = prepareImage(value, createIniField(Fields.CYLINDERSCOUNT)); + CountDownLatch controllerCreated = new CountDownLatch(1); + TestHelper.createVirtualController(controllerImage, controllerPort, parameter -> controllerCreated.countDown(), logger); + assertTrue(controllerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + + + // start "rusEFI network connector" to connect controller with backend since in real life controller has only local serial port it does not have network + SessionDetails deviceSessionDetails = NetworkConnector.runNetworkConnector(MockRusEfiDevice.TEST_TOKEN_1, TestHelper.LOCALHOST + ":" + controllerPort, serverPortForControllers); + + assertTrue(controllerRegistered.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + + SessionDetails authenticatorSessionDetails = new SessionDetails(deviceSessionDetails.getControllerInfo(), MockRusEfiDevice.TEST_TOKEN_3, deviceSessionDetails.getOneTimeToken()); + ApplicationRequest applicationRequest = new ApplicationRequest(authenticatorSessionDetails, userId); + + // start authenticator + + int authenticatorPort = 7004; // local port on which authenticator accepts connections from Tuner Studio + LocalApplicationProxy.startAndRun(logger, serverPortForRemoteUsers, applicationRequest, authenticatorPort); + + + CountDownLatch connectionEstablishedCountDownLatch = new CountDownLatch(1); + + // connect to proxy and read virtual controller through it + clientManager.startAndConnect(TestHelper.LOCALHOST + ":" + authenticatorPort, new ConnectionStateListener() { + @Override + public void onConnectionEstablished() { + connectionEstablishedCountDownLatch.countDown(); + } + + @Override + public void onConnectionFailed() { + System.out.println("Failed"); + } + }); + assertTrue("Proxied ECU Connection established", connectionEstablishedCountDownLatch.await(30, TimeUnit.SECONDS)); + + BinaryProtocol clientStreamState = clientManager.getCurrentStreamState(); + Objects.requireNonNull(clientStreamState, "clientStreamState"); + ConfigurationImage clientImage = clientStreamState.getControllerConfiguration(); + String clientValue = iniField.getValue(clientImage); + assertEquals(Double.toString(value), clientValue); + } + } + +} diff --git a/java_console/ui/src/test/java/com/rusefi/MockRusEfiDevice.java b/java_console/ui/src/test/java/com/rusefi/MockRusEfiDevice.java index c268f8c444..c640cd9d2a 100644 --- a/java_console/ui/src/test/java/com/rusefi/MockRusEfiDevice.java +++ b/java_console/ui/src/test/java/com/rusefi/MockRusEfiDevice.java @@ -1,16 +1,22 @@ package com.rusefi; import com.opensr5.Logger; +import com.rusefi.config.generated.Fields; +import com.rusefi.io.tcp.BinaryProtocolServer; +import com.rusefi.io.tcp.TcpIoStream; +import com.rusefi.proxy.BaseBroadcastingThread; import com.rusefi.server.ControllerInfo; import com.rusefi.server.SessionDetails; +import com.rusefi.server.rusEFISSLContext; import java.io.IOException; import java.net.Socket; -import static com.rusefi.tools.online.ProxyClient.LOCALHOST; +import static com.rusefi.TestHelper.LOCALHOST; public class MockRusEfiDevice { public static final String TEST_TOKEN_1 = "00000000-1234-1234-1234-123456789012"; + public static final String TEST_TOKEN_3 = "33333333-3333-1234-1234-123456789012"; private SessionDetails sessionDetails; private final Logger logger; @@ -26,9 +32,21 @@ public class MockRusEfiDevice { } public void connect(int serverPort) throws IOException { - BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(new Socket(LOCALHOST, serverPort), + Socket socket = rusEFISSLContext.getSSLSocket(LOCALHOST, serverPort); + BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(socket, sessionDetails, - logger); + logger) { + @Override + protected void handleCommand(BinaryProtocolServer.Packet packet, TcpIoStream stream) throws IOException { + super.handleCommand(packet, stream); + + if (packet.getPacket()[0] == Fields.TS_OUTPUT_COMMAND) { + byte[] response = new byte[1 + Fields.TS_OUTPUT_SIZE]; + response[0] = (byte) BinaryProtocolServer.TS_OK.charAt(0); + stream.sendPacket(response, logger); + } + } + }; baseBroadcastingThread.start(); } } diff --git a/java_console/ui/src/test/java/com/rusefi/ServerTest.java b/java_console/ui/src/test/java/com/rusefi/ServerTest.java index 8cc5e753e9..097fc7d048 100644 --- a/java_console/ui/src/test/java/com/rusefi/ServerTest.java +++ b/java_console/ui/src/test/java/com/rusefi/ServerTest.java @@ -1,118 +1,157 @@ package com.rusefi; -import com.opensr5.ConfigurationImage; import com.opensr5.Logger; import com.rusefi.config.generated.Fields; import com.rusefi.io.IoStream; import com.rusefi.io.commands.HelloCommand; -import com.rusefi.server.Backend; -import com.rusefi.server.ClientConnectionState; -import com.rusefi.server.SessionDetails; -import com.rusefi.server.UserDetails; +import com.rusefi.server.*; +import com.rusefi.tools.online.HttpUtil; import com.rusefi.tools.online.ProxyClient; +import org.junit.Before; import org.junit.Test; import java.io.IOException; -import java.net.Socket; +import java.net.MalformedURLException; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import java.util.function.Function; -import static com.rusefi.TestHelper.createIniField; -import static com.rusefi.TestHelper.prepareImage; -import static com.rusefi.tools.online.ProxyClient.LOCALHOST; +import static com.rusefi.Timeouts.READ_IMAGE_TIMEOUT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * integration test of the rusEFI online backend process * At the moment this test is very loose with timing it must be unreliable? + *

+ * https://github.com/rusefi/web_backend/blob/master/documentation/rusEFI%20remote.png */ public class ServerTest { private final static Logger logger = Logger.CONSOLE; + @Before + public void setTestCertificate() throws MalformedURLException { + commonServerTest(); + } + + static void commonServerTest() throws MalformedURLException { + HttpUtil.RUSEFI_PROXY_HOSTNAME = TestHelper.LOCALHOST; + + rusEFISSLContext.init("certificate/test_pkcs12.jks", "password"); + } + @Test - public void testSessionTimeout() throws InterruptedException, IOException { - int serverPort = 7000; + public void testControllerSessionTimeout() throws InterruptedException, IOException { + int serverPortForControllers = 7000; int httpPort = 8000; - Function userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); + UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); CountDownLatch serverCreated = new CountDownLatch(1); CountDownLatch allClientsDisconnected = new CountDownLatch(1); CountDownLatch onConnected = new CountDownLatch(2); - Backend backend = new Backend(userDetailsResolver, httpPort, logger) { + CountDownLatch allConnected = new CountDownLatch(1); + + + try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) { @Override - public void register(ClientConnectionState clientConnectionState) { + public void register(ControllerConnectionState clientConnectionState) { super.register(clientConnectionState); onConnected.countDown(); + try { + allConnected.await(); + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + throw new IllegalStateException(); } @Override - public void close(ClientConnectionState inactiveClient) { + public void close(ControllerConnectionState inactiveClient) { super.close(inactiveClient); if (getCount() == 0) allClientsDisconnected.countDown(); } - }; + }) { - Backend.runProxy(serverPort, serverCreated, backend); - assertTrue(serverCreated.await(30, TimeUnit.SECONDS)); - assertEquals(0, backend.getCount()); + backend.runControllerConnector(serverPortForControllers, parameter -> serverCreated.countDown()); + assertTrue(serverCreated.await(30, TimeUnit.SECONDS)); + assertEquals(0, backend.getCount()); - new MockRusEfiDevice(MockRusEfiDevice.TEST_TOKEN_1, "rusEFI 2020.07.06.frankenso_na6.2468827536", logger).connect(serverPort); - new MockRusEfiDevice("12345678-1234-1234-1234-123456789012", "rusEFI 2020.07.11.proteus_f4.1986715563", logger).connect(serverPort); + new MockRusEfiDevice(MockRusEfiDevice.TEST_TOKEN_1, "rusEFI 2020.07.06.frankenso_na6.2468827536", logger).connect(serverPortForControllers); + new MockRusEfiDevice("12345678-1234-1234-1234-123456789012", "rusEFI 2020.07.11.proteus_f4.1986715563", logger).connect(serverPortForControllers); - assertTrue(onConnected.await(30, TimeUnit.SECONDS)); + assertTrue("onConnected", onConnected.await(30, TimeUnit.SECONDS)); - List clients = backend.getClients(); - assertEquals(2, clients.size()); + List clients = backend.getClients(); + assertEquals(2, clients.size()); - List onlineUsers = ProxyClient.getOnlineUsers(httpPort); - assertEquals(2, onlineUsers.size()); + List onlineUsers = ProxyClient.getOnlineUsers(HttpUtil.RUSEFI_PROXY_JSON_PROTOCOL + TestHelper.LOCALHOST + ":" + httpPort + ProxyClient.LIST_PATH); + assertEquals(2, onlineUsers.size()); - assertTrue(allClientsDisconnected.await(30, TimeUnit.SECONDS)); + allConnected.countDown(); + assertTrue("allClientsDisconnected", allClientsDisconnected.await(30, TimeUnit.SECONDS)); + } } @Test - public void testRelayWorkflow() throws InterruptedException, IOException { - Function userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); + public void testInvalidApplicationRequest() throws InterruptedException, IOException { + UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); int httpPort = 8001; - Backend backend = new Backend(userDetailsResolver, httpPort, logger); - int serverPort = 7001; - CountDownLatch serverCreated = new CountDownLatch(1); + int serverPortForRemoteUsers = 6801; + CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1); + try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) { + @Override + protected void onDisconnectApplication() { + super.onDisconnectApplication(); + disconnectedCountDownLatch.countDown(); + } + }) { - // first start backend server - Backend.runProxy(serverPort, serverCreated, backend); - assertTrue(serverCreated.await(30, TimeUnit.SECONDS)); + CountDownLatch applicationServerCreated = new CountDownLatch(1); + backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown()); + assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + // start authenticator + IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger); + new HelloCommand(logger, "hello").handle(authenticatorToProxyStream); - // create virtual controller - int controllerPort = 7002; - ConfigurationImage controllerImage = prepareImage(240, createIniField(Fields.CYLINDERSCOUNT)); - CountDownLatch controllerCreated = new CountDownLatch(1); - TestHelper.createVirtualController(controllerImage, controllerPort, parameter -> controllerCreated.countDown(), logger); - assertTrue(controllerCreated.await(30, TimeUnit.SECONDS)); - - - // start network broadcaster to connect controller with backend since in real life controller has only local serial port it does not have network - IoStream targetEcuSocket = TestHelper.createTestStream(controllerPort, logger); - HelloCommand.send(targetEcuSocket, logger); - String controllerSignature = HelloCommand.getHelloResponse(targetEcuSocket.getDataBuffer(), logger); - - SessionDetails sessionDetails = MockRusEfiDevice.createTestSession(MockRusEfiDevice.TEST_TOKEN_1, controllerSignature); - - BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(new Socket(LOCALHOST, serverPort), - sessionDetails, - logger) { - // todo - }; - baseBroadcastingThread.start(); - + assertTrue(disconnectedCountDownLatch.await(30, TimeUnit.SECONDS)); + } } + @Test + public void testAuthenticatorRequestUnknownSession() throws InterruptedException, IOException { + int serverPortForRemoteUsers = 6800; + UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); + int httpPort = 8002; + + CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1); + + try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) { + @Override + protected void onDisconnectApplication() { + super.onDisconnectApplication(); + disconnectedCountDownLatch.countDown(); + } + }) { + + CountDownLatch applicationServerCreated = new CountDownLatch(1); + backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown()); + assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + + SessionDetails sessionDetails = MockRusEfiDevice.createTestSession(MockRusEfiDevice.TEST_TOKEN_1, Fields.TS_SIGNATURE); + ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, 123); + + // start authenticator + IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger); + LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(logger, applicationRequest); + localApplicationProxy.run(authenticatorToProxyStream); + + assertTrue(disconnectedCountDownLatch.await(30, TimeUnit.SECONDS)); + } + } } diff --git a/java_console/ui/src/test/java/com/rusefi/TestHelper.java b/java_console/ui/src/test/java/com/rusefi/TestHelper.java index c32c40c833..ddcb4f7638 100644 --- a/java_console/ui/src/test/java/com/rusefi/TestHelper.java +++ b/java_console/ui/src/test/java/com/rusefi/TestHelper.java @@ -11,7 +11,7 @@ import com.rusefi.io.LinkConnector; import com.rusefi.io.LinkManager; import com.rusefi.io.tcp.BinaryProtocolServer; import com.rusefi.io.tcp.TcpIoStream; -import com.rusefi.tools.online.ProxyClient; +import com.rusefi.server.rusEFISSLContext; import com.rusefi.tune.xml.Constant; import org.jetbrains.annotations.NotNull; @@ -19,16 +19,18 @@ import java.io.IOException; import java.net.Socket; public class TestHelper { + public static final String LOCALHOST = "localhost"; + @NotNull public static ScalarIniField createIniField(Field field) { - return new ScalarIniField(field.getName(), field.getOffset(), "", field.getType(), 1); + return new ScalarIniField(field.getName(), field.getOffset(), "", field.getType(), 1, "0"); } @NotNull public static ConfigurationImage prepareImage(int input, ScalarIniField scalarIniField) { ConfigurationImage ci = new ConfigurationImage(Fields.TOTAL_CONFIG_SIZE); - scalarIniField.setValue(ci, new Constant(scalarIniField.getName(), "", Integer.toString(input))); + scalarIniField.setValue(ci, new Constant(scalarIniField.getName(), "", Integer.toString(input), scalarIniField.getDigits())); return ci; } @@ -46,12 +48,23 @@ public class TestHelper { } @NotNull - public static IoStream createTestStream(int controllerPort, Logger logger) { + public static IoStream secureConnectToLocalhost(int controllerPort, Logger logger) { IoStream targetEcuSocket; try { - targetEcuSocket = new TcpIoStream(logger, new Socket(ProxyClient.LOCALHOST, controllerPort)); + targetEcuSocket = new TcpIoStream("[local]", logger, rusEFISSLContext.getSSLSocket(LOCALHOST, controllerPort)); } catch (IOException e) { - throw new IllegalStateException("Failed to connect to controller " + ProxyClient.LOCALHOST + ":" + controllerPort); + throw new IllegalStateException("Failed to connect to controller " + LOCALHOST + ":" + controllerPort); + } + return targetEcuSocket; + } + + @NotNull + public static IoStream connectToLocalhost(int controllerPort, Logger logger) { + IoStream targetEcuSocket; + try { + targetEcuSocket = new TcpIoStream("[local]", logger, new Socket(LOCALHOST, controllerPort)); + } catch (IOException e) { + throw new IllegalStateException("Failed to connect to controller " + LOCALHOST + ":" + controllerPort); } return targetEcuSocket; } diff --git a/java_console/ui/src/test/java/com/rusefi/io/TcpCommunicationIntegrationTest.java b/java_console/ui/src/test/java/com/rusefi/io/TcpCommunicationIntegrationTest.java index 46b5909845..4a60dec37d 100644 --- a/java_console/ui/src/test/java/com/rusefi/io/TcpCommunicationIntegrationTest.java +++ b/java_console/ui/src/test/java/com/rusefi/io/TcpCommunicationIntegrationTest.java @@ -8,7 +8,6 @@ import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.config.generated.Fields; import com.rusefi.io.tcp.BinaryProtocolProxy; import com.rusefi.io.tcp.BinaryProtocolServer; -import com.rusefi.tools.online.ProxyClient; import org.junit.Test; import java.util.Objects; @@ -61,7 +60,7 @@ public class TcpCommunicationIntegrationTest { // todo: remove CONFIGURATION_RUSEFI_BINARY or nicer API to disable local file load LinkManager clientManager = new LinkManager(LOGGER); - clientManager.startAndConnect(ProxyClient.LOCALHOST + ":" + port, new ConnectionStateListener() { + clientManager.startAndConnect(TestHelper.LOCALHOST + ":" + port, new ConnectionStateListener() { @Override public void onConnectionEstablished() { connectionEstablishedCountDownLatch.countDown(); @@ -82,7 +81,7 @@ public class TcpCommunicationIntegrationTest { String clientValue = iniField.getValue(clientImage); assertEquals(Double.toString(value), clientValue); - clientManager.stop(); + clientManager.close(); } @Test @@ -98,14 +97,14 @@ public class TcpCommunicationIntegrationTest { // connect proxy to virtual controller - IoStream targetEcuSocket = TestHelper.createTestStream(controllerPort, LOGGER); - BinaryProtocolProxy.createProxy(targetEcuSocket, proxyPort); + IoStream targetEcuSocket = TestHelper.connectToLocalhost(controllerPort, LOGGER); + BinaryProtocolProxy.createProxy(LOGGER, targetEcuSocket, proxyPort); CountDownLatch connectionEstablishedCountDownLatch = new CountDownLatch(1); // connect to proxy and read virtual controller through it LinkManager clientManager = new LinkManager(LOGGER); - clientManager.startAndConnect(ProxyClient.LOCALHOST + ":" + proxyPort, new ConnectionStateListener() { + clientManager.startAndConnect(TestHelper.LOCALHOST + ":" + proxyPort, new ConnectionStateListener() { @Override public void onConnectionEstablished() { connectionEstablishedCountDownLatch.countDown(); @@ -118,7 +117,7 @@ public class TcpCommunicationIntegrationTest { }); assertTrue("Connection established", connectionEstablishedCountDownLatch.await(30, TimeUnit.SECONDS)); - clientManager.stop(); + clientManager.close(); } } diff --git a/java_console/ui/src/test/java/com/rusefi/ui/TuneReadWriteTest.java b/java_console/ui/src/test/java/com/rusefi/ui/TuneReadWriteTest.java index 9421089de4..37d7551778 100644 --- a/java_console/ui/src/test/java/com/rusefi/ui/TuneReadWriteTest.java +++ b/java_console/ui/src/test/java/com/rusefi/ui/TuneReadWriteTest.java @@ -6,6 +6,7 @@ import com.opensr5.ini.field.IniField; import com.opensr5.io.ConfigurationImageFile; import com.rusefi.binaryprotocol.MsqFactory; import com.rusefi.config.generated.Fields; +import com.rusefi.tune.xml.Constant; import com.rusefi.tune.xml.Msq; import org.junit.Before; import org.junit.Test; @@ -14,6 +15,7 @@ import java.nio.file.Files; import java.nio.file.Path; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * from IDEA this unit test needs to be executed with "empty" working directory @@ -32,6 +34,11 @@ public class TuneReadWriteTest { public void testCompareBinaryToTSTune() throws Exception { Msq tsTune = Msq.readTune(PATH + "CurrentTune.msq"); System.out.println(tsTune); + assertNotNull("signature", tsTune.getVersionInfo().getSignature()); + + Constant flow = tsTune.findPage().findParameter("injector_flow"); + assertNotNull(flow); + assertEquals("2", flow.getDigits()); ConfigurationImage tsBinaryData = tsTune.asImage(IniFileModel.getInstance(), Fields.TOTAL_CONFIG_SIZE); @@ -53,8 +60,17 @@ public class TuneReadWriteTest { Msq tuneFromBinary = MsqFactory.valueOf(fileBinaryData); tuneFromBinary.writeXmlFile(fileName); + Constant batteryCorrection = tuneFromBinary.findPage().findParameter("injector_battLagCorrBins"); + assertNotNull(batteryCorrection); + assertEquals("2", batteryCorrection.getDigits()); + + Constant flow = tuneFromBinary.findPage().findParameter("injector_flow"); + assertNotNull(flow); + assertEquals("2", flow.getDigits()); + // and now reading that XML back Msq tuneFromFile = Msq.readTune(fileName); + assertNotNull(tuneFromFile.getVersionInfo().getSignature()); ConfigurationImage binaryDataFromXml = tuneFromFile.asImage(IniFileModel.getInstance(), Fields.TOTAL_CONFIG_SIZE); diff --git a/java_console/ui/src/test/resources/frankenso/mainController.ini b/java_console/ui/src/test/resources/frankenso/mainController.ini index 8e890d2e2b..41616496d2 100644 --- a/java_console/ui/src/test/resources/frankenso/mainController.ini +++ b/java_console/ui/src/test/resources/frankenso/mainController.ini @@ -849,7 +849,7 @@ page = 1 cj125CsPinMode = bits, U08, 2225, [0:7], "default", "default inverted", "open collector", "open collector inverted" dizzySparkOutputPin = bits, U08, 2226, [0:7], "NONE", "INVALID", "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6","PE7","PE8","PE9","PE10","PE11","PE12","PE13","PE14","PE15", "PF0","PF1","PF2","PF3","PF4","PF5","PF6","PF7","PF8","PF9","PF10","PF11","PF12","PF13","PF14","PF15", "PG0","PG1","PG2","PG3","PG4","PG5","PG6","PG7","PG8","PG9","PG10","PG11","PG12","PG13","PG14","PG15", "PH0","PH1","PH2","PH3","PH4","PH5","PH6","PH7","PH8","PH9","PH10","PH11","PH12","PH13","PH14","PH15","TLE6240_1", "TLE6240_2", "TLE6240_3", "TLE6240_4", "TLE6240_5", "TLE6240_6", "TLE6240_7", "TLE6240_8", "TLE6240_9", "TLE6240_10", "TLE6240_11", "TLE6240_12", "TLE6240_13", "TLE6240_14", "TLE6240_15", "TLE6240_16", "MC33972_1", "MC33972_2", "MC33972_3", "MC33972_4", "MC33972_5", "MC33972_6", "MC33972_7", "MC33972_8", "MC33972_9", "MC33972_10", "MC33972_11", "MC33972_12", "MC33972_13", "MC33972_14", "MC33972_15", "MC33972_16", "MC33972_17", "MC33972_18", "MC33972_19", "MC33972_20", "MC33972_21", "MC33972_22", "TLE8888_1", "TLE8888_2", "TLE8888_3", "TLE8888_4", "TLE8888_5", "TLE8888_6", "TLE8888_7", "TLE8888_8", "TLE8888_9", "TLE8888_10", "TLE8888_11", "TLE8888_12", "TLE8888_13", "TLE8888_14", "TLE8888_15", "TLE8888_16", "TLE8888_17", "TLE8888_18", "TLE8888_19", "TLE8888_20", "TLE8888_21", "TLE8888_22", "TLE8888_23", "TLE8888_24", "TLE8888_25", "TLE8888_26", "TLE8888_27", "TLE8888_28", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" dizzySparkOutputPinMode = bits, U08, 2227, [0:7], "default", "default inverted", "open collector", "open collector inverted" - crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, + crankingIACposition = scalar, S32, 2228, "percent", 1, 0, -100.0, 100, 0 tChargeMinRpmMinTps = scalar, F32, 2232, "mult", 1, 0, 0, 3, 4 tChargeMinRpmMaxTps = scalar, F32, 2236, "mult", 1, 0, 0, 3, 4 tChargeMaxRpmMinTps = scalar, F32, 2240, "mult", 1, 0, 0, 3, 4 diff --git a/java_console/ui/ui.iml b/java_console/ui/ui.iml index 07864d9b01..6e6a8fb20c 100644 --- a/java_console/ui/ui.iml +++ b/java_console/ui/ui.iml @@ -28,7 +28,7 @@ - + \ No newline at end of file diff --git a/java_console/upload_server.sh b/java_console/upload_server.sh new file mode 100755 index 0000000000..17bdaf3702 --- /dev/null +++ b/java_console/upload_server.sh @@ -0,0 +1,11 @@ +#!/bin/bash + + +if [ ! "$1" ] || [ ! "$2" ] || [ ! "$3" ]; then + echo "No Secrets" + exit 0 +fi + +echo -e "\nUploading plugin body" + +ncftpput -m -R -v -u "$1" -p "$2" "$3" autoupdate ../java_console_binary/rusefi_server.jar diff --git a/java_tools/ConfigDefinition.jar b/java_tools/ConfigDefinition.jar index 5563da07d4..4da6b20e07 100644 Binary files a/java_tools/ConfigDefinition.jar and b/java_tools/ConfigDefinition.jar differ diff --git a/java_tools/configuration_definition/src/com/rusefi/output/JavaFieldsConsumer.java b/java_tools/configuration_definition/src/com/rusefi/output/JavaFieldsConsumer.java index 45d2676f8f..af5917b355 100644 --- a/java_tools/configuration_definition/src/com/rusefi/output/JavaFieldsConsumer.java +++ b/java_tools/configuration_definition/src/com/rusefi/output/JavaFieldsConsumer.java @@ -1,5 +1,6 @@ package com.rusefi.output; +import com.opensr5.ini.IniFileModel; import com.rusefi.*; import java.io.CharArrayWriter; @@ -75,8 +76,14 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer { javaFieldsWriter.write("\tpublic static final String[] " + configField.getType() + " = {" + enumOptions + "};" + EOL); } + writeJavaFieldName(nameWithPrefix, tsPosition); - if (configField.getElementSize() == 1) { + if (isStringField(configField)) { + String custom = state.tsCustomLine.get(configField.getType()); + String[] tokens = custom.split(","); + String stringSize = tokens[3].trim(); + javaFieldsWriter.write(stringSize + ", FieldType.STRING"); + } else if (configField.getElementSize() == 1) { javaFieldsWriter.write("FieldType.INT8"); } else if (configField.getElementSize() == 2) { javaFieldsWriter.write("FieldType.INT16"); @@ -94,6 +101,11 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer { return tsPosition; } + private boolean isStringField(ConfigField configField) { + String custom = state.tsCustomLine.get(configField.getType()); + return custom != null && custom.toLowerCase().startsWith(IniFileModel.FIELD_TYPE_STRING); + } + public void handleEndStruct(ConfigStructure structure) throws IOException { if (state.stack.isEmpty()) { writeJavaFields(structure.tsFields, "", 0); diff --git a/java_tools/configuration_definition/src/com/rusefi/test/ConfigFieldParserTest.java b/java_tools/configuration_definition/src/com/rusefi/test/ConfigFieldParserTest.java index dbdb08317d..a5d8bd061c 100644 --- a/java_tools/configuration_definition/src/com/rusefi/test/ConfigFieldParserTest.java +++ b/java_tools/configuration_definition/src/com/rusefi/test/ConfigFieldParserTest.java @@ -4,13 +4,14 @@ import com.rusefi.ConfigField; import com.rusefi.ReaderState; import com.rusefi.TypesHelper; import com.rusefi.VariableRegistry; -import com.rusefi.output.ConfigurationConsumer; import com.rusefi.output.FsioSettingsConsumer; import com.rusefi.output.JavaFieldsConsumer; -import com.rusefi.output.TSProjectConsumer; import org.junit.Test; -import java.io.*; +import java.io.BufferedReader; +import java.io.CharArrayWriter; +import java.io.IOException; +import java.io.StringReader; import java.util.Arrays; import java.util.Collections; @@ -114,7 +115,7 @@ public class ConfigFieldParserTest { JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state); state.readBufferedReader(reader, Arrays.asList(javaFieldsConsumer)); - assertEquals("\tpublic static final Field VAR = Field.create(\"VAR\", 0, FieldType.INT);\n" + + assertEquals("\tpublic static final Field VAR = Field.create(\"VAR\", 0, 120, FieldType.STRING);\n" + "\tpublic static final Field PERIODMS = Field.create(\"PERIODMS\", 120, FieldType.INT16);\n", javaFieldsConsumer.getJavaFieldsWriter()); diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/LocalApplicationProxy.java b/java_tools/proxy_server/src/main/java/com/rusefi/LocalApplicationProxy.java new file mode 100644 index 0000000000..097a7421a6 --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/LocalApplicationProxy.java @@ -0,0 +1,43 @@ +package com.rusefi; + +import com.opensr5.Logger; +import com.rusefi.io.IoStream; +import com.rusefi.io.commands.HelloCommand; +import com.rusefi.io.tcp.BinaryProtocolProxy; +import com.rusefi.io.tcp.TcpIoStream; +import com.rusefi.server.ApplicationRequest; +import com.rusefi.server.rusEFISSLContext; +import com.rusefi.tools.online.HttpUtil; + +import java.io.IOException; + +public class LocalApplicationProxy { + private final Logger logger; + private final ApplicationRequest applicationRequest; + + public LocalApplicationProxy(Logger logger, ApplicationRequest applicationRequest) { + this.logger = logger; + this.applicationRequest = applicationRequest; + } + + /** + * @param serverPortForRemoteUsers port on which rusEFI proxy accepts authenticator connections + * @param applicationRequest remote session we want to connect to + * @param authenticatorPort local port we would bind for TunerStudio to connect to + */ + static void startAndRun(Logger logger, int serverPortForRemoteUsers, ApplicationRequest applicationRequest, int authenticatorPort) throws IOException { + IoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", logger, rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, serverPortForRemoteUsers)); + LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(logger, applicationRequest); + localApplicationProxy.run(authenticatorToProxyStream); + + BinaryProtocolProxy.createProxy(logger, authenticatorToProxyStream, authenticatorPort); + } + + public void run(IoStream authenticatorToProxyStream) throws IOException { + // right from connection push session authentication data + new HelloCommand(logger, applicationRequest.toJson()).handle(authenticatorToProxyStream); + } + + public static void start(String[] strings) { + } +} diff --git a/java_console/ui/src/test/java/com/rusefi/BaseBroadcastingThread.java b/java_tools/proxy_server/src/main/java/com/rusefi/proxy/BaseBroadcastingThread.java similarity index 80% rename from java_console/ui/src/test/java/com/rusefi/BaseBroadcastingThread.java rename to java_tools/proxy_server/src/main/java/com/rusefi/proxy/BaseBroadcastingThread.java index 554edef6c1..4af83c8aca 100644 --- a/java_console/ui/src/test/java/com/rusefi/BaseBroadcastingThread.java +++ b/java_tools/proxy_server/src/main/java/com/rusefi/proxy/BaseBroadcastingThread.java @@ -1,4 +1,4 @@ -package com.rusefi; +package com.rusefi.proxy; import com.opensr5.Logger; import com.rusefi.binaryprotocol.IncomingDataBuffer; @@ -18,7 +18,7 @@ public class BaseBroadcastingThread { private final Thread thread; public BaseBroadcastingThread(Socket socket, SessionDetails sessionDetails, Logger logger) throws IOException { - TcpIoStream stream = new TcpIoStream(logger, socket); + TcpIoStream stream = new TcpIoStream("[broadcast] ", logger, socket); IncomingDataBuffer in = stream.getDataBuffer(); thread = new Thread(() -> { @@ -33,9 +33,10 @@ public class BaseBroadcastingThread { byte command = payload[0]; if (command == Fields.TS_HELLO_COMMAND) { - new HelloCommand(logger, sessionDetails.toJson()).handle(packet, stream); + // respond on hello request with information about session + new HelloCommand(logger, sessionDetails.toJson()).handle(stream); } else { - handleCommand(); + handleCommand(packet, stream); } } } catch (IOException e) { @@ -44,7 +45,7 @@ public class BaseBroadcastingThread { }); } - protected void handleCommand() { + protected void handleCommand(BinaryProtocolServer.Packet packet, TcpIoStream stream) throws IOException { } public void start() { diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/proxy/NetworkConnector.java b/java_tools/proxy_server/src/main/java/com/rusefi/proxy/NetworkConnector.java new file mode 100644 index 0000000000..b22bef1227 --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/proxy/NetworkConnector.java @@ -0,0 +1,85 @@ +package com.rusefi.proxy; + +import com.opensr5.ConfigurationImage; +import com.opensr5.Logger; +import com.rusefi.config.generated.Fields; +import com.rusefi.io.ConnectionStateListener; +import com.rusefi.io.IoStream; +import com.rusefi.io.LinkManager; +import com.rusefi.io.commands.HelloCommand; +import com.rusefi.io.tcp.BinaryProtocolServer; +import com.rusefi.io.tcp.TcpIoStream; +import com.rusefi.server.ControllerInfo; +import com.rusefi.server.SessionDetails; +import com.rusefi.server.rusEFISSLContext; +import com.rusefi.tools.online.HttpUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * Connector between rusEFI ECU and rusEFI server + */ +public class NetworkConnector { + public static SessionDetails runNetworkConnector(String authToken, String controllerPort, int serverPortForControllers) throws InterruptedException, IOException { + LinkManager linkManager = new LinkManager(Logger.CONSOLE) + .setCompositeLogicEnabled(false) + .setNeedPullData(false); + + CountDownLatch onConnected = new CountDownLatch(1); + linkManager.startAndConnect(controllerPort, new ConnectionStateListener() { + @Override + public void onConnectionEstablished() { + onConnected.countDown(); + } + + @Override + public void onConnectionFailed() { + + } + }); + + System.out.println("Connecting to controller..."); + onConnected.await(1, TimeUnit.MINUTES); + if (onConnected.getCount() != 0) { + System.out.println("Connection to controller failed"); + return null; + } + + return runNetworkConnector(serverPortForControllers, linkManager, Logger.CONSOLE, authToken); + } + + @NotNull + private static SessionDetails runNetworkConnector(int serverPortForControllers, LinkManager linkManager, final Logger logger, String authToken) throws IOException { + IoStream targetEcuSocket = linkManager.getConnector().getBinaryProtocol().getStream(); + HelloCommand.send(targetEcuSocket, logger); + String controllerSignature = HelloCommand.getHelloResponse(targetEcuSocket.getDataBuffer(), logger).trim(); + + ConfigurationImage image = linkManager.getConnector().getBinaryProtocol().getControllerConfiguration(); + String vehicleName = Fields.VEHICLENAME.getStringValue(image); + String engineMake = Fields.ENGINEMAKE.getStringValue(image); + String engineCode = Fields.ENGINECODE.getStringValue(image); + //ControllerInfo ci = new ControllerInfo(vehicleName, engineMake, engineCode, controllerSignature); + + // todo: request vehicle info from controller + ControllerInfo ci = new ControllerInfo("vehicle", "make", "code", controllerSignature); + SessionDetails deviceSessionDetails = new SessionDetails(ci, authToken, SessionDetails.createOneTimeCode()); + + BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, serverPortForControllers), + deviceSessionDetails, + logger) { + @Override + protected void handleCommand(BinaryProtocolServer.Packet packet, TcpIoStream stream) throws IOException { + super.handleCommand(packet, stream); + targetEcuSocket.sendPacket(packet); + + BinaryProtocolServer.Packet response = targetEcuSocket.readPacket(); + stream.sendPacket(response); + } + }; + baseBroadcastingThread.start(); + return deviceSessionDetails; + } +} diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/ApplicationRequest.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/ApplicationRequest.java new file mode 100644 index 0000000000..ced6bf9740 --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/ApplicationRequest.java @@ -0,0 +1,66 @@ +package com.rusefi.server; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.stream.JsonParsingException; +import java.io.StringReader; +import java.util.Objects; + +public class ApplicationRequest { + private static final String SESSION = "session"; + private static final String USER_ID = "user_id"; + + private final SessionDetails sessionDetails; + private final int targetUserId; + + public ApplicationRequest(SessionDetails sessionDetails, int targetUserId) { + this.sessionDetails = sessionDetails; + this.targetUserId = targetUserId; + } + + public SessionDetails getSessionDetails() { + return sessionDetails; + } + + public int getTargetUserId() { + return targetUserId; + } + + public String toJson() { + JsonObject jsonObject = Json.createObjectBuilder() + .add(SESSION, sessionDetails.toJson()) + .add(USER_ID, targetUserId) + .build(); + return jsonObject.toString(); + } + + public static ApplicationRequest valueOf(String jsonString) { + JsonReader reader = Json.createReader(new StringReader(jsonString)); + + JsonObject jsonObject; + try { + jsonObject = reader.readObject(); + } catch (JsonParsingException e) { + throw new IllegalStateException("While parsing [" + jsonString + "]", e); + } + int targetUserId = jsonObject.getInt(USER_ID); + + SessionDetails session = SessionDetails.valueOf(jsonObject.getString(SESSION)); + return new ApplicationRequest(session, targetUserId); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ApplicationRequest that = (ApplicationRequest) o; + return targetUserId == that.targetUserId && + sessionDetails.equals(that.sessionDetails); + } + + @Override + public int hashCode() { + return Objects.hash(sessionDetails, targetUserId); + } +} diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/Backend.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/Backend.java index d1b31bc132..2de047dd76 100644 --- a/java_tools/proxy_server/src/main/java/com/rusefi/server/Backend.java +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/Backend.java @@ -1,102 +1,86 @@ package com.rusefi.server; import com.opensr5.Logger; +import com.rusefi.Listener; +import com.rusefi.io.IoStream; +import com.rusefi.io.commands.HelloCommand; +import com.rusefi.io.tcp.BinaryProtocolProxy; import com.rusefi.io.tcp.BinaryProtocolServer; +import com.rusefi.io.tcp.TcpIoStream; import com.rusefi.tools.online.ProxyClient; import org.jetbrains.annotations.NotNull; import org.takes.Take; import org.takes.facets.fork.FkRegex; import org.takes.facets.fork.TkFork; -import org.takes.http.Exit; import org.takes.http.FtBasic; +import org.takes.rs.RsHtml; import org.takes.rs.RsJson; import javax.json.Json; import javax.json.JsonArrayBuilder; import javax.json.JsonObject; +import java.io.Closeable; import java.io.IOException; +import java.net.BindException; import java.net.Socket; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CountDownLatch; +import java.util.*; +import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; -public class Backend { +public class Backend implements Closeable { public static final String VERSION_PATH = "/version"; public static final String BACKEND_VERSION = "0.0001"; + public static final int SERVER_PORT_FOR_APPLICATIONS = 8002; + public static final int SERVER_PORT_FOR_CONTROLLERS = 8003; private final FkRegex showOnlineUsers = new FkRegex(ProxyClient.LIST_PATH, (Take) req -> getUsersOnline() ); - - public static void runProxy(int serverPort, CountDownLatch serverCreated, Backend backend) { - BinaryProtocolServer.tcpServerSocket(serverPort, "Server", new Function() { - @Override - public Runnable apply(Socket clientSocket) { - return new Runnable() { - @Override - public void run() { - ClientConnectionState clientConnectionState = new ClientConnectionState(clientSocket, backend.logger, backend.getUserDetailsResolver()); - try { - clientConnectionState.requestControllerInfo(); - - backend.register(clientConnectionState); - clientConnectionState.runEndlessLoop(); - } catch (IOException e) { - backend.close(clientConnectionState); - } - } - }; - } - }, backend.logger, parameter -> serverCreated.countDown()); - } - - @NotNull - private RsJson getUsersOnline() throws IOException { - JsonArrayBuilder builder = Json.createArrayBuilder(); - List clients = getClients(); - for (ClientConnectionState client : clients) { - - JsonObject clientObject = Json.createObjectBuilder() - .add(UserDetails.USER_ID, client.getUserDetails().getUserId()) - .add(UserDetails.USERNAME, client.getUserDetails().getUserName()) - .add(ControllerInfo.SIGNATURE, client.getSessionDetails().getControllerInfo().getSignature()) - .build(); - builder.add(clientObject); - } - return new RsJson(builder.build()); - } + private boolean isClosed; // guarded by own monitor - private final Set clients = new HashSet<>(); + private final Set clients = new HashSet<>(); + // guarded by clients + private HashMap byId = new HashMap<>(); // private final int clientTimeout; - private final Function userDetailsResolver; + private final UserDetailsResolver userDetailsResolver; private final Logger logger; + public final static AtomicLong totalSessions = new AtomicLong(); - public Backend(Function userDetailsResolver, int httpPort, Logger logger) { + public Backend(UserDetailsResolver userDetailsResolver, int httpPort, Logger logger) { // this.clientTimeout = clientTimeout; this.userDetailsResolver = userDetailsResolver; this.logger = logger; - new Thread(new Runnable() { - @Override - public void run() { + new Thread(() -> { + try { + System.out.println("Starting http backend on " + httpPort); try { new FtBasic( new TkFork(showOnlineUsers, + Monitoring.showStatistics, new FkRegex(VERSION_PATH, BACKEND_VERSION), - new FkRegex("/", "rusEFI Online") + new FkRegex("/", new RsHtml("\n" + + "rusEFI Online\n" + + "
\n" + + "Status\n" + + "
\n" + + "List\n" + + "
\n" + + "
\n" + + "\n")) ), httpPort - ).start(Exit.NEVER); - } catch (IOException e) { - throw new IllegalStateException(e); + ).start(() -> isClosed); + } catch (BindException e) { + throw new IllegalStateException("While binding " + httpPort, e); } - + logger.info("Shutting down backend on port " + httpPort); + } catch (IOException e) { + throw new IllegalStateException(e); } - }).start(); + + }, "Http Server Thread").start(); // new Thread(() -> { @@ -107,7 +91,106 @@ public class Backend { // }, "rusEFI Server Cleanup").start(); } - public Function getUserDetailsResolver() { + public void runApplicationConnector(int serverPortForApplications, Listener serverSocketCreationCallback) { + // connection from authenticator app which proxies for Tuner Studio + // authenticator pushed hello packet on connect + System.out.println("Starting application connector at " + serverPortForApplications); + BinaryProtocolServer.tcpServerSocket(logger, new Function() { + @Override + public Runnable apply(Socket applicationSocket) { + return new Runnable() { + @Override + public void run() { + totalSessions.incrementAndGet(); + // connection from authenticator app which proxies for Tuner Studio + IoStream applicationClientStream = null; + try { + applicationClientStream = new TcpIoStream("[app] ", logger, applicationSocket); + + // authenticator pushed hello packet on connect + String jsonString = HelloCommand.getHelloResponse(applicationClientStream.getDataBuffer(), logger); + if (jsonString == null) + return; + ApplicationRequest applicationRequest = ApplicationRequest.valueOf(jsonString); + logger.info("Application Connected: " + applicationRequest); + + ControllerKey controllerKey = new ControllerKey(applicationRequest.getTargetUserId(), applicationRequest.getSessionDetails().getControllerInfo()); + ControllerConnectionState state; + synchronized (clients) { + state = byId.get(controllerKey); + } + if (state == null) { + applicationClientStream.close(); + onDisconnectApplication(); + logger.info("No controller for " + controllerKey); + return; + } + + BinaryProtocolProxy.runProxy(state.getStream(), applicationClientStream); + + } catch (Throwable e) { + if (applicationClientStream != null) + applicationClientStream.close(); + e.printStackTrace(); + logger.info("Got error " + e); + onDisconnectApplication(); + } + } + }; + } + }, serverPortForApplications, "ApplicationServer", serverSocketCreationCallback, BinaryProtocolServer.SECURE_SOCKET_FACTORY); + } + + protected void onDisconnectApplication() { + logger.info("Disconnecting application"); + } + + public void runControllerConnector(int serverPortForControllers, Listener serverSocketCreationCallback) { + System.out.println("Starting controller connector at " + serverPortForControllers); + BinaryProtocolServer.tcpServerSocket(logger, new Function() { + @Override + public Runnable apply(Socket controllerSocket) { + return new Runnable() { + @Override + public void run() { + totalSessions.incrementAndGet(); + ControllerConnectionState controllerConnectionState = new ControllerConnectionState(controllerSocket, logger, getUserDetailsResolver()); + try { + controllerConnectionState.requestControllerInfo(); + + // IMPORTANT: has to happen before we register controller while we still have exclusive access + controllerConnectionState.getOutputs(); + + register(controllerConnectionState); + } catch (Throwable e) { + close(controllerConnectionState); + } + } + }; + } + }, serverPortForControllers, "ControllerServer", serverSocketCreationCallback, BinaryProtocolServer.SECURE_SOCKET_FACTORY); + } + + @NotNull + private RsJson getUsersOnline() throws IOException { + JsonArrayBuilder builder = Json.createArrayBuilder(); + List clients = getClients(); + for (ControllerConnectionState client : clients) { + + JsonObject clientObject = Json.createObjectBuilder() + .add(UserDetails.USER_ID, client.getUserDetails().getUserId()) + .add(UserDetails.USERNAME, client.getUserDetails().getUserName()) + .add(ControllerInfo.SIGNATURE, client.getSessionDetails().getControllerInfo().getSignature()) + .add(ControllerInfo.VEHICLE_NAME, client.getSessionDetails().getControllerInfo().getVehicleName()) + .add(ControllerInfo.ENGINE_MAKE, client.getSessionDetails().getControllerInfo().getEngineMake()) + .add(ControllerInfo.ENGINE_CODE, client.getSessionDetails().getControllerInfo().getEngineCode()) + .build(); + builder.add(clientObject); + } + return new RsJson(builder.build()); + } + + public UserDetailsResolver getUserDetailsResolver() { return userDetailsResolver; } @@ -128,21 +211,33 @@ public class Backend { // // } - public void register(ClientConnectionState clientConnectionState) { + public void register(ControllerConnectionState controllerConnectionState) { + Objects.requireNonNull(controllerConnectionState.getControllerKey(), "ControllerKey"); synchronized (clients) { - clients.add(clientConnectionState); + clients.add(controllerConnectionState); + byId.put(controllerConnectionState.getControllerKey(), controllerConnectionState); } + onRegister(controllerConnectionState); } - public void close(ClientConnectionState inactiveClient) { + protected void onRegister(ControllerConnectionState controllerConnectionState) { + } + + public void close(ControllerConnectionState inactiveClient) { inactiveClient.close(); synchronized (clients) { // in case of exception in the initialization phase we do not even add client into the the collection clients.remove(inactiveClient); + byId.remove(inactiveClient.getControllerKey()); } } - public List getClients() { + @Override + public void close() { + isClosed = true; + } + + public List getClients() { synchronized (clients) { return new ArrayList<>(clients); } @@ -153,4 +248,5 @@ public class Backend { return clients.size(); } } + } diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/BackendLauncher.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/BackendLauncher.java new file mode 100644 index 0000000000..7ca88cb87f --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/BackendLauncher.java @@ -0,0 +1,26 @@ +package com.rusefi.server; + +import com.opensr5.Logger; +import com.rusefi.tools.online.HttpUtil; + +import java.net.MalformedURLException; + +public class BackendLauncher { + /** + * need this method to be not in Backend class for console to work without all backend classes + */ + public static void start(String[] args) throws MalformedURLException { + /* todo + rusEFISSLContext.setupCertificates(new File("keystore.jks"), System.getProperty("RUSEFI_PROXY_PASSWORD")); + */ + + UserDetailsResolver userDetailsFunction = new JsonUserDetailsResolver(); + + Backend backend = new Backend(userDetailsFunction, HttpUtil.HTTP_PORT, Logger.CONSOLE); + backend.runApplicationConnector(Backend.SERVER_PORT_FOR_APPLICATIONS, parameter -> { + }); + backend.runControllerConnector(Backend.SERVER_PORT_FOR_CONTROLLERS, parameter -> { + }); + + } +} diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/ClientConnectionState.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerConnectionState.java similarity index 68% rename from java_tools/proxy_server/src/main/java/com/rusefi/server/ClientConnectionState.java rename to java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerConnectionState.java index 2a7b342206..22e771219b 100644 --- a/java_tools/proxy_server/src/main/java/com/rusefi/server/ClientConnectionState.java +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerConnectionState.java @@ -11,12 +11,11 @@ import com.rusefi.io.tcp.TcpIoStream; import java.io.Closeable; import java.io.IOException; import java.net.Socket; -import java.util.function.Function; -public class ClientConnectionState { +public class ControllerConnectionState { private final Socket clientSocket; private final Logger logger; - private final Function userDetailsResolver; + private final UserDetailsResolver userDetailsResolver; private boolean isClosed; private IoStream stream; @@ -29,23 +28,27 @@ public class ClientConnectionState { * user info from rusEFI database based on auth token */ private UserDetails userDetails; + private ControllerKey controllerKey; - public ClientConnectionState(Socket clientSocket, Logger logger, Function userDetailsResolver) { + public ControllerConnectionState(Socket clientSocket, Logger logger, UserDetailsResolver userDetailsResolver) { this.clientSocket = clientSocket; this.logger = logger; this.userDetailsResolver = userDetailsResolver; try { - stream = new TcpIoStream(logger, clientSocket); + stream = new TcpIoStream("[controller] ", logger, clientSocket); incomingData = stream.getDataBuffer(); } catch (IOException e) { close(); } } -// public long getLastActivityTimestamp() { -// return lastActivityTimestamp; -// } + public IoStream getStream() { + return stream; + } + public ControllerKey getControllerKey() { + return controllerKey; + } public boolean isClosed() { return isClosed; @@ -67,6 +70,10 @@ public class ClientConnectionState { logger.info(sessionDetails.getAuthToken() + " New client: " + sessionDetails.getControllerInfo()); userDetails = userDetailsResolver.apply(sessionDetails.getAuthToken()); + if (userDetails == null) { + throw new IOException("Unable to resolve " + sessionDetails.getAuthToken()); + } + controllerKey = new ControllerKey(userDetails.getUserId(), sessionDetails.getControllerInfo()); logger.info("User " + userDetails); } @@ -91,14 +98,18 @@ public class ClientConnectionState { public void runEndlessLoop() throws IOException { while (true) { - byte[] commandPacket = GetOutputsCommand.createRequest(); - - stream.sendPacket(commandPacket, logger); - - byte[] packet = incomingData.getPacket(logger, "msg", true); - if (packet == null) - throw new IOException("No response"); + getOutputs(); } } + + public void getOutputs() throws IOException { + byte[] commandPacket = GetOutputsCommand.createRequest(); + + stream.sendPacket(commandPacket, logger); + + byte[] packet = incomingData.getPacket(logger, "msg", true); + if (packet == null) + throw new IOException("No response"); + } } diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerKey.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerKey.java new file mode 100644 index 0000000000..1188b9ab8c --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/ControllerKey.java @@ -0,0 +1,35 @@ +package com.rusefi.server; + +import java.util.Objects; + +public class ControllerKey { + private final int userId; + private final ControllerInfo controllerInfo; + + public ControllerKey(int userId, ControllerInfo controllerInfo) { + this.userId = userId; + this.controllerInfo = controllerInfo; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ControllerKey that = (ControllerKey) o; + return userId == that.userId && + controllerInfo.equals(that.controllerInfo); + } + + @Override + public int hashCode() { + return Objects.hash(userId, controllerInfo); + } + + @Override + public String toString() { + return "ControllerKey{" + + "userId=" + userId + + ", controllerInfo=" + controllerInfo + + '}'; + } +} diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/JsonUserDetailsResolver.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/JsonUserDetailsResolver.java new file mode 100644 index 0000000000..dfbb893eb6 --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/JsonUserDetailsResolver.java @@ -0,0 +1,38 @@ +package com.rusefi.server; + +import com.rusefi.tools.online.HttpUtil; +import org.apache.http.HttpResponse; +import org.jetbrains.annotations.Nullable; +import org.json.simple.JSONObject; +import org.json.simple.parser.ParseException; + +import java.io.IOException; + +public class JsonUserDetailsResolver implements UserDetailsResolver { + @Override + @Nullable + public UserDetails apply(String authToken) { + + try { + HttpResponse response = HttpUtil.executeGet(HttpUtil.RUSEFI_ONLINE_JSON_API_PREFIX + "getUserByToken&rusefi_token=" + authToken); + JSONObject json = HttpUtil.getJsonResponse(response); + System.out.println("String " + json); + Object getUserByToken = json.get("getUserByToken"); + if (getUserByToken instanceof String) { + System.out.println("AUTH FAILED: Result " + getUserByToken); + return null; + } + JSONObject details = (JSONObject) getUserByToken; + String id = (String) details.get("ID"); + String name = (String) details.get("NAME"); + + UserDetails result = new UserDetails(name, Integer.parseInt(id)); + System.out.println("AUTH SUCCESS " + result); + return result; + } catch (IOException | ParseException e) { + System.out.println("JsonUserDetailsResolver error" + e); + e.printStackTrace(); + return null; + } + } +} diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/Monitoring.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/Monitoring.java new file mode 100644 index 0000000000..90d8f74dca --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/Monitoring.java @@ -0,0 +1,36 @@ +package com.rusefi.server; + +import org.takes.Take; +import org.takes.facets.fork.FkRegex; +import org.takes.rs.RsJson; + +import javax.json.Json; +import javax.json.JsonObjectBuilder; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.OperatingSystemMXBean; + +public class Monitoring { + public static final String STATUS = "/status"; + static final FkRegex showStatistics = new FkRegex(STATUS, + (Take) req -> Monitoring.getStatus()); + + + private static String formatSize(long v) { + if (v < 1024) return v + " B"; + int z = (63 - Long.numberOfLeadingZeros(v)) / 10; + return String.format("%.1f %sB", (double) v / (1L << (z * 10)), " KMGTPE".charAt(z)); + } + + private static RsJson getStatus() throws IOException { + JsonObjectBuilder builder = Json.createObjectBuilder(); + OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); + builder.add("CPU_Load", operatingSystemMXBean.getSystemLoadAverage()); + builder.add("free_ram", formatSize(Runtime.getRuntime().freeMemory())); + builder.add("max_ram", formatSize(Runtime.getRuntime().maxMemory())); + builder.add("threads", Thread.getAllStackTraces().size()); + builder.add("sessions", Backend.totalSessions.get()); + + return new RsJson(builder.build()); + } +} diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/UserDetailsResolver.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/UserDetailsResolver.java new file mode 100644 index 0000000000..e2c567c9e7 --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/UserDetailsResolver.java @@ -0,0 +1,6 @@ +package com.rusefi.server; + +import java.util.function.Function; + +public interface UserDetailsResolver extends Function { +} diff --git a/java_tools/proxy_server/src/test/java/com/rusefi/server/JsonUserDetailsResolverSandbox.java b/java_tools/proxy_server/src/test/java/com/rusefi/server/JsonUserDetailsResolverSandbox.java new file mode 100644 index 0000000000..d5069952b9 --- /dev/null +++ b/java_tools/proxy_server/src/test/java/com/rusefi/server/JsonUserDetailsResolverSandbox.java @@ -0,0 +1,9 @@ +package com.rusefi.server; + +public class JsonUserDetailsResolverSandbox { + public static void main(String[] args) { + JsonUserDetailsResolver resolver = new JsonUserDetailsResolver(); + + System.out.println("UserDetails result: " + resolver.apply("haba-haba")); + } +} diff --git a/java_tools/proxy_server/src/test/java/com/rusefi/server/SessionDetailsTest.java b/java_tools/proxy_server/src/test/java/com/rusefi/server/SessionDetailsTest.java index bce93d0b9e..64c5543254 100644 --- a/java_tools/proxy_server/src/test/java/com/rusefi/server/SessionDetailsTest.java +++ b/java_tools/proxy_server/src/test/java/com/rusefi/server/SessionDetailsTest.java @@ -8,14 +8,21 @@ public class SessionDetailsTest { @Test public void testSerialization() { ControllerInfo ci = new ControllerInfo("name", "make", "code", "sign"); - SessionDetails sd = new SessionDetails(ci, "auth", 123); String json = sd.toJson(); - SessionDetails fromJson = SessionDetails.valueOf(json); - assertEquals(sd, fromJson); } + @Test + public void testApplcationRequest() { + ControllerInfo ci = new ControllerInfo("name", "make", "code", "sign"); + SessionDetails sd = new SessionDetails(ci, "auth", 123); + ApplicationRequest ar = new ApplicationRequest(sd, 321); + + String json = ar.toJson(); + ApplicationRequest fromJson = ApplicationRequest.valueOf(json); + assertEquals(ar, fromJson); + } } diff --git a/java_tools/ts_plugin/build.xml b/java_tools/ts_plugin/build.xml index a9968f786a..bfc068788e 100644 --- a/java_tools/ts_plugin/build.xml +++ b/java_tools/ts_plugin/build.xml @@ -13,17 +13,19 @@ + - + + diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadQueue.java b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadQueue.java deleted file mode 100644 index a7bd7e166a..0000000000 --- a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadQueue.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.rusefi.ts_plugin; - -import com.efiAnalytics.plugin.ecu.ControllerAccess; -import com.rusefi.tune.xml.Msq; - -public class UploadQueue { - public static void enqueue(ControllerAccess controllerAccess, String configurationName) { - Msq msq = TuneUploder.grabTune(controllerAccess, configurationName); - } -} diff --git a/java_tools/ts_plugin/src/com/rusefi/TsTuneReader.java b/java_tools/ts_plugin/src/main/java/com/rusefi/TsTuneReader.java similarity index 100% rename from java_tools/ts_plugin/src/com/rusefi/TsTuneReader.java rename to java_tools/ts_plugin/src/main/java/com/rusefi/TsTuneReader.java diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/BroadcastTab.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/BroadcastTab.java new file mode 100644 index 0000000000..e7e52ea0ea --- /dev/null +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/BroadcastTab.java @@ -0,0 +1,11 @@ +package com.rusefi.ts_plugin; + +import javax.swing.*; + +public class BroadcastTab { + private final JComponent content = new JPanel(); + + public JComponent getContent() { + return content; + } +} diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/LogUploadSelector.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/LogUploadSelector.java similarity index 100% rename from java_tools/ts_plugin/src/com/rusefi/ts_plugin/LogUploadSelector.java rename to java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/LogUploadSelector.java diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/MetaDataCache.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/MetaDataCache.java similarity index 100% rename from java_tools/ts_plugin/src/com/rusefi/ts_plugin/MetaDataCache.java rename to java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/MetaDataCache.java diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/PluginEntry.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/PluginEntry.java new file mode 100644 index 0000000000..c002038a25 --- /dev/null +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/PluginEntry.java @@ -0,0 +1,64 @@ +package com.rusefi.ts_plugin; + +import com.efiAnalytics.plugin.ecu.ControllerAccess; +import com.rusefi.ts_plugin.util.ManifestHelper; +import com.rusefi.tune.xml.Constant; + +import javax.swing.*; +import java.util.function.Supplier; + +/** + * TsPlugin launcher creates an instance of this class via reflection. + */ +public class PluginEntry implements TsPluginBody { + private final JTabbedPane tabbedPane = new JTabbedPane(); + + /** + * the real constructor - this one is invoked via reflection + */ + public PluginEntry() { + this(ControllerAccess::getInstance); + } + + public PluginEntry(Supplier controllerAccessSupplier) { + System.out.println("PluginEntry init " + this); + + UploadTab uploadTab = new UploadTab(controllerAccessSupplier); + BroadcastTab broadcastTab = new BroadcastTab(); + RemoteTab remoteTab = new RemoteTab(); + + tabbedPane.addTab("Upload", uploadTab.getContent()); + tabbedPane.addTab("Broadcast", broadcastTab.getContent()); + tabbedPane.addTab("Remote ECU", remoteTab.getContent()); + } + + public static boolean isEmpty(Constant constant) { + if (constant == null) + return true; + return isEmpty(constant.getValue()); + } + + private static boolean isEmpty(String value) { + return value == null || value.trim().length() == 0; + } + + @Override + public JComponent getContent() { + return tabbedPane; + } +/* + public void close() { + PersistentConfiguration.getConfig().save(); + } +*/ + + /** + * this method is invoked by refection + * + * @see TsPluginBody#GET_VERSION + */ + @SuppressWarnings("unused") + public static String getVersion() { + return ManifestHelper.getVersion(); + } +} diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/RemoteTab.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/RemoteTab.java new file mode 100644 index 0000000000..b9bad90d30 --- /dev/null +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/RemoteTab.java @@ -0,0 +1,57 @@ +package com.rusefi.ts_plugin; + +import com.rusefi.NamedThreadFactory; +import com.rusefi.server.UserDetails; +import com.rusefi.tools.online.HttpUtil; +import com.rusefi.tools.online.ProxyClient; +import org.apache.http.HttpResponse; + +import javax.swing.*; +import java.awt.*; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +public class RemoteTab { + private final JComponent content = new JPanel(new BorderLayout()); + + private final JButton refresh = new JButton("Refresh List"); + + private final Executor listDownloadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("online list downloader")); + + public RemoteTab() { + + JPanel topPanel = new JPanel(new FlowLayout()); + + topPanel.add(refresh); + + refresh.addActionListener(e -> requestListDownload()); + + content.add(topPanel, BorderLayout.NORTH); + requestListDownload(); + } + + private void requestListDownload() { + listDownloadExecutor.execute(new Runnable() { + @Override + public void run() { + String url = HttpUtil.RUSEFI_PROXY_JSON_API_PREFIX + "/list_online"; + + List userDetails; + try { + userDetails = ProxyClient.getOnlineUsers(HttpUtil.HTTP_PORT); + } catch (IOException e) { + e.printStackTrace(); + return; + } + System.out.println(userDetails); + + } + }); + } + + public JComponent getContent() { + return content; + } +} diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/TuneUploder.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/TuneUploder.java similarity index 99% rename from java_tools/ts_plugin/src/com/rusefi/ts_plugin/TuneUploder.java rename to java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/TuneUploder.java index 06b0c3cc8d..7b2c0d9bd9 100644 --- a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/TuneUploder.java +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/TuneUploder.java @@ -108,7 +108,7 @@ public class TuneUploder { } Page page = msq.findPage(); - page.constant.add(new Constant(parameterName, cp.getUnits(), value)); + page.constant.add(new Constant(parameterName, cp.getUnits(), value, Integer.toString(cp.getDecimalPlaces()))); } private static String getArrayValue(double[][] arrayValues) { diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadQueue.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadQueue.java new file mode 100644 index 0000000000..448bc3d4b8 --- /dev/null +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadQueue.java @@ -0,0 +1,95 @@ +package com.rusefi.ts_plugin; + +import com.efiAnalytics.plugin.ecu.ControllerAccess; +import com.rusefi.shared.FileUtil; +import com.rusefi.tools.online.Online; +import com.rusefi.tools.online.UploadResult; +import com.rusefi.tune.xml.Msq; +import com.rusefi.ui.AuthTokenPanel; + +import javax.xml.bind.JAXBException; +import java.io.File; +import java.io.IOException; +import java.util.Objects; +import java.util.concurrent.LinkedBlockingDeque; + +public class UploadQueue { + public static final String OUTBOX_FOLDER = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + "outbox"; + private static LinkedBlockingDeque queue = new LinkedBlockingDeque<>(128); + + private static boolean isStarted; + + public synchronized static void start() { + if (isStarted) + return; + isStarted = true; + readOutbox(); + new Thread(() -> { + try { + uploadLoop(); + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + }, "Positing Thread").start(); + } + + private static void readOutbox() { + for (String file : Objects.requireNonNull(new File(OUTBOX_FOLDER).list((dir, name) -> name.endsWith(".msq")))) { + if (queue.size() > 90) + return; + System.out.println(UploadQueue.class.getSimpleName() + " readOutbox " + file); + try { + String fileName = OUTBOX_FOLDER + File.separator + file; + queue.put(fileName); + } catch (Exception e) { + e.printStackTrace(); + } + } + System.out.println(UploadQueue.class.getSimpleName() + " readOutbox got " + queue.size()); + } + + private static void uploadLoop() throws InterruptedException { + while (true) { + String fileName = queue.take(); + + UploadResult result = Online.upload(new File(fileName), AuthTokenPanel.getAuthToken()); + System.out.println("isError " + result.isError()); + System.out.println("first " + result.getFirstMessage()); + if (result.isError() && result.getFirstMessage().contains("This file already exists")) { + System.out.println(UploadQueue.class.getSimpleName() + " No need to re-try this one"); + delete(fileName); + // do not retry this error + continue; + } + if (result.isError()) { + System.out.println(UploadQueue.class.getSimpleName() + " Re-queueing " + fileName); + queue.put(fileName); + continue; + } + delete(fileName); + } + } + + private static void delete(String fileName) { + System.out.println(UploadQueue.class.getSimpleName() + " Deleting " + fileName); + new File(fileName).delete(); + } + + public static void enqueue(ControllerAccess controllerAccess, String configurationName) { + start(); + if (queue.size() > 100) { + // too much pending drama + return; + } + Msq msq = TuneUploder.grabTune(controllerAccess, configurationName); + msq.bibliography.setTuneComment("Auto-saved"); + try { + new File(OUTBOX_FOLDER).mkdirs(); + String fileName = OUTBOX_FOLDER + File.separator + System.currentTimeMillis() + ".msq"; + msq.writeXmlFile(fileName); + queue.put(fileName); + } catch (InterruptedException | JAXBException | IOException e) { + throw new IllegalStateException(e); + } + } +} diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadTab.java similarity index 84% rename from java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java rename to java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadTab.java index 9fec24ef0f..9862103691 100644 --- a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadTab.java @@ -11,7 +11,6 @@ import com.rusefi.config.generated.Fields; import com.rusefi.tools.online.Online; import com.rusefi.tools.online.UploadResult; import com.rusefi.ts_plugin.util.ManifestHelper; -import com.rusefi.tune.xml.Constant; import com.rusefi.tune.xml.Msq; import com.rusefi.ui.AuthTokenPanel; import com.rusefi.ui.util.URLLabel; @@ -21,54 +20,50 @@ import org.putgemin.VerticalFlowLayout; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.util.Date; import java.util.Map; import java.util.function.Supplier; -/** - * TsPlugin launcher creates an instance of this class via reflection. - */ -public class PluginEntry implements TsPluginBody { +public class UploadTab { + private final JComponent content = new JPanel(new VerticalFlowLayout()); + // 2 seconds aggregation by default + private static final int AUTO_UPDATE_AGGREGATION = Integer.parseInt(System.getProperty("autoupload.aggregation", "2000")); + private static final String REO_URL = "https://rusefi.com/online/"; private final AuthTokenPanel tokenPanel = new AuthTokenPanel(); - private final JComponent content = new JPanel(new VerticalFlowLayout()); + private final Supplier controllerAccessSupplier; private final UploadView uploadView = new UploadView(); private final JButton upload = new JButton("Upload Current Tune"); - private final Supplier controllerAccessSupplier; private String currentConfiguration; private UploaderStatus uploaderStatus = new UploaderStatus(); - private final Timer timer = new Timer(1000 /* one second */, new AbstractAction() { + private final Timer timer = new Timer(AUTO_UPDATE_AGGREGATION, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { - System.out.println("Timer! " + System.currentTimeMillis() + " " + timer + " " + e); +// System.out.println("Timer! " + System.currentTimeMillis() + " " + timer + " " + e); + if (UploadView.isAutoUpload()) { + System.out.println(new Date() + ": enqueue tune"); + UploadQueue.enqueue(controllerAccessSupplier.get(), currentConfiguration); + } } }); private final ControllerParameterChangeListener listener; - /** - * the real constructor - this one is invoked via reflection - */ - public PluginEntry() { - this(ControllerAccess::getInstance); - } + public UploadTab(Supplier controllerAccessSupplier) { + this.controllerAccessSupplier = controllerAccessSupplier; - public PluginEntry(Supplier controllerAccessSupplier) { - System.out.println("PluginEntry init " + this); timer.stop(); timer.setRepeats(false); - this.controllerAccessSupplier = controllerAccessSupplier; + UploadQueue.start(); listener = parameterName -> { // System.out.println("Parameter value changed " + parameterName); timer.restart(); - if (UploadView.isAutoUpload()) { - UploadQueue.enqueue(controllerAccessSupplier.get(), currentConfiguration); - } }; upload.setBackground(new Color(0x90EE90)); @@ -140,7 +135,7 @@ public class PluginEntry implements TsPluginBody { } }); - content.add(new JLabel(ManifestHelper.getBuildTimestamp())); + content.add(new JLabel("Version " + ManifestHelper.getBuildTimestamp())); // content.add(new JLabel("Active project: " + getConfigurationName())); @@ -151,6 +146,7 @@ public class PluginEntry implements TsPluginBody { content.add(new JLabel(LOGO)); content.add(tokenPanel.getContent()); content.add(new URLLabel(REO_URL)); + } /** @@ -168,6 +164,12 @@ public class PluginEntry implements TsPluginBody { currentConfiguration = configurationName; } + private void updateUploadEnabled() { + uploadView.update(uploaderStatus); + + upload.setEnabled(uploaderStatus.isTuneOk() && uploaderStatus.isProjectIsOk()); + } + private void subscribeToUpdates(String configurationName, ControllerAccess controllerAccess) { IniFileModel model = new IniFileModel().readIniFile(TsTuneReader.getProjectModeFileName(configurationName)); Map allIniFields = model.allIniFields; @@ -185,31 +187,6 @@ public class PluginEntry implements TsPluginBody { } } - public static boolean isEmpty(Constant constant) { - if (constant == null) - return true; - return isEmpty(constant.getValue()); - } - - private void updateUploadEnabled() { - uploadView.update(uploaderStatus); - - upload.setEnabled(uploaderStatus.isTuneOk() && uploaderStatus.isProjectIsOk()); - } - - private static boolean isEmpty(String value) { - return value == null || value.trim().length() == 0; - } - - @Override - public JComponent getContent() { - return content; - } -/* - public void close() { - PersistentConfiguration.getConfig().save(); - } -*/ private String getConfigurationName() { ControllerAccess controllerAccess = controllerAccessSupplier.get(); if (controllerAccess == null) { @@ -222,13 +199,7 @@ public class PluginEntry implements TsPluginBody { return configurationNames[0]; } - /** - * this method is invoked by refection - * - * @see TsPluginBody#GET_VERSION - */ - @SuppressWarnings("unused") - public static String getVersion() { - return ManifestHelper.getVersion(); + public JComponent getContent() { + return content; } } diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadView.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadView.java similarity index 93% rename from java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadView.java rename to java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadView.java index ffc397207b..4b2b812334 100644 --- a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadView.java +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadView.java @@ -22,12 +22,14 @@ public class UploadView { content.add(projectWarning); content.add(tuneInfo); content.add(uploadState); + content.add(autoUpload); autoUpload.setSelected(isAutoUpload()); autoUpload.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { PersistentConfiguration.getConfig().getRoot().setProperty(AUTO_UPLOAD, autoUpload.isSelected()); + PersistentConfiguration.getConfig().save(); } }); uploadState.setVisible(false); @@ -38,7 +40,7 @@ public class UploadView { } public void setResult(UploadResult result) { - uploadState.setText(result.getMessage().get(0).toString()); + uploadState.setText(result.getFirstMessage()); uploadState.setVisible(true); } diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploaderStatus.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploaderStatus.java similarity index 100% rename from java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploaderStatus.java rename to java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploaderStatus.java diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/util/ManifestHelper.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/util/ManifestHelper.java similarity index 100% rename from java_tools/ts_plugin/src/com/rusefi/ts_plugin/util/ManifestHelper.java rename to java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/util/ManifestHelper.java diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginBodySandbox.java b/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/PluginBodySandbox.java similarity index 100% rename from java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginBodySandbox.java rename to java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/PluginBodySandbox.java diff --git a/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/RemoteTabSandbox.java b/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/RemoteTabSandbox.java new file mode 100644 index 0000000000..f2f8ee4b61 --- /dev/null +++ b/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/RemoteTabSandbox.java @@ -0,0 +1,9 @@ +package com.rusefi.ts_plugin; + +import com.rusefi.ui.util.FrameHelper; + +public class RemoteTabSandbox { + public static void main(String[] args) { + new FrameHelper().showFrame(new RemoteTab().getContent()); + } +} diff --git a/java_tools/ts_plugin/ts_plugin.iml b/java_tools/ts_plugin/ts_plugin.iml index e32d346d51..8a045a4fe5 100644 --- a/java_tools/ts_plugin/ts_plugin.iml +++ b/java_tools/ts_plugin/ts_plugin.iml @@ -3,7 +3,8 @@ - + + @@ -15,5 +16,6 @@ + \ No newline at end of file diff --git a/java_tools/ts_plugin/upload.sh b/java_tools/ts_plugin/upload_plugin.sh similarity index 100% rename from java_tools/ts_plugin/upload.sh rename to java_tools/ts_plugin/upload_plugin.sh diff --git a/java_tools/ts_plugin_launcher/.idea/libraries/httpclient.xml b/java_tools/ts_plugin_launcher/.idea/libraries/httpclient.xml index 3fedad0411..d86ad16d80 100644 --- a/java_tools/ts_plugin_launcher/.idea/libraries/httpclient.xml +++ b/java_tools/ts_plugin_launcher/.idea/libraries/httpclient.xml @@ -4,6 +4,7 @@ + diff --git a/java_tools/ts_plugin_launcher/.idea/libraries/jSerialComm.xml b/java_tools/ts_plugin_launcher/.idea/libraries/jSerialComm.xml new file mode 100644 index 0000000000..07aef6e82e --- /dev/null +++ b/java_tools/ts_plugin_launcher/.idea/libraries/jSerialComm.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/java_tools/ts_plugin_launcher/.idea/libraries/jcip_annotations.xml b/java_tools/ts_plugin_launcher/.idea/libraries/jcip_annotations.xml new file mode 100644 index 0000000000..99bd563f23 --- /dev/null +++ b/java_tools/ts_plugin_launcher/.idea/libraries/jcip_annotations.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/java_tools/ts_plugin_launcher/.idea/modules.xml b/java_tools/ts_plugin_launcher/.idea/modules.xml index af6e89fb9e..1c3c28fbb8 100644 --- a/java_tools/ts_plugin_launcher/.idea/modules.xml +++ b/java_tools/ts_plugin_launcher/.idea/modules.xml @@ -4,6 +4,7 @@ + diff --git a/java_tools/ts_plugin_launcher/.idea/runConfigurations/RemoteTabSandbox.xml b/java_tools/ts_plugin_launcher/.idea/runConfigurations/RemoteTabSandbox.xml new file mode 100644 index 0000000000..3ba1ad72a9 --- /dev/null +++ b/java_tools/ts_plugin_launcher/.idea/runConfigurations/RemoteTabSandbox.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/misc/console_launcher/readme.html b/misc/console_launcher/readme.html index 944aac6892..c2b08d5d23 100644 --- a/misc/console_launcher/readme.html +++ b/misc/console_launcher/readme.html @@ -2,7 +2,7 @@

-This is rusEfi open source engine control unit bundle. +This is rusEFI open source engine control unit bundle.


Source code & links diff --git a/misc/jenkins/build_working_folder.sh b/misc/jenkins/build_working_folder.sh index da82195d40..734bb9fd43 100644 --- a/misc/jenkins/build_working_folder.sh +++ b/misc/jenkins/build_working_folder.sh @@ -1,9 +1,13 @@ #!/bin/bash -FULL_BUNDLE_FILE="$BUNDLE_FULL_NAME.zip" +# +# file build_working_folder.sh +# + +FULL_BUNDLE_FILE="${BUNDLE_FULL_NAME}.zip" UPDATE_BUNDLE_FILE="${BUNDLE_FULL_NAME}_autoupdate.zip" -echo "Packaging temp/$FULL_BUNDLE_FILE file" +echo "${BUNDLE_FULL_NAME}: Packaging temp/$FULL_BUNDLE_FILE file" rm -rf temp mkdir temp @@ -50,8 +54,9 @@ cp java_tools/ts_plugin_launcher/build/jar/rusefi_plugin_launcher.jar $CONSOLE_F cp simulator/build/rusefi_simulator.exe $CONSOLE_FOLDER cp misc/console_launcher/rusefi_*.exe $CONSOLE_FOLDER cp java_console/rusefi.xml $CONSOLE_FOLDER +cp -r java_console/bin $FOLDER -cp misc/console_launcher/readme.html $FOLDER +cp misc/console_launcher/readme.html $FOLDER cp firmware/tunerstudio/generated/$INI_FILE_OVERRIDE $FOLDER # Unsetting since would not be used anywhere else @@ -106,7 +111,10 @@ mkdir -p artifacts mv temp/$FULL_BUNDLE_FILE artifacts echo "Removing static content from ${CONSOLE_FOLDER} and $DRIVERS_FOLDER" -rm -rf $CONSOLE_FOLDER +rm -rf $CONSOLE_FOLDER/*.exe +rm -rf $CONSOLE_FOLDER/DfuSe +rm -rf $CONSOLE_FOLDER/openocd +rm -rf $CONSOLE_FOLDER/rusefi_autoupdate.jar rm -rf $DRIVERS_FOLDER # for autoupdate we do not want the unique folder name with timestamp diff --git a/misc/jenkins/compile_other_versions/prepare_bundle.sh b/misc/jenkins/compile_other_versions/prepare_bundle.sh index 8594feb0d3..e67dfc6cda 100644 --- a/misc/jenkins/compile_other_versions/prepare_bundle.sh +++ b/misc/jenkins/compile_other_versions/prepare_bundle.sh @@ -1,14 +1,16 @@ #!/bin/bash +BUNDLE_NAME="$1" +export INI_FILE_OVERRIDE="$2" SCRIPT_NAME="prepare_bundle.sh" -echo "Entering $SCRIPT_NAME with $BUNDLE_NAME" +echo "Entering $SCRIPT_NAME with ${BUNDLE_NAME}" echo "RUSEFI_BUILD_FTP_USER=$RUSEFI_BUILD_FTP_USER" TIMESTAMP=$(date "+%Y%m%d_%H%M%S") -export FOLDER="temp/snapshot_${TIMESTAMP}_${2}_rusefi" +export FOLDER="temp/snapshot_${TIMESTAMP}_${BUNDLE_NAME}_rusefi" -export BUNDLE_FULL_NAME="rusefi_bundle_$BUNDLE_NAME" +export BUNDLE_FULL_NAME="rusefi_bundle_${BUNDLE_NAME}" bash misc/jenkins/build_working_folder.sh diff --git a/unit_tests/efifeatures.h b/unit_tests/efifeatures.h index 910f15331f..5af53c1aec 100644 --- a/unit_tests/efifeatures.h +++ b/unit_tests/efifeatures.h @@ -11,6 +11,8 @@ #define EFI_ENABLE_ASSERTS TRUE +#define EFI_PRINTF_FUEL_DETAILS TRUE + #define EFI_CJ125 TRUE #define ENABLE_PERF_TRACE FALSE diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index ae37ace222..bfcf90a5ee 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -19,6 +19,8 @@ extern int timeNowUs; extern WarningCodeState unitTestWarningCodeState; extern engine_configuration_s & activeConfiguration; +extern bool printTriggerDebug; +extern bool printFuelDebug; EngineTestHelperBase::EngineTestHelperBase() { // todo: make this not a global variable, we need currentTimeProvider interface on engine @@ -138,6 +140,9 @@ void EngineTestHelper::moveTimeForwardMs(float deltaTimeMs) { } void EngineTestHelper::moveTimeForwardUs(int deltaTimeUs) { + if (printTriggerDebug || printFuelDebug) { + printf("moveTimeForwardUs %.1fms\r\n", deltaTimeUs / 1000.0); + } timeNowUs += deltaTimeUs; } diff --git a/unit_tests/logicdata.cpp b/unit_tests/logicdata.cpp new file mode 100644 index 0000000000..0a21019f60 --- /dev/null +++ b/unit_tests/logicdata.cpp @@ -0,0 +1,19 @@ +/* + * @file logicdata.cpp + * + * Created on: Jul 19, 2020 + * @author Andrey Belomutskiy, (c) 2012-2020 + */ + +#include "logicdata.h" +#include +#include + +void writeFile() { + + FILE *ptr = fopen("test.logicdata", "wb"); + + + fclose(ptr); + +} diff --git a/unit_tests/logicdata_sandbox.cpp b/unit_tests/logicdata_sandbox.cpp new file mode 100644 index 0000000000..fab07e3836 --- /dev/null +++ b/unit_tests/logicdata_sandbox.cpp @@ -0,0 +1,11 @@ + +#include +#include "logicdata.h" + +int main(int argc, char **argv) { + printf(".logicdata Sandbox 20200719\n"); + + writeFile(); + + printf("Done!\n"); +} diff --git a/unit_tests/run_logicdata_sandbox.bat b/unit_tests/run_logicdata_sandbox.bat new file mode 100644 index 0000000000..953f0e968f --- /dev/null +++ b/unit_tests/run_logicdata_sandbox.bat @@ -0,0 +1,5 @@ +rm -f build/logicdata_sandbox.exe + +x86_64-w64-mingw32-g++ logicdata.cpp logicdata_sandbox.cpp -o build/logicdata_sandbox.exe -Wall + +build\logicdata_sandbox.exe diff --git a/unit_tests/tests/ignition_injection/injection_mode_transition.cpp b/unit_tests/tests/ignition_injection/injection_mode_transition.cpp new file mode 100644 index 0000000000..221c8f7f67 --- /dev/null +++ b/unit_tests/tests/ignition_injection/injection_mode_transition.cpp @@ -0,0 +1,40 @@ +/* + * @file injection_mode_transition.cpp + * + * Created on: Jul 19, 2020 + * @author Andrey Belomutskiy, (c) 2012-2020 + */ + +#include "engine_test_helper.h" + + +// https://github.com/rusefi/rusefi/issues/1592 +TEST(fuelControl, transitionIssue1592) { + + WITH_ENGINE_TEST_HELPER(TEST_ENGINE); + setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð, IM_SEQUENTIAL); + + eth.fireTriggerEvents2(4 /* count */ , 600 /* ms */); + + ASSERT_EQ(CRANKING, engine->rpmCalculator.getState()); + ASSERT_EQ( 100, GET_RPM()) << "spinning-RPM#1"; + + ASSERT_EQ(IM_SIMULTANEOUS, ENGINE(getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE))); + + + eth.fireRise(150); + eth.fireFall(150); + + eth.fireRise(150); + eth.fireFall(150); + + eth.fireRise(150); + eth.fireFall(150); + + ASSERT_EQ( 400, GET_RPM()) << "running-RPM#1"; + + ASSERT_EQ(IM_SIMULTANEOUS, ENGINE(getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE))); + +} + + diff --git a/unit_tests/tests/test_dwell_corner_case_issue_796.cpp b/unit_tests/tests/ignition_injection/test_dwell_corner_case_issue_796.cpp similarity index 100% rename from unit_tests/tests/test_dwell_corner_case_issue_796.cpp rename to unit_tests/tests/ignition_injection/test_dwell_corner_case_issue_796.cpp diff --git a/unit_tests/tests/test_fuelCut.cpp b/unit_tests/tests/ignition_injection/test_fuelCut.cpp similarity index 100% rename from unit_tests/tests/test_fuelCut.cpp rename to unit_tests/tests/ignition_injection/test_fuelCut.cpp diff --git a/unit_tests/tests/test_ignition_scheduling.cpp b/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp similarity index 100% rename from unit_tests/tests/test_ignition_scheduling.cpp rename to unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp diff --git a/unit_tests/tests/test_miata_na6_real_cranking.cpp b/unit_tests/tests/ignition_injection/test_miata_na6_real_cranking.cpp similarity index 100% rename from unit_tests/tests/test_miata_na6_real_cranking.cpp rename to unit_tests/tests/ignition_injection/test_miata_na6_real_cranking.cpp diff --git a/unit_tests/tests/test_multispark.cpp b/unit_tests/tests/ignition_injection/test_multispark.cpp similarity index 100% rename from unit_tests/tests/test_multispark.cpp rename to unit_tests/tests/ignition_injection/test_multispark.cpp diff --git a/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp b/unit_tests/tests/ignition_injection/test_startOfCrankingPrimingPulse.cpp similarity index 100% rename from unit_tests/tests/test_startOfCrankingPrimingPulse.cpp rename to unit_tests/tests/ignition_injection/test_startOfCrankingPrimingPulse.cpp diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 0985abc618..72d0c281a4 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -6,6 +6,11 @@ TESTS_SRC_CPP = \ tests/trigger/test_cam_vvt_input.cpp \ tests/trigger/test_2jz_vvt.cpp \ tests/trigger/test_injection_scheduling.cpp \ + tests/ignition_injection/injection_mode_transition.cpp \ + tests/ignition_injection/test_startOfCrankingPrimingPulse.cpp \ + tests/ignition_injection/test_miata_na6_real_cranking.cpp \ + tests/ignition_injection/test_ignition_scheduling.cpp \ + tests/ignition_injection/test_fuelCut.cpp \ tests/test_util.cpp \ tests/test_ion.cpp \ tests/test_aux_valves.cpp \ @@ -13,18 +18,14 @@ TESTS_SRC_CPP = \ tests/test_hip9011.cpp \ tests/test_cj125.cpp \ tests/test_engine_math.cpp \ - tests/test_startOfCrankingPrimingPulse.cpp \ - tests/test_miata_na6_real_cranking.cpp \ tests/test_fasterEngineSpinningUp.cpp \ tests/test_dwell_corner_case_issue_796.cpp \ tests/test_idle_controller.cpp \ tests/test_issue_898.cpp \ tests/test_etb.cpp \ - tests/test_ignition_scheduling.cpp \ tests/test_fuel_map.cpp \ tests/test_fuel_wall_wetting.cpp \ tests/test_one_cylinder_logic.cpp \ - tests/test_fuelCut.cpp \ tests/test_pwm_generator.cpp \ tests/test_logic_expression.cpp \ tests/test_speed_density.cpp \ @@ -36,7 +37,7 @@ TESTS_SRC_CPP = \ tests/test_accel_enrichment.cpp \ tests/test_tacho.cpp \ tests/test_gpiochip.cpp \ - tests/test_multispark.cpp \ + tests/ignition_injection/test_multispark.cpp \ tests/test_deadband.cpp \ tests/sensor/basic_sensor.cpp \ tests/sensor/func_sensor.cpp \