From a9da9156976d611414f61d74c444bf0dd48088b1 Mon Sep 17 00:00:00 2001 From: lenvm Date: Fri, 13 Dec 2024 17:31:19 +0100 Subject: [PATCH] add doxygen style comments to functions, and change function names for consistency --- Software/Software.ino | 2 +- Software/src/communication/can/comm_can.cpp | 40 ++++++------- Software/src/communication/can/comm_can.h | 57 ++++++++++++++++++- .../contactorcontrol/comm_contactorcontrol.h | 21 +++++++ .../comm_equipmentstopbutton.h | 14 +++++ Software/src/communication/nvm/comm_nvm.cpp | 2 +- Software/src/communication/nvm/comm_nvm.h | 23 +++++++- Software/src/communication/rs485/comm_rs485.h | 7 +++ .../seriallink/comm_seriallink.cpp | 2 +- .../seriallink/comm_seriallink.h | 9 ++- Software/src/devboard/webserver/webserver.cpp | 16 +++--- Software/src/devboard/webserver/webserver.h | 2 +- 12 files changed, 158 insertions(+), 37 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index 75edee02..efcb4051 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -199,7 +199,7 @@ void core_loop(void* task_time_us) { receive_RS485(); // Process serial2 RS485 interface #endif // RS485_INVERTER_SELECTED #if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER) - runSerialDataLink(); + run_serialDataLink(); #endif // SERIAL_LINK_RECEIVER || SERIAL_LINK_TRANSMITTER END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us); #ifdef WEBSERVER diff --git a/Software/src/communication/can/comm_can.cpp b/Software/src/communication/can/comm_can.cpp index 098d8cbe..8d7923fd 100644 --- a/Software/src/communication/can/comm_can.cpp +++ b/Software/src/communication/can/comm_can.cpp @@ -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 CAN_frame_t rx_frame_native; 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 +#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 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 diff --git a/Software/src/communication/can/comm_can.h b/Software/src/communication/can/comm_can.h index 81c046f1..48e3c9c3 100644 --- a/Software/src/communication/can/comm_can.h +++ b/Software/src/communication/can/comm_can.h @@ -15,6 +15,8 @@ #include "../../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h" #endif //CANFD_ADDON +enum frameDirection { MSG_RX, MSG_TX }; //RX = 0, TX = 1 + /** * @brief Initialization function for CAN. * @@ -24,19 +26,68 @@ */ void init_CAN(); +/** + * @brief Transmit one CAN frame + * + * @param[in] CAN_frame* tx_frame + * @param[in] int interface + * + * @return void + */ void transmit_can(); +/** + * @brief Send CAN messages to all components + * + * @param[in] void + * + * @return void + */ void send_can(); +/** + * @brief Receive CAN messages from all interfaces + * + * @param[in] void + * + * @return void + */ 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(); +/** + * @brief Receive CAN messages from CAN addon chip + * + * @param[in] void + * + * @return void + */ 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); #endif diff --git a/Software/src/communication/contactorcontrol/comm_contactorcontrol.h b/Software/src/communication/contactorcontrol/comm_contactorcontrol.h index 1e7cf0f5..2f4e1e0c 100644 --- a/Software/src/communication/contactorcontrol/comm_contactorcontrol.h +++ b/Software/src/communication/contactorcontrol/comm_contactorcontrol.h @@ -6,10 +6,31 @@ #include "../../datalayer/datalayer.h" #include "../../devboard/utils/events.h" +/** + * @brief Contactor initialization + * + * @param[in] void + * + * @return void + */ void init_contactors(); +/** + * @brief Handle contactors + * + * @param[in] void + * + * @return void + */ void handle_contactors(); +/** + * @brief Handle contactors of battery 2 + * + * @param[in] void + * + * @return void + */ void handle_contactors_battery2(); #endif diff --git a/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h b/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h index 543c4182..f4f5a989 100644 --- a/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h +++ b/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h @@ -7,8 +7,22 @@ #include "../../devboard/utils/debounce_button.h" #endif +/** + * @brief Initialization of equipment stop button + * + * @param[in] void + * + * @return void + */ void init_equipment_stop_button(); +/** + * @brief Monitor equipment stop button + * + * @param[in] void + * + * @return void + */ void monitor_equipment_stop_button(); #endif diff --git a/Software/src/communication/nvm/comm_nvm.cpp b/Software/src/communication/nvm/comm_nvm.cpp index 32f9f931..03afbee0 100644 --- a/Software/src/communication/nvm/comm_nvm.cpp +++ b/Software/src/communication/nvm/comm_nvm.cpp @@ -78,7 +78,7 @@ void store_settings_equipment_stop() { settings.end(); } -void storeSettings() { +void store_settings() { // ATTENTION ! The maximum length for settings keys is 15 characters if (!settings.begin("batterySettings", false)) { set_event(EVENT_PERSISTENT_SAVE_INFO, 0); diff --git a/Software/src/communication/nvm/comm_nvm.h b/Software/src/communication/nvm/comm_nvm.h index eaeafca5..eb624e89 100644 --- a/Software/src/communication/nvm/comm_nvm.h +++ b/Software/src/communication/nvm/comm_nvm.h @@ -7,10 +7,31 @@ #include "../../devboard/utils/events.h" #include "../../devboard/wifi/wifi.h" +/** + * @brief Initialization of setting storage + * + * @param[in] void + * + * @return void + */ void init_stored_settings(); +/** + * @brief Store settings of equipment stop button + * + * @param[in] void + * + * @return void + */ void store_settings_equipment_stop(); -void storeSettings(); +/** + * @brief Store settings + * + * @param[in] void + * + * @return void + */ +void store_settings(); #endif diff --git a/Software/src/communication/rs485/comm_rs485.h b/Software/src/communication/rs485/comm_rs485.h index d4fd97c2..b4077dd4 100644 --- a/Software/src/communication/rs485/comm_rs485.h +++ b/Software/src/communication/rs485/comm_rs485.h @@ -7,6 +7,13 @@ #include "../../lib/eModbus-eModbus/ModbusServerRTU.h" #include "../../lib/eModbus-eModbus/scripts/mbServerFCs.h" +/** + * @brief Initialization of RS485 + * + * @param[in] void + * + * @return void + */ void init_rs485(); #endif diff --git a/Software/src/communication/seriallink/comm_seriallink.cpp b/Software/src/communication/seriallink/comm_seriallink.cpp index a08bb3c9..b355ae97 100644 --- a/Software/src/communication/seriallink/comm_seriallink.cpp +++ b/Software/src/communication/seriallink/comm_seriallink.cpp @@ -18,7 +18,7 @@ void init_serialDataLink() { // Main functions #if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER) -void runSerialDataLink() { +void run_serialDataLink() { static unsigned long updateTime = 0; unsigned long currentMillis = millis(); diff --git a/Software/src/communication/seriallink/comm_seriallink.h b/Software/src/communication/seriallink/comm_seriallink.h index 277165aa..c88b3437 100644 --- a/Software/src/communication/seriallink/comm_seriallink.h +++ b/Software/src/communication/seriallink/comm_seriallink.h @@ -3,8 +3,15 @@ #include "../../include.h" +/** + * @brief Initialization of serial data link + * + * @param[in] void + * + * @return void + */ void init_serialDataLink(); -void runSerialDataLink(); +void run_serialDataLink(); #endif diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index ff7770ee..0b815844 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -131,7 +131,7 @@ void init_webserver() { String value = request->getParam("value")->value(); if (value.length() <= 63) { // Check if SSID is within the allowable length ssid = value.c_str(); - storeSettings(); + store_settings(); request->send(200, "text/plain", "Updated successfully"); } else { 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(); if (value.length() > 8) { // Check if password is within the allowable length password = value.c_str(); - storeSettings(); + store_settings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Password must be atleast 8 characters"); @@ -165,7 +165,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); datalayer.battery.info.total_capacity_Wh = value.toInt(); - storeSettings(); + store_settings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -179,7 +179,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); datalayer.battery.settings.soc_scaling_active = value.toInt(); - storeSettings(); + store_settings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -193,7 +193,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); datalayer.battery.settings.max_percentage = static_cast(value.toFloat() * 100); - storeSettings(); + store_settings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -237,7 +237,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); datalayer.battery.settings.min_percentage = static_cast(value.toFloat() * 100); - storeSettings(); + store_settings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -251,7 +251,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); datalayer.battery.settings.max_user_set_charge_dA = static_cast(value.toFloat() * 10); - storeSettings(); + store_settings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -265,7 +265,7 @@ void init_webserver() { if (request->hasParam("value")) { String value = request->getParam("value")->value(); datalayer.battery.settings.max_user_set_discharge_dA = static_cast(value.toFloat() * 10); - storeSettings(); + store_settings(); request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); diff --git a/Software/src/devboard/webserver/webserver.h b/Software/src/devboard/webserver/webserver.h index 21416850..a75ef8fb 100644 --- a/Software/src/devboard/webserver/webserver.h +++ b/Software/src/devboard/webserver/webserver.h @@ -104,7 +104,7 @@ void onOTAEnd(bool success); template String formatPowerValue(String label, T value, String unit, int precision, String color = "white"); -extern void storeSettings(); +extern void store_settings(); void ota_monitor();