mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 10:19:29 +02:00
First commit
This commit is contained in:
parent
440e010a71
commit
4d95fcfc31
3 changed files with 65 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "src/battery/BATTERIES.h"
|
#include "src/battery/BATTERIES.h"
|
||||||
#include "src/charger/CHARGERS.h"
|
#include "src/charger/CHARGERS.h"
|
||||||
#include "src/devboard/config.h"
|
#include "src/devboard/config.h"
|
||||||
|
#include "src/devboard/utils/events.h"
|
||||||
#include "src/inverter/INVERTERS.h"
|
#include "src/inverter/INVERTERS.h"
|
||||||
#include "src/lib/adafruit-Adafruit_NeoPixel/Adafruit_NeoPixel.h"
|
#include "src/lib/adafruit-Adafruit_NeoPixel/Adafruit_NeoPixel.h"
|
||||||
#include "src/lib/eModbus-eModbus/Logging.h"
|
#include "src/lib/eModbus-eModbus/Logging.h"
|
||||||
|
@ -129,6 +130,8 @@ void setup() {
|
||||||
init_webserver();
|
init_webserver();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
init_events();
|
||||||
|
|
||||||
init_CAN();
|
init_CAN();
|
||||||
|
|
||||||
init_LED();
|
init_LED();
|
||||||
|
@ -183,6 +186,7 @@ void loop() {
|
||||||
{
|
{
|
||||||
previousMillisUpdateVal = millis();
|
previousMillisUpdateVal = millis();
|
||||||
update_values(); // Update values heading towards inverter. Prepare for sending on CAN, or write directly to Modbus.
|
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
|
// Output
|
||||||
|
@ -190,6 +194,7 @@ void loop() {
|
||||||
#ifdef DUAL_CAN
|
#ifdef DUAL_CAN
|
||||||
send_can2();
|
send_can2();
|
||||||
#endif
|
#endif
|
||||||
|
update_event_timestamps();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialization functions
|
// Initialization functions
|
||||||
|
|
33
Software/src/devboard/utils/events.cpp
Normal file
33
Software/src/devboard/utils/events.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
27
Software/src/devboard/utils/events.h
Normal file
27
Software/src/devboard/utils/events.h
Normal 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__
|
Loading…
Add table
Add a link
Reference in a new issue