mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
add doxygen style comments to functions, and change function names for consistency
This commit is contained in:
parent
4c4b4eef81
commit
4e3dcf159b
12 changed files with 161 additions and 40 deletions
|
@ -199,7 +199,7 @@ void core_loop(void* task_time_us) {
|
||||||
receive_RS485(); // Process serial2 RS485 interface
|
receive_RS485(); // Process serial2 RS485 interface
|
||||||
#endif // RS485_INVERTER_SELECTED
|
#endif // RS485_INVERTER_SELECTED
|
||||||
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
||||||
runSerialDataLink();
|
run_serialDataLink();
|
||||||
#endif // SERIAL_LINK_RECEIVER || SERIAL_LINK_TRANSMITTER
|
#endif // SERIAL_LINK_RECEIVER || SERIAL_LINK_TRANSMITTER
|
||||||
END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us);
|
END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us);
|
||||||
#ifdef WEBSERVER
|
#ifdef WEBSERVER
|
||||||
|
|
|
@ -207,26 +207,6 @@ void receive_can(CAN_frame* rx_frame, int interface) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CANFD_ADDON
|
|
||||||
// Functions
|
|
||||||
void receive_canfd_addon() { // This section checks if we have a complete CAN-FD message incoming
|
|
||||||
CANFDMessage frame;
|
|
||||||
int count = 0;
|
|
||||||
while (canfd.available() && count++ < 16) {
|
|
||||||
canfd.receive(frame);
|
|
||||||
|
|
||||||
CAN_frame rx_frame;
|
|
||||||
rx_frame.ID = frame.id;
|
|
||||||
rx_frame.ext_ID = frame.ext;
|
|
||||||
rx_frame.DLC = frame.len;
|
|
||||||
memcpy(rx_frame.data.u8, frame.data, MIN(rx_frame.DLC, 64));
|
|
||||||
//message incoming, pass it on to the handler
|
|
||||||
receive_can(&rx_frame, CANFD_ADDON_MCP2518);
|
|
||||||
receive_can(&rx_frame, CANFD_NATIVE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // CANFD_ADDON
|
|
||||||
|
|
||||||
void receive_can_native() { // This section checks if we have a complete CAN message incoming on native CAN port
|
void receive_can_native() { // This section checks if we have a complete CAN message incoming on native CAN port
|
||||||
CAN_frame_t rx_frame_native;
|
CAN_frame_t rx_frame_native;
|
||||||
if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame_native, 0) == pdTRUE) {
|
if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame_native, 0) == pdTRUE) {
|
||||||
|
@ -267,6 +247,26 @@ void receive_can_addon() { // This section checks if we have a complete CAN mes
|
||||||
}
|
}
|
||||||
#endif // CAN_ADDON
|
#endif // CAN_ADDON
|
||||||
|
|
||||||
|
#ifdef CANFD_ADDON
|
||||||
|
// Functions
|
||||||
|
void receive_canfd_addon() { // This section checks if we have a complete CAN-FD message incoming
|
||||||
|
CANFDMessage frame;
|
||||||
|
int count = 0;
|
||||||
|
while (canfd.available() && count++ < 16) {
|
||||||
|
canfd.receive(frame);
|
||||||
|
|
||||||
|
CAN_frame rx_frame;
|
||||||
|
rx_frame.ID = frame.id;
|
||||||
|
rx_frame.ext_ID = frame.ext;
|
||||||
|
rx_frame.DLC = frame.len;
|
||||||
|
memcpy(rx_frame.data.u8, frame.data, MIN(rx_frame.DLC, 64));
|
||||||
|
//message incoming, pass it on to the handler
|
||||||
|
receive_can(&rx_frame, CANFD_ADDON_MCP2518);
|
||||||
|
receive_can(&rx_frame, CANFD_NATIVE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // CANFD_ADDON
|
||||||
|
|
||||||
// Support functions
|
// Support functions
|
||||||
void print_can_frame(CAN_frame frame, frameDirection msgDir) {
|
void print_can_frame(CAN_frame frame, frameDirection msgDir) {
|
||||||
#ifdef DEBUG_CAN_DATA // If enabled in user settings, print out the CAN messages via USB
|
#ifdef DEBUG_CAN_DATA // If enabled in user settings, print out the CAN messages via USB
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include "../../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h"
|
#include "../../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h"
|
||||||
#endif //CANFD_ADDON
|
#endif //CANFD_ADDON
|
||||||
|
|
||||||
|
enum frameDirection { MSG_RX, MSG_TX }; //RX = 0, TX = 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialization function for CAN.
|
* @brief Initialization function for CAN.
|
||||||
*
|
*
|
||||||
|
@ -24,19 +26,68 @@
|
||||||
*/
|
*/
|
||||||
void init_CAN();
|
void init_CAN();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transmit one CAN frame
|
||||||
|
*
|
||||||
|
* @param[in] CAN_frame* tx_frame
|
||||||
|
* @param[in] int interface
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void transmit_can();
|
void transmit_can();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send CAN messages to all components
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void send_can();
|
void send_can();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Receive CAN messages from all interfaces
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void receive_can();
|
void receive_can();
|
||||||
|
|
||||||
void receive_canfd_addon();
|
/**
|
||||||
|
* @brief Receive CAN messages from CAN tranceiver natively installed on Lilygo hardware
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void receive_can_native();
|
void receive_can_native();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Receive CAN messages from CAN addon chip
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void receive_can_addon();
|
void receive_can_addon();
|
||||||
|
|
||||||
enum frameDirection { MSG_RX, MSG_TX }; //RX = 0, TX = 1
|
/**
|
||||||
|
* @brief Receive CAN messages from CANFD addon chip
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void receive_canfd_addon();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief print CAN frames via USB
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void print_can_frame(CAN_frame frame, frameDirection msgDir);
|
void print_can_frame(CAN_frame frame, frameDirection msgDir);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,10 +6,31 @@
|
||||||
#include "../../datalayer/datalayer.h"
|
#include "../../datalayer/datalayer.h"
|
||||||
#include "../../devboard/utils/events.h"
|
#include "../../devboard/utils/events.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Contactor initialization
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void init_contactors();
|
void init_contactors();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle contactors
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void handle_contactors();
|
void handle_contactors();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle contactors of battery 2
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void handle_contactors_battery2();
|
void handle_contactors_battery2();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,8 +7,22 @@
|
||||||
#include "../../devboard/utils/debounce_button.h"
|
#include "../../devboard/utils/debounce_button.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialization of equipment stop button
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void init_equipment_stop_button();
|
void init_equipment_stop_button();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Monitor equipment stop button
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void monitor_equipment_stop_button();
|
void monitor_equipment_stop_button();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -78,7 +78,7 @@ void store_settings_equipment_stop() {
|
||||||
settings.end();
|
settings.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void storeSettings() {
|
void store_settings() {
|
||||||
// ATTENTION ! The maximum length for settings keys is 15 characters
|
// ATTENTION ! The maximum length for settings keys is 15 characters
|
||||||
if (!settings.begin("batterySettings", false)) {
|
if (!settings.begin("batterySettings", false)) {
|
||||||
set_event(EVENT_PERSISTENT_SAVE_INFO, 0);
|
set_event(EVENT_PERSISTENT_SAVE_INFO, 0);
|
||||||
|
|
|
@ -7,10 +7,31 @@
|
||||||
#include "../../devboard/utils/events.h"
|
#include "../../devboard/utils/events.h"
|
||||||
#include "../../devboard/wifi/wifi.h"
|
#include "../../devboard/wifi/wifi.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialization of setting storage
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void init_stored_settings();
|
void init_stored_settings();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Store settings of equipment stop button
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void store_settings_equipment_stop();
|
void store_settings_equipment_stop();
|
||||||
|
|
||||||
void storeSettings();
|
/**
|
||||||
|
* @brief Store settings
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void store_settings();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,6 +7,13 @@
|
||||||
#include "../../lib/eModbus-eModbus/ModbusServerRTU.h"
|
#include "../../lib/eModbus-eModbus/ModbusServerRTU.h"
|
||||||
#include "../../lib/eModbus-eModbus/scripts/mbServerFCs.h"
|
#include "../../lib/eModbus-eModbus/scripts/mbServerFCs.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialization of RS485
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void init_rs485();
|
void init_rs485();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,7 +18,7 @@ void init_serialDataLink() {
|
||||||
// Main functions
|
// Main functions
|
||||||
|
|
||||||
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
||||||
void runSerialDataLink() {
|
void run_serialDataLink() {
|
||||||
static unsigned long updateTime = 0;
|
static unsigned long updateTime = 0;
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,15 @@
|
||||||
|
|
||||||
#include "../../include.h"
|
#include "../../include.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialization of serial data link
|
||||||
|
*
|
||||||
|
* @param[in] void
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
void init_serialDataLink();
|
void init_serialDataLink();
|
||||||
|
|
||||||
void runSerialDataLink();
|
void run_serialDataLink();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -131,7 +131,7 @@ void init_webserver() {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
if (value.length() <= 63) { // Check if SSID is within the allowable length
|
if (value.length() <= 63) { // Check if SSID is within the allowable length
|
||||||
ssid = value.c_str();
|
ssid = value.c_str();
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "SSID must be 63 characters or less");
|
request->send(400, "text/plain", "SSID must be 63 characters or less");
|
||||||
|
@ -148,7 +148,7 @@ void init_webserver() {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
if (value.length() > 8) { // Check if password is within the allowable length
|
if (value.length() > 8) { // Check if password is within the allowable length
|
||||||
password = value.c_str();
|
password = value.c_str();
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Password must be atleast 8 characters");
|
request->send(400, "text/plain", "Password must be atleast 8 characters");
|
||||||
|
@ -165,7 +165,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.info.total_capacity_Wh = value.toInt();
|
datalayer.battery.info.total_capacity_Wh = value.toInt();
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
@ -179,7 +179,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.settings.soc_scaling_active = value.toInt();
|
datalayer.battery.settings.soc_scaling_active = value.toInt();
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
@ -193,7 +193,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.settings.max_percentage = static_cast<uint16_t>(value.toFloat() * 100);
|
datalayer.battery.settings.max_percentage = static_cast<uint16_t>(value.toFloat() * 100);
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
@ -237,7 +237,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.settings.min_percentage = static_cast<uint16_t>(value.toFloat() * 100);
|
datalayer.battery.settings.min_percentage = static_cast<uint16_t>(value.toFloat() * 100);
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
@ -251,7 +251,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.settings.max_user_set_charge_dA = static_cast<uint16_t>(value.toFloat() * 10);
|
datalayer.battery.settings.max_user_set_charge_dA = static_cast<uint16_t>(value.toFloat() * 10);
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
@ -265,7 +265,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.settings.max_user_set_discharge_dA = static_cast<uint16_t>(value.toFloat() * 10);
|
datalayer.battery.settings.max_user_set_discharge_dA = static_cast<uint16_t>(value.toFloat() * 10);
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
@ -279,7 +279,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.settings.user_set_voltage_limits_active = value.toInt();
|
datalayer.battery.settings.user_set_voltage_limits_active = value.toInt();
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
@ -293,7 +293,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.settings.max_user_set_charge_voltage_dV = static_cast<uint16_t>(value.toFloat() * 10);
|
datalayer.battery.settings.max_user_set_charge_voltage_dV = static_cast<uint16_t>(value.toFloat() * 10);
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
@ -307,7 +307,7 @@ void init_webserver() {
|
||||||
if (request->hasParam("value")) {
|
if (request->hasParam("value")) {
|
||||||
String value = request->getParam("value")->value();
|
String value = request->getParam("value")->value();
|
||||||
datalayer.battery.settings.max_user_set_discharge_voltage_dV = static_cast<uint16_t>(value.toFloat() * 10);
|
datalayer.battery.settings.max_user_set_discharge_voltage_dV = static_cast<uint16_t>(value.toFloat() * 10);
|
||||||
storeSettings();
|
store_settings();
|
||||||
request->send(200, "text/plain", "Updated successfully");
|
request->send(200, "text/plain", "Updated successfully");
|
||||||
} else {
|
} else {
|
||||||
request->send(400, "text/plain", "Bad Request");
|
request->send(400, "text/plain", "Bad Request");
|
||||||
|
|
|
@ -104,7 +104,7 @@ void onOTAEnd(bool success);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
String formatPowerValue(String label, T value, String unit, int precision, String color = "white");
|
String formatPowerValue(String label, T value, String unit, int precision, String color = "white");
|
||||||
|
|
||||||
extern void storeSettings();
|
extern void store_settings();
|
||||||
|
|
||||||
void ota_monitor();
|
void ota_monitor();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue