updated Project with elementes From ChainLube-Project

This commit is contained in:
2024-05-30 23:38:05 +02:00
parent 7a2e95c126
commit cf76ea7cc7
16 changed files with 1662 additions and 679 deletions

View File

@@ -3,14 +3,18 @@
#define _COMMON_H_
#include <stdint.h>
#include <stddef.h>
#define Q(x) #x
#define QUOTE(x) Q(x)
#define SET_BIT(value, bitPosition) ((value) |= (1U << (bitPosition)))
#define TRUE 1
#define FALSE 0
#ifndef HOST_NAME
#define HOST_NAME "AirsoftTimer_%08X"
#endif
#define SHUTDOWN_DELAY_MS 5000
#define STARTUP_DELAY_MS 20000
@@ -44,6 +48,17 @@
#define OTA_DELAY 50 // ticks -> 10ms / tick
#endif
typedef enum eSystem_Status
{
sysStat_Startup,
sysStat_Normal,
sysStat_Rain,
sysStat_Purge,
sysStat_Error,
sysStat_Shutdown
} tSystem_Status;
#define STARTUP_DELAY 2500
#define SHUTDOWN_DELAY_MS 2500
#endif

View File

@@ -1,9 +1,21 @@
/**
* @file debugger.h
*
* @brief Header file for debugging functions and status in the ChainLube application.
*
* This file declares functions and status definitions for debugging purposes in the ChainLube project.
* It includes functions to print system information, WiFi information, format EEPROM data,
* handle debug messages, and manage the status of different debug ports.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _DEBUGGER_H_
#define _DEBUGGER_H_
#include <Arduino.h>
#include "webui.h"
const char PROGMEM helpCmd[] = "sysinfo - System Info\n"
"netinfo - WiFi Info\n"
"formatPDS - Format Persistence EEPROM Data\n"

View File

@@ -1,57 +1,39 @@
/**
* @file dtc.h
*
* @brief Header file for handling Diagnostic Trouble Codes (DTC) in the ChainLube application.
*
* This file provides definitions and functions for handling Diagnostic Trouble Codes (DTC)
* in the ChainLube project. It includes structures for DTC entries, severity levels,
* and functions for DTC maintenance and processing. DTCs are used to track system errors and issues.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _DTC_H_
#define _DTC_H_
#include <Arduino.h>
#include "dtc_defs.h"
#define MAX_DTC_STORAGE 12
typedef enum DTCNums_e
typedef struct
{
DTC_NO_EEPROM_FOUND = 1,
DTC_EEPROM_CFG_BAD,
DTC_EEPROM_PDS_BAD,
DTC_EEPROM_PDSADRESS_BAD,
DTC_EEPROM_VERSION_BAD,
DTC_FLASHFS_ERROR,
DTC_FLASHFS_VERSION_ERROR,
DTC_EEPROM_CFG_SANITY,
DTC_NO_LORA_FOUND,
DTC_NO_BATMNON_FOUND,
DTC_BAT_LOW,
DTC_BAT_CRITICAL,
DTC_EEPROM_MIGRATE_FAILED,
DTC_LAST_DTC
} DTCNums_t;
typedef enum DTCActive_e
{
DTC_NONE,
DTC_ACTIVE,
DTC_PREVIOUS
} DTCActive_t;
typedef enum DTCSeverity_e
{
DTC_INFO,
DTC_WARN,
DTC_CRITICAL
} DTCSeverity_t;
typedef struct DTCEntry_s
{
DTCNums_t Number;
DTCNum_t Number;
uint32_t timestamp;
DTCActive_t active;
DTCSeverity_t severity;
uint32_t debugVal;
} DTCEntry_t;
void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active, uint32_t DebugValue = 0);
void ClearDTC(DTCNums_t DTC_no);
void MaintainDTC(DTCNum_t DTC_no, boolean active, uint32_t DebugValue = 0);
void ClearDTC(DTCNum_t DTC_no);
void ClearAllDTC();
DTCNums_t getlastDTC(boolean only_active);
DTCNums_t getlastDTC_Severity(boolean only_active, DTCSeverity_t severity);
DTCNum_t getlastDTC(boolean only_active);
DTCNum_t ActiveDTCseverity(DTCSeverity_t severity);
DTCSeverity_t getSeverityForDTC(DTCNum_t targetCode);
void DTC_Process();
extern DTCEntry_s DTCStorage[MAX_DTC_STORAGE];
extern DTCEntry_t DTCStorage[MAX_DTC_STORAGE];
#endif

View File

@@ -0,0 +1,85 @@
/**
* @file dtc_defs.h
*
* @brief Header file for Diagnostic Trouble Code (DTC) definitions in the ChainLube application.
*
* This file contains definitions for Diagnostic Trouble Codes (DTC) in the ChainLube project.
* It includes enums for DTC active status, severity levels, and specific DTC codes.
* The file also defines an array of DTC definitions and a timestamp indicating the generation time.
*
* @note This file is auto-generated by a script on 2024-05-30 21:56:51.
*
* @author Marcel Peterkau
* @date 30.05.2024
*/
#ifndef DTC_DEFS_H
#define DTC_DEFS_H
#include <stdint.h>
typedef uint32_t DTCNum_t;
typedef enum
{
DTC_INACTIVE,
DTC_ACTIVE,
DTC_PREVIOUS
} DTCActive_t;
typedef enum
{
DTC_NONE,
DTC_INFO,
DTC_WARN,
DTC_CRITICAL
} DTCSeverity_t;
typedef struct {
DTCNum_t code;
DTCSeverity_t severity;
} DTC_t;
#define DTC_NO_DTC 0
#define DTC_BAT_CRITICAL 1
#define DTC_BAT_LOW 2
#define DTC_NO_EEPROM_FOUND 3
#define DTC_EEPROM_CFG_BAD 4
#define DTC_EEPROM_PDS_BAD 5
#define DTC_EEPROM_PDSADRESS_BAD 6
#define DTC_EEPROM_VERSION_BAD 7
#define DTC_FLASHFS_ERROR 8
#define DTC_FLASHFS_VERSION_ERROR 9
#define DTC_NO_BATMNON_FOUND 10
#define DTC_NO_LORA_FOUND 11
#define DTC_EEPROM_CFG_SANITY 12
#define DTC_EEPROM_MIGRATE_FAILED 13
#define DTC_FAKE_DTC_INFO 14
#define DTC_FAKE_DTC_WARN 15
#define DTC_FAKE_DTC_CRIT 16
#define DTC_LAST_DTC 17
const DTC_t dtc_definitions[] = {
{ DTC_NO_DTC , DTC_NONE }, // No Error
{ DTC_BAT_CRITICAL , DTC_CRITICAL }, // Akku ist komplett leer. Den Akku aufladen!
{ DTC_BAT_LOW , DTC_WARN }, // Akku ist unter der Warnschwelle. Den Akku demnächst aufladen
{ DTC_NO_EEPROM_FOUND , DTC_CRITICAL }, // Es wurde kein EEPROM gefunden. Dies lässt einen Hardware-Defekt vermuten.
{ DTC_EEPROM_CFG_BAD , DTC_CRITICAL }, // Die Checksumme der Config-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück
{ DTC_EEPROM_PDS_BAD , DTC_CRITICAL }, // Die Checksumme der Betriebsdaten-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück
{ DTC_EEPROM_PDSADRESS_BAD , DTC_CRITICAL }, // Die Adresse der Betriebsdaten-Partition im EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück
{ DTC_EEPROM_VERSION_BAD , DTC_CRITICAL }, // Die Layout-Version des EEPROM stimmt nicht mit der Firmware-Version überein. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück
{ DTC_FLASHFS_ERROR , DTC_CRITICAL }, // Der Flashspeicher konnte nicht initialisiert werden. Aktualisieren sie Flash & Firmware
{ DTC_FLASHFS_VERSION_ERROR , DTC_CRITICAL }, // Die Version des Flashspeicher stimmt nicht mit der Firmware-Version überein. Aktualisieren sie den Flash mit der passenden Update-Datei
{ DTC_NO_BATMNON_FOUND , DTC_CRITICAL }, // Es wurde keine Akkuüberwachung über I2C gefunden, Prüfen sie die Hardware!
{ DTC_NO_LORA_FOUND , DTC_CRITICAL }, // Es konnte keine Verbindung zum LoRa-Transceiver hergestellt werden. Prüfen Sie die Hardware auf Defekte
{ DTC_EEPROM_CFG_SANITY , DTC_WARN }, // Ein oder mehrer Einstellungswerte sind ausserhalb plausibler Werte. Prüfen Sie Ihre Einstellungen
{ DTC_EEPROM_MIGRATE_FAILED , DTC_CRITICAL }, // Es wurde ein altes EEPROm Image erkannt, konnte aber nicht migriert werden. EEPROM manuell zurück setzen und neue Einstellunge speichern.
{ DTC_FAKE_DTC_INFO , DTC_INFO }, // Ein Dummy-DTC der Schwere "Info" für Debugging-Zwecke
{ DTC_FAKE_DTC_WARN , DTC_WARN }, // Ein Dummy-DTC der Schwere "Warnung" für Debugging-Zwecke
{ DTC_FAKE_DTC_CRIT , DTC_CRITICAL }, // Ein Dummy-DTC der Schwere "Kritisch" für Debugging-Zwecke
{ DTC_LAST_DTC , DTC_NONE } // Last Error
};
#endif // DTC_DEFS_H
// CODEGENERATOR_CHECKSUM: 313d59949b074024df3c5d796f65e3bd518e34f0bb171185c30f008f21c19d30

View File

@@ -1,38 +1,63 @@
/**
* @file eeprom.h
*
* @brief Header file for configuration settings and EEPROM operations in the DE-Timer application.
*
* This file defines configuration settings for the DE-Timer project, including default values,
* EEPROM structures, and functions for EEPROM operations. It also defines enums for different sources
* of speed input, GPS baud rates, and CAN bus sources. Additionally, it includes functions for EEPROM handling
* such as storing, retrieving, and formatting configuration data.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _EEPROM_H_
#define _EEPROM_H_
#include <Arduino.h>
#include <Wire.h>
#include <I2C_eeprom.h>
#include "globals.h"
#include "dtc.h"
#include "common.h"
#include "debugger.h"
#define I2C_EE_ADDRESS 0x50
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC64
#define EEPROM_ENDURANCE 1000000
#define EEPROM_STRUCTURE_REVISION 3 // Increment this version when changing EEPROM structures
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC256
typedef enum
typedef enum Factions_e
{
NONE,
FACTION_1,
FACTION_2,
FACTION_3
} factions_t;
} Factions_t;
typedef enum EERequest_e
{
EE_IDLE,
EE_CFG_SAVE,
EE_CFG_LOAD,
EE_CFG_FORMAT,
EE_PDS_SAVE,
EE_PDS_LOAD,
EE_PDS_FORMAT,
EE_FORMAT_ALL,
EE_ALL_SAVE
} EERequest_t;
// Structure for persistence data stored in EEPROM
typedef struct
{
uint32_t writeCycleCounter = 0;
uint32_t faction_1_timer = 0;
uint32_t faction_2_timer = 0;
uint32_t faction_3_timer = 0;
factions_t activeFaction = NONE;
uint32_t checksum = 0;
uint32_t writeCycleCounter;
uint32_t faction_1_timer;
uint32_t faction_2_timer;
uint32_t faction_3_timer;
Factions_t activeFaction;
uint32_t checksum;
} persistenceData_t;
extern persistenceData_t PersistenceData;
typedef enum
{
BATTERY_UNDEFINED,
@@ -47,6 +72,7 @@ const char BatteryString[][10]{
const size_t BatteryString_Elements = sizeof(BatteryString) / sizeof(BatteryString[0]);
// Structure for configuration settings stored in EEPROM
typedef struct
{
uint8_t EEPROM_Version;
@@ -55,24 +81,30 @@ typedef struct
char Faction_1_Name[33];
char Faction_2_Name[33];
char Faction_3_Name[33];
char wifi_ap_ssid[33];
char wifi_ap_password[64];
char wifi_client_ssid[33];
char wifi_client_password[64];
bool wifi_autoconnect;
uint32_t checksum;
} configData_t;
extern configData_t ConfigData;
// Default configuration settings
const configData_t ConfigData_defaults = {
2, // EEPROM_Version (incerease this if anything on Layout changes!)
BATTERY_LIPO_3S, // batteryType
false, // active_faction_on_reboot
"FACTION 1", // Faction_1_Name
"FACTION 2", // Faction_2_Name
"FACTION 3", // Faction_3_Name
0 // checksum
2, // EEPROM_Version (incerease this if anything on Layout changes!)
BATTERY_LIPO_3S, // batteryType
false, // active_faction_on_reboot
"FACTION 1", // Faction_1_Name
"FACTION 2", // Faction_2_Name
"FACTION 3", // Faction_3_Name
"ChainLube",
QUOTE(WIFI_AP_PASSWORD),
QUOTE(WIFI_SSID_CLIENT),
QUOTE(WIFI_PASSWORD_CLIENT),
true,
0 // checksum
};
const uint16_t startofConfigData = 16;
const uint16_t startofPersistence = 16 + sizeof(ConfigData) + (sizeof(ConfigData) % 16);
void InitEEPROM();
void EEPROM_Process();
void StoreConfig_EEPROM();
@@ -85,5 +117,9 @@ uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
void MovePersistencePage_EEPROM(boolean reset);
uint32_t ConfigSanityCheck(bool autocorrect = false);
bool validateWiFiString(char *string, size_t size);
#endif // _EEPROM_H_
extern configData_t ConfigData;
extern persistenceData_t PersistenceData;
extern uint16_t eePersistenceMarker;
#endif // _CONFIG_H_

View File

@@ -2,68 +2,43 @@
#define _GLOBALS_H_
#include <Arduino.h>
typedef enum eSystem_Status
{
sysStat_null,
sysStat_Startup,
sysStat_Normal,
sysStat_Error,
sysStat_Shutdown
} tSystem_Status;
const char sSystem_Status_txt[][9] = {
"Null",
"Startup",
"Normal",
"Error",
"Shutdown"
};
typedef enum eEERequest
{
EE_IDLE,
EE_CFG_SAVE,
EE_CFG_LOAD,
EE_CFG_FORMAT,
EE_PDS_SAVE,
EE_PDS_LOAD,
EE_PDS_FORMAT,
EE_FORMAT_ALL,
EE_ALL_SAVE
} tEERequest;
#include "eeprom.h"
#include "common.h"
typedef struct Globals_s
{
char DeviceName[33];
char DeviceName_ID[43];
char FlashVersion[10];
tSystem_Status systemStatus = sysStat_Startup;
eEERequest requestEEAction = EE_IDLE;
uint16_t eePersistanceAdress;
tSystem_Status systemStatus = sysStat_Startup; /**< Current system status */
tSystem_Status resumeStatus = sysStat_Startup; /**< Status to resume after rain mode */
char systemStatustxt[16] = ""; /**< Text representation of system status */
EERequest_t requestEEAction = EE_IDLE; /**< EEPROM-related request */
char DeviceName[33]; /**< Device name */
char FlashVersion[10]; /**< Flash version */
uint16_t eePersistanceAdress; /**< EEPROM persistence address */
bool hasDTC;
int loadvoltage_mV = 0;
int battery_level = 0;
bool timer_disabled = false;
} Globals_t;
extern Globals_t globals;
extern Globals_t globals; /**< Global variable struct */
typedef struct Constants_s
{
uint8_t FW_Version_major;
uint8_t FW_Version_minor;
uint8_t Required_Flash_Version_major;
uint8_t Required_Flash_Version_minor;
char GitHash[11];
uint8_t FW_Version_major; /**< Firmware version major number */
uint8_t FW_Version_minor; /**< Firmware version minor number */
uint8_t Required_Flash_Version_major; /**< Required flash version major number */
uint8_t Required_Flash_Version_minor; /**< Required flash version minor number */
char GitHash[11]; /**< Git hash string */
} Constants_t;
const Constants_t constants PROGMEM = {
1,5, // Firmware_Version
1,4, // Required Flash Version
GIT_REV // Git-Hash-String
1, 4, // Firmware_Version
1, 4, // Required Flash Version
GIT_REV // Git-Hash-String
};
/**
* @brief Initializes global variables.
*/
void initGlobals();
#endif
#endif // _GLOBALS_H_

View File

@@ -0,0 +1,26 @@
/**
* @file struct2json.h
*
* @brief Header file for converting structs to JSON objects.
*
* @note This file is auto-generated by a script on 2024-05-30 22:54:25.
*
* @author Marcel Peterkau
* @date 30.05.2024
*/
#ifndef _STRUCT2JSON_H_
#define _STRUCT2JSON_H_
#include <Arduino.h>
#include <ArduinoJson.h>
#include "eeprom.h"
void generateJsonObject_ConfigData(JsonObject data);
void generateJsonObject_PersistenceData(JsonObject data);
#endif /* _STRUCT2JSON_H_ */
// CODEGENERATOR_CHECKSUM: 735cd4daf9a46bd773bdf5e6cd5a58d61b0d877196399bc2784a0d0ea7af717d

View File

@@ -1,3 +1,16 @@
/**
* @file webui.h
*
* @brief Header file for the web-based user interface (WebUI) in the ChainLube application.
*
* This file contains declarations for functions related to the initialization and processing of the
* web-based user interface (WebUI). It includes the necessary libraries and dependencies for handling
* web server functionality, asynchronous JSON operations, and live debugging through WebSockets.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _WEBUI_H_
#define _WEBUI_H_
@@ -11,14 +24,26 @@
#include <AsyncJson.h>
#include <ArduinoJson.h>
#include "eeprom.h"
#include "config.h"
#include "globals.h"
#include "dtc.h"
#include "common.h"
#include "debugger.h"
#include "struct2json.h"
typedef enum
{
info,
success,
warning,
error
} NotificationType_t;
void initWebUI();
void Webserver_Process();
void Websocket_PushLiveDebug(String Message);
void Webserver_Shutdown();
#endif
void Websocket_PushLiveDebug(String Message);
void Websocket_PushNotification(String Message, NotificationType_t type);
#endif // _WEBUI_H_