Skip to content

Commit

Permalink
Code review by Dala
Browse files Browse the repository at this point in the history
  • Loading branch information
dalathegreat committed Dec 20, 2023
1 parent 2ab1970 commit bc6beaf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
16 changes: 11 additions & 5 deletions Software/Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void setup() {
init_contactors();

init_modbus();

init_serialDataLink();

inform_user_on_inverter();
Expand Down Expand Up @@ -241,6 +242,11 @@ void init_modbus() {
handle_static_data_modbus_byd();
#endif
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS)
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
// Check that Dual LilyGo via RS485 option isn't enabled, this collides with Modbus!
#error MODBUS CANNOT BE USED IN DOUBLE LILYGO SETUPS! CHECK USER SETTINGS!
#endif

// Init Serial2 connected to the RTU Modbus
RTUutils::prepareHardwareSerial(Serial2);
Serial2.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN);
Expand Down Expand Up @@ -627,18 +633,18 @@ void update_values() {
}

void runSerialDataLink() {
static unsigned long sdlTimer = 0;
static unsigned long updateTime = 0;
unsigned long currentMillis = millis();
#ifdef SERIAL_LINK_RECEIVER
if (currentMillis - sdlTimer >= 1) { //--- try 2 second
sdlTimer = currentMillis;
if ((currentMillis - updateTime) > 1) { //Every 2ms
updateTime = currentMillis;
manageSerialLinkReceiver();
}
#endif

#ifdef SERIAL_LINK_TRANSMITTER
if (currentMillis - sdlTimer >= 1) { //--- try 2 second
sdlTimer = currentMillis;
if ((currentMillis - updateTime) > 1) { //Every 2ms
updateTime = currentMillis;
manageSerialLinkTransmitter();
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Software/USER_SETTINGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for FoxESS inverters)
//#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter)
//#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery)
#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver
//#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver

#endif
8 changes: 3 additions & 5 deletions Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const uint8_t sendingNumVariables = 0;
#define SerialReceiver Serial2
#endif

#define REPORT_SDL_DATA 1

// txid,rxid, num_send,num_recv
SerialDataLink dataLinkReceive(SerialReceiver, 0, 0x01, sendingNumVariables,
INVERTER_RECV_NUM_VARIABLES); // ...
Expand Down Expand Up @@ -55,8 +53,8 @@ void __getData() {
void updateData() {
// --- update with fresh data
dataLinkReceive.updateData(0, inverterAllowsContactorClosing);
//dataLinkReceive.updateData(1,var2);
//dataLinkReceive.updateData(2,var3);
//dataLinkReceive.updateData(1,var2); // For future expansion,
//dataLinkReceive.updateData(2,var3); // if inverter needs to send data to battery
}

/*
Expand Down Expand Up @@ -156,7 +154,7 @@ void manageSerialLinkReceiver() {
// --- printUsefullData();
//Serial.print("SOC = ");
//Serial.println(SOC);
#ifdef REPORT_SDL_DATA
#ifdef DEBUG_VIA_USB
update_values_serial_link();
#endif
}
Expand Down
8 changes: 3 additions & 5 deletions Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ const uint8_t receivingNumVariables = BATTERY_RECV_NUM_VARIABLES;
const uint8_t receivingNumVariables = 0;
#endif

//#define REPORT_SDL_DATA 1

// txid,rxid,num_tx,num_rx
SerialDataLink dataLinkTransmit(Serial2, 0x01, 0, BATTERY_SEND_NUM_VARIABLES, receivingNumVariables);

void printSendingValues();

void _getData() {
inverterAllowsContactorClosing = dataLinkTransmit.getReceivedData(0);
//var2 = dataLinkTransmit.getReceivedData(1);
//var3 = dataLinkTransmit.getReceivedData(2);
//var2 = dataLinkTransmit.getReceivedData(1); // For future expansion,
//var3 = dataLinkTransmit.getReceivedData(2); // if inverter needs to send data to battery
}

void manageSerialLinkTransmitter() {
Expand Down Expand Up @@ -92,7 +90,7 @@ void manageSerialLinkTransmitter() {
Serial.print(currentTime);
Serial.println(" - Transmit Good");
// printUsefullData();
#ifdef REPORT_SDL_DATA
#ifdef DEBUG_VIA_USB
void printSendingValues();
#endif
}
Expand Down

0 comments on commit bc6beaf

Please sign in to comment.