From c42de4b24c7222e196df737d5745c598cd229844 Mon Sep 17 00:00:00 2001 From: Marcel Peterkau Date: Mon, 25 Sep 2023 07:21:33 +0200 Subject: [PATCH] added CAN-Debug-Message --- Software/include/can.h | 2 ++ Software/include/lubeapp.h | 1 + Software/include/sanitycheck.h | 6 ++++ Software/src/can.cpp | 65 ++++++++++++++++++++++++++++++++++ Software/src/main.cpp | 33 +++++++---------- 5 files changed, 86 insertions(+), 21 deletions(-) diff --git a/Software/include/can.h b/Software/include/can.h index b646297..6de4206 100644 --- a/Software/include/can.h +++ b/Software/include/can.h @@ -7,6 +7,7 @@ #include "common.h" #include "globals.h" #include "dtc.h" +#include "debugger.h" struct can_frame { @@ -16,6 +17,7 @@ struct can_frame }; void Init_CAN(); +void CAN_Process(); uint32_t Process_CAN_WheelSpeed(); #endif \ No newline at end of file diff --git a/Software/include/lubeapp.h b/Software/include/lubeapp.h index 21d0ad3..5c55f75 100644 --- a/Software/include/lubeapp.h +++ b/Software/include/lubeapp.h @@ -7,6 +7,7 @@ #include "common.h" #include "globals.h" #include "dtc.h" +#include "debugger.h" void RunLubeApp(uint32_t add_milimeters); void LubePulse(); diff --git a/Software/include/sanitycheck.h b/Software/include/sanitycheck.h index 6da5368..5304d70 100644 --- a/Software/include/sanitycheck.h +++ b/Software/include/sanitycheck.h @@ -16,6 +16,12 @@ #endif #endif +#ifdef CAN_DEBUG_MESSAGE + #ifndef FEATURE_ENABLE_CAN + #error "You cannot enable CAN-Debug-Message without FEATURE_ENABLE_CAN" + #endif +#endif + #ifndef ADMIN_PASSWORD #error "You need to define ADMIN_PASSWORD for OTA-Update" #endif diff --git a/Software/src/can.cpp b/Software/src/can.cpp index 3a10e65..ad0b440 100644 --- a/Software/src/can.cpp +++ b/Software/src/can.cpp @@ -2,6 +2,9 @@ #include "can.h" MCP_CAN CAN0(GPIO_CS_CAN); +#ifdef CAN_DEBUG_MESSAGE +void sendCANDebugMessage(); +#endif void Init_CAN() { @@ -16,6 +19,17 @@ void Init_CAN() CAN0.setMode(MCP_NORMAL); } +void CAN_Process() +{ + static uint32_t previousMillis = 0; + + if (millis() - previousMillis >= 100) + { + sendCANDebugMessage(); + previousMillis = millis(); + } +} + uint32_t Process_CAN_WheelSpeed() { #define FACTOR_RWP_KMH_890ADV 18 // Divider to convert Raw Data to km/h @@ -46,4 +60,55 @@ uint32_t Process_CAN_WheelSpeed() return milimeters_to_add; } + +#ifdef CAN_DEBUG_MESSAGE +void sendCANDebugMessage() +{ +#define MAX_DEBUG_MULTIPLEXER 6 + static uint8_t debugMultiplexer = 0; + byte data[8] = {debugMultiplexer, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + uint32_t millisValue = millis(); + + switch (debugMultiplexer) + { + case 0: + memcpy(&data[1], &millisValue, sizeof(millisValue)); + memcpy(&data[5], &globals.purgePulses, sizeof(globals.purgePulses)); + break; + case 1: + data[1] = (uint8_t)globals.systemStatus; + data[2] = (uint8_t)globals.resumeStatus; + data[3] = (uint8_t)globals.requestEEAction; + data[4] = globals.TankPercentage; + data[5] = (0x01 & globals.hasDTC) | ((0x01 & globals.measurementActive) << 1); + break; + case 2: + memcpy(&data[1], &globals.eePersistanceAdress, sizeof(globals.eePersistanceAdress)); + memcpy(&data[3], &PersistenceData.tankRemain_microL, sizeof(PersistenceData.tankRemain_microL)); + break; + case 3: + memcpy(&data[1], &PersistenceData.writeCycleCounter, sizeof(PersistenceData.writeCycleCounter)); + memcpy(&data[3], &PersistenceData.TravelDistance_highRes_mm, sizeof(PersistenceData.TravelDistance_highRes_mm)); + break; + case 4: + memcpy(&data[1], &PersistenceData.odometer_mm, sizeof(PersistenceData.odometer_mm)); + break; + case 5: + memcpy(&data[1], &PersistenceData.odometer, sizeof(PersistenceData.odometer)); + break; + case 6: + memcpy(&data[1], &PersistenceData.checksum, sizeof(PersistenceData.checksum)); + break; + default: + break; + } + + debugMultiplexer++; + debugMultiplexer = debugMultiplexer > MAX_DEBUG_MULTIPLEXER ? 0 : debugMultiplexer; + + byte sndStat = CAN0.sendMsgBuf(0x7FF, 0, 8, data); + if (sndStat != CAN_OK) + Debug_pushMessage("failed sending CAN-DbgMsg: %d\n", sndStat); +} +#endif #endif \ No newline at end of file diff --git a/Software/src/main.cpp b/Software/src/main.cpp index 061781b..7e461dc 100644 --- a/Software/src/main.cpp +++ b/Software/src/main.cpp @@ -96,31 +96,19 @@ void setup() #endif leds.begin(); Serial.print("\nLED-Init done"); - switch (LubeConfig.SpeedSource) - { - case SOURCE_IMPULSE: - pinMode(GPIO_TRIGGER, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING); - break; -#ifdef FEATURE_ENABLE_GPS - case SOURCE_GPS: - Init_GPS(); - break; -#endif -#ifdef FEATURE_ENABLE_TIMER - case SOURCE_TIME: - break; + pinMode(GPIO_TRIGGER, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING); + Serial.print("\nPulse-Input Init done"); +#ifdef FEATURE_ENABLE_GPS + Init_GPS(); + Serial.print("\nGPS-Init done"); #endif #ifdef FEATURE_ENABLE_CAN - case SOURCE_CAN: - Init_CAN(); - break; + Init_CAN(); + Serial.print("\nCAN-Init done"); #endif - default: - Debug_pushMessage("Source Setting N/A"); - break; - } + Serial.print("\nSource-Init done"); pinMode(GPIO_BUTTON, INPUT_PULLUP); pinMode(GPIO_PUMP, OUTPUT); @@ -193,6 +181,9 @@ void loop() RunLubeApp(wheelDistance); #ifdef FEATURE_ENABLE_OLED Display_Process(); +#endif +#ifdef FEATURE_ENABLE_CAN + CAN_Process(); #endif Button_Process(); LED_Process();