diff --git a/Software/src/inverter/INVERTERS.h b/Software/src/inverter/INVERTERS.h index 97527c2b..9d8825f7 100644 --- a/Software/src/inverter/INVERTERS.h +++ b/Software/src/inverter/INVERTERS.h @@ -29,4 +29,8 @@ #include "SOLAX-CAN.h" #endif +#ifdef SERIAL_LINK_TRANSMITTER_INVERTER +#include "SERIAL-LINK-TRANSMITTER-INVERTER.h" +#endif + #endif diff --git a/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.cpp b/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.cpp new file mode 100644 index 00000000..f25479cd --- /dev/null +++ b/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.cpp @@ -0,0 +1,81 @@ +//SERIAL-LINK-TRANSMITTER-INVERTER.cpp + +#include "SERIAL-LINK-TRANSMITTER-INVERTER.h" + +/* +* SerialDataLink +* txid=1, rxid=0 gives this the startup transmit priority_queue +* Will transmit max 16 int variable - receive none +*/ + +#define BATTERY_SEND_NUM_VARIABLES 16 +#define BATTERY_RECV_NUM_VARIABLES 3 //--- comment out if nothing to receive + +#ifdef BATTERY_RECV_NUM_VARIABLES + const uint8_t receivingNumVariables = BATTERY_RECV_NUM_VARIABLES; +#else + const uint8_t receivingNumVariables = 0; +#endif + +// txid,rxid,num_tx,num_rx +SerialDataLink dataLinkTransmit(Serial2, 0x01, 0, BATTERY_SEND_NUM_VARIABLES, + receivingNumVariables ); + + +void _getData() +{ + /* + var1 = dataLinkTransmit.getReceivedData(0); + var2 = dataLinkTransmit.getReceivedData(1); + var3 = dataLinkTransmit.getReceivedData(2); + */ +} + + +void manageSerialLinkTransmitter() +{ + static bool initLink=false; + static unsigned long updateTime = 0; + + dataLinkTransmit.run(); + + #ifdef BATTERY_RECV_NUM_VARIABLES + bool readError = dataLinkTransmit.checkReadError(true); // check for error & clear error flag + if (dataLinkTransmit.checkNewData(true)) // true = clear Flag + { + _getData(); + } + #endif + + if (millis() - updateTime > 100) + { + updateTime = millis(); + if (! initLink) + { + initLink = true; + // sends variables every 5000mS even if no change + dataLinkTransmit.setUpdateInterval(5000); + } + bool sendError = dataLinkTransmit.checkTransmissionError(true); + // todo some error management - LEDS etc + + dataLinkTransmit.updateData(0,SOC); + dataLinkTransmit.updateData(1,StateOfHealth); + dataLinkTransmit.updateData(2,battery_voltage); + dataLinkTransmit.updateData(3,battery_current); + dataLinkTransmit.updateData(4,capacity_Wh); + dataLinkTransmit.updateData(5,remaining_capacity_Wh); + dataLinkTransmit.updateData(6,max_target_discharge_power); + dataLinkTransmit.updateData(7,max_target_charge_power); + dataLinkTransmit.updateData(8,bms_status); + dataLinkTransmit.updateData(9,bms_char_dis_status); + dataLinkTransmit.updateData(10,stat_batt_power); + dataLinkTransmit.updateData(11,temperature_min); + dataLinkTransmit.updateData(12,temperature_max); + dataLinkTransmit.updateData(13,cell_max_voltage); + dataLinkTransmit.updateData(14,cell_min_voltage); + dataLinkTransmit.updateData(15,batteryAllowsContactorClosing); + } + + +} \ No newline at end of file diff --git a/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.h b/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.h new file mode 100644 index 00000000..8a54741e --- /dev/null +++ b/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.h @@ -0,0 +1,41 @@ +//SERIAL-LINK-TRANSMITTER-INVERTER.h + +#ifndef SERIAL_LINK_TRANSMITTER_INVERTER_H +#define SERIAL_LINK_TRANSMITTER_INVERTER_H + + +#include +#include "../../USER_SETTINGS.h" +#include "../lib/SerialDataLink/SerialDataLink.h" + + +// These parameters need to be mapped for the inverter +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint16_t bms_status; //Enum, 0-5 +extern uint16_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t cell_max_voltage; //mV, 0-4350 +extern uint16_t cell_min_voltage; //mV, 0-4350 +extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false + + + +void manageSerialLinkTransmitter(); + + + + + + + + +#endif \ No newline at end of file