diff --git a/firmware/console/tooth_logger.cpp b/firmware/console/tooth_logger.cpp index f8978d6a8f..cc5f6504c7 100644 --- a/firmware/console/tooth_logger.cpp +++ b/firmware/console/tooth_logger.cpp @@ -16,17 +16,51 @@ #include "efilib.h" #include "tunerstudio_configuration.h" -static uint16_t buffer[1000] CCM_OPTIONAL; +typedef struct __attribute__ ((packed)) { + uint16_t timestamp; +} tooth_logger_s; + +typedef struct __attribute__ ((packed)) { + // the whole order of all packet bytes is reversed, not just the 'endian-swap' integers + uint32_t timestamp; + // unfortunately all these fields are required by TS... + bool priLevel : 1; + bool secLevel : 1; + bool trigger : 1; + bool sync : 1; +} composite_logger_s; + +static composite_logger_s buffer[COMPOSITE_PACKET_COUNT] CCM_OPTIONAL; static size_t NextIdx = 0; static volatile bool ToothLoggerEnabled = false; static uint32_t lastEdgeTimestamp = 0; -void SetNextEntry(uint16_t entry) { +static bool trigger1 = false; +static bool trigger2 = false; + +//char (*__kaboom)[sizeof( composite_logger_s )] = 1; +//char (*__kaboom)[sizeof( buffer )] = 1; + +//void SetNextToothEntry(uint16_t entry) { // TS uses big endian, grumble - buffer[NextIdx] = SWAP_UINT16(entry); +// buffer[NextIdx] = SWAP_UINT16(entry); + //NextIdx++; + + +static void SetNextCompositeEntry(uint32_t nowUs, bool trigger1, bool trigger2) { + // TS uses big endian, grumble + buffer[NextIdx].timestamp = SWAP_UINT32(nowUs); + buffer[NextIdx].priLevel = trigger1; + buffer[NextIdx].secLevel = trigger2; + // todo: + //buffer[NextIdx].sync = isSynced; + //buffer[NextIdx].trigger = wtfIsTriggerIdk; + NextIdx++; + static_assert(sizeof(composite_logger_s) == COMPOSITE_PACKET_SIZE, "composite packet size"); + // If we hit the end, loop if (NextIdx >= sizeof(buffer) / sizeof(buffer[0])) { NextIdx = 0; @@ -39,19 +73,41 @@ void LogTriggerTooth(trigger_event_e tooth, efitick_t timestamp) { return; } - // We currently only support the primary trigger falling edge - // (this is the edge that VR sensors are accurate on) - // Since VR sensors are the most useful case here, this is okay for now. - if (tooth != SHAFT_PRIMARY_FALLING) { - return; +/* + // We currently only support the primary trigger falling edge + // (this is the edge that VR sensors are accurate on) + // Since VR sensors are the most useful case here, this is okay for now. + if (tooth != SHAFT_PRIMARY_FALLING) { + return; + } + + uint32_t nowUs = NT2US(timestamp); + // 10us per LSB - this gives plenty of accuracy, yet fits 655.35 ms in to a uint16 + uint16_t delta = static_cast((nowUs - lastEdgeTimestamp) / 10); + lastEdgeTimestamp = nowUs; + + SetNextEntry(delta); +*/ + + switch (tooth) { + case SHAFT_PRIMARY_FALLING: + trigger1 = false; + break; + case SHAFT_PRIMARY_RISING: + trigger1 = true; + break; + case SHAFT_SECONDARY_FALLING: + trigger2 = false; + break; + case SHAFT_SECONDARY_RISING: + trigger2 = true; + break; + default: + break; } uint32_t nowUs = NT2US(timestamp); - // 10us per LSB - this gives plenty of accuracy, yet fits 655.35 ms in to a uint16 - uint16_t delta = static_cast((nowUs - lastEdgeTimestamp) / 10); - lastEdgeTimestamp = nowUs; - - SetNextEntry(delta); + SetNextCompositeEntry(nowUs, trigger1, trigger2); } void EnableToothLogger() { diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 97e19ed6b6..f9c58ef7ce 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -76,8 +76,12 @@ struct_no_prefix engine_configuration_s #define TRIGGER_TYPE_60_2 8 #define TRIGGER_TYPE_36_1 9 -#define COMPOSITE_PACKET_COUNT 1000 -#define COMPOSITE_PACKET_SIZE 2 +#define TOOTH_PACKET_COUNT 1000 +#define TOOTH_PACKET_SIZE 2 +#define TOOTH_DATA_LENGTH @@TOOTH_PACKET_SIZE@@*@@TOOTH_PACKET_COUNT@@ + +#define COMPOSITE_PACKET_COUNT 500 +#define COMPOSITE_PACKET_SIZE 5 #define COMPOSITE_DATA_LENGTH @@COMPOSITE_PACKET_SIZE@@*@@COMPOSITE_PACKET_COUNT@@ #define MAP_ANGLE_SIZE 8 diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index f63e070f47..9dae030fb6 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -109,22 +109,39 @@ enable2ndByteCanID = false [LoggerDefinition] ; valid logger types: composite, tooth, trigger, csv - loggerDef = compositeLogger, "Primary Trigger Logger", tooth +; loggerDef = compositeLogger, "Primary Trigger Logger", tooth + loggerDef = compositeLogger, "Trigger Logger", composite startCommand = "l\x01" stopCommand = "l\x02" dataReadCommand = "L" dataReadTimeout = 10000 ; time in ms dataReadyCondition = { toothLogReady } + continuousRead = true ; each packet is @@COMPOSITE_PACKET_SIZE@@ and we have @@COMPOSITE_PACKET_COUNT@@ of those dataLength = @@COMPOSITE_DATA_LENGTH@@ +;tooth ; recordDef = headerLen, footerLen, recordLen - recordDef = 0, 0, @@COMPOSITE_PACKET_SIZE@@ +; recordDef = 0, 0, @@COMPOSITE_PACKET_SIZE@@ ; uint16 that stores 1/100 second - recordField = toothTime, "tooth", 0, 16, 0.01, "ms" +; recordField = toothTime, "tooth", 0, 16, 0.01, "ms" + + ; recordDef = headerLen, footerLen, recordLen + recordDef = 0, 0, @@COMPOSITE_PACKET_SIZE@@ + + ; these names are hard-coded inside TS + recordField = priLevel, "PriLevel", 0, 1, 1.0, "Flag" + recordField = secLevel, "SecLevel", 1, 1, 1.0, "Flag" + recordField = trigger, "Trigger", 2, 1, 1.0, "Flag" + recordField = sync, "Sync", 3, 1, 1.0, "Flag" + recordField = time, "Time", 8, 32, 0.01, "ms" + + ; it seems that TS also needs to know the diff.size of a tooth + calcField = toothTime, "ToothTime", "ms", { time - pastValue(time, 1) } + [VeAnalyze] ; tableName, lambdaTargetTableName, lambdaChannel, egoCorrectionChannel, activeCondition diff --git a/java_console/models/src/com/rusefi/config/generated/Fields.java b/java_console/models/src/com/rusefi/config/generated/Fields.java index 487f95a4f0..1dcb36c1cd 100644 --- a/java_console/models/src/com/rusefi/config/generated/Fields.java +++ b/java_console/models/src/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.bat integration\rusefi_config.txt Mon Apr 13 18:54:18 EDT 2020 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.bat integration\rusefi_config.txt Mon Apr 13 20:23:02 EDT 2020 // by class com.rusefi.output.FileJavaFieldsConsumer import com.rusefi.config.*; @@ -285,9 +285,9 @@ public class Fields { public static final int coastingFuelCutTps_offset = 3152; public static final int communicationLedPin_offset = 1812; public static final int communicationLedPin_offset_hex = 714; - public static final int COMPOSITE_DATA_LENGTH = 2000; - public static final int COMPOSITE_PACKET_COUNT = 1000; - public static final int COMPOSITE_PACKET_SIZE = 2; + public static final int COMPOSITE_DATA_LENGTH = 2500; + public static final int COMPOSITE_PACKET_COUNT = 500; + public static final int COMPOSITE_PACKET_SIZE = 5; public static final String CONSOLE_DATA_PROTOCOL_TAG = " @"; public static final int consoleLoopPeriodMs_offset = 716; public static final int consoleSerialRxPin_offset = 1819; @@ -1293,6 +1293,9 @@ public class Fields { public static final int tle8888spiDevice_offset = 4000; public static final int todoClutchDownPinInverted_offset = 976; public static final int todoClutchUpPinInverted_offset = 976; + public static final int TOOTH_DATA_LENGTH = 2000; + public static final int TOOTH_PACKET_COUNT = 1000; + public static final int TOOTH_PACKET_SIZE = 2; public static final String TOP_DEAD_CENTER_MESSAGE = "r"; public static final int TOTAL_CONFIG_SIZE = 20000; public static final int tps1_1AdcChannel_offset = 512;