added CAN-Debug-Message

This commit is contained in:
Marcel Peterkau 2023-09-25 07:21:33 +02:00
parent ce9f1a2306
commit c42de4b24c
5 changed files with 86 additions and 21 deletions

View File

@ -7,6 +7,7 @@
#include "common.h" #include "common.h"
#include "globals.h" #include "globals.h"
#include "dtc.h" #include "dtc.h"
#include "debugger.h"
struct can_frame struct can_frame
{ {
@ -16,6 +17,7 @@ struct can_frame
}; };
void Init_CAN(); void Init_CAN();
void CAN_Process();
uint32_t Process_CAN_WheelSpeed(); uint32_t Process_CAN_WheelSpeed();
#endif #endif

View File

@ -7,6 +7,7 @@
#include "common.h" #include "common.h"
#include "globals.h" #include "globals.h"
#include "dtc.h" #include "dtc.h"
#include "debugger.h"
void RunLubeApp(uint32_t add_milimeters); void RunLubeApp(uint32_t add_milimeters);
void LubePulse(); void LubePulse();

View File

@ -16,6 +16,12 @@
#endif #endif
#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 #ifndef ADMIN_PASSWORD
#error "You need to define ADMIN_PASSWORD for OTA-Update" #error "You need to define ADMIN_PASSWORD for OTA-Update"
#endif #endif

View File

@ -2,6 +2,9 @@
#include "can.h" #include "can.h"
MCP_CAN CAN0(GPIO_CS_CAN); MCP_CAN CAN0(GPIO_CS_CAN);
#ifdef CAN_DEBUG_MESSAGE
void sendCANDebugMessage();
#endif
void Init_CAN() void Init_CAN()
{ {
@ -16,6 +19,17 @@ void Init_CAN()
CAN0.setMode(MCP_NORMAL); CAN0.setMode(MCP_NORMAL);
} }
void CAN_Process()
{
static uint32_t previousMillis = 0;
if (millis() - previousMillis >= 100)
{
sendCANDebugMessage();
previousMillis = millis();
}
}
uint32_t Process_CAN_WheelSpeed() uint32_t Process_CAN_WheelSpeed()
{ {
#define FACTOR_RWP_KMH_890ADV 18 // Divider to convert Raw Data to km/h #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; 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 #endif

View File

@ -96,31 +96,19 @@ void setup()
#endif #endif
leds.begin(); leds.begin();
Serial.print("\nLED-Init done"); Serial.print("\nLED-Init done");
switch (LubeConfig.SpeedSource)
{
case SOURCE_IMPULSE:
pinMode(GPIO_TRIGGER, INPUT_PULLUP); pinMode(GPIO_TRIGGER, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING); attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING);
break; Serial.print("\nPulse-Input Init done");
#ifdef FEATURE_ENABLE_GPS #ifdef FEATURE_ENABLE_GPS
case SOURCE_GPS:
Init_GPS(); Init_GPS();
break; Serial.print("\nGPS-Init done");
#endif
#ifdef FEATURE_ENABLE_TIMER
case SOURCE_TIME:
break;
#endif #endif
#ifdef FEATURE_ENABLE_CAN #ifdef FEATURE_ENABLE_CAN
case SOURCE_CAN:
Init_CAN(); Init_CAN();
break; Serial.print("\nCAN-Init done");
#endif #endif
default:
Debug_pushMessage("Source Setting N/A");
break;
}
Serial.print("\nSource-Init done"); Serial.print("\nSource-Init done");
pinMode(GPIO_BUTTON, INPUT_PULLUP); pinMode(GPIO_BUTTON, INPUT_PULLUP);
pinMode(GPIO_PUMP, OUTPUT); pinMode(GPIO_PUMP, OUTPUT);
@ -193,6 +181,9 @@ void loop()
RunLubeApp(wheelDistance); RunLubeApp(wheelDistance);
#ifdef FEATURE_ENABLE_OLED #ifdef FEATURE_ENABLE_OLED
Display_Process(); Display_Process();
#endif
#ifdef FEATURE_ENABLE_CAN
CAN_Process();
#endif #endif
Button_Process(); Button_Process();
LED_Process(); LED_Process();