First commit

This commit is contained in:
Cabooman 2024-02-05 01:19:37 +01:00
parent 440e010a71
commit 4d95fcfc31
3 changed files with 65 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include "src/battery/BATTERIES.h"
#include "src/charger/CHARGERS.h"
#include "src/devboard/config.h"
#include "src/devboard/utils/events.h"
#include "src/inverter/INVERTERS.h"
#include "src/lib/adafruit-Adafruit_NeoPixel/Adafruit_NeoPixel.h"
#include "src/lib/eModbus-eModbus/Logging.h"
@ -129,6 +130,8 @@ void setup() {
init_webserver();
#endif
init_events();
init_CAN();
init_LED();
@ -183,6 +186,7 @@ void loop() {
{
previousMillisUpdateVal = millis();
update_values(); // Update values heading towards inverter. Prepare for sending on CAN, or write directly to Modbus.
set_event(EVENT_DUMMY, (uint8_t)millis());
}
// Output
@ -190,6 +194,7 @@ void loop() {
#ifdef DUAL_CAN
send_can2();
#endif
update_event_timestamps();
}
// Initialization functions

View file

@ -0,0 +1,33 @@
#include "events.h"
typedef struct {
uint32_t timestamp; // Time in seconds since startup when the event occurred
uint8_t data; // Custom data passed when setting the event, for example cell number for under voltage
uint8_t occurences; // Number of occurrences since startup
} EVENTS_STRUCT_TYPE;
static EVENTS_STRUCT_TYPE entries[EVENT_NOF_EVENTS];
static unsigned long previous_millis = 0;
static uint32_t time_seconds = 0;
void init_events(void) {
for (uint8_t i = 0; i < EVENT_NOF_EVENTS; i++) {
entries[i].timestamp = 0;
entries[i].data = 0;
entries[i].occurences = 0;
}
}
void set_event(EVENTS_ENUM_TYPE event, uint8_t data) {
entries[event].timestamp = time_seconds;
entries[event].data = data;
entries[event].occurences++;
}
void update_event_timestamps(void) {
unsigned long new_millis = millis();
if (new_millis - previous_millis >= 1000) {
time_seconds++;
previous_millis = new_millis;
}
}

View file

@ -0,0 +1,27 @@
#ifndef __EVENTS_H__
#define __EVENTS_H__
#include <Arduino.h>
typedef enum {
EVENT_CAN_FAILURE = 0u,
EVENT_CAN_WARNING,
EVENT_WATER_INGRESS,
EVENT_12V_LOW,
EVENT_SOC_PLAUSIBILITY_ERROR,
EVENT_KWH_PLAUSIBILITY_ERROR,
EVENT_BATTERY_CHG_DISCHG_STOP_REQ,
EVENT_LOW_SOH,
EVENT_HVIL_FAILURE,
EVENT_INTERNAL_OPEN_FAULT,
EVENT_CELL_UNDER_VOLTAGE,
EVENT_CELL_OVER_VOLTAGE,
EVENT_DUMMY,
EVENT_NOF_EVENTS
} EVENTS_ENUM_TYPE;
void init_events(void);
void set_event(EVENTS_ENUM_TYPE event, uint8_t data);
void update_event_timestamps(void);
#endif // __MYTIMER_H__