From 2be59b87a1b5f8b4c3e2f23c64c39ca9732381d5 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Mon, 28 Oct 2019 11:07:08 +1100 Subject: [PATCH 1/2] Resend Linkready if all slaves have dropped Signed-off-by: Alastair D'Silva --- TWCManager.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/TWCManager.py b/TWCManager.py index f0fbde4e..feaa0a90 100644 --- a/TWCManager.py +++ b/TWCManager.py @@ -649,6 +649,10 @@ def delete_slave(deleteSlaveID): except KeyError: pass +def slave_count(): + global slaveTWCs + return len(slaveTWCs) + def total_amps_actual_all_twcs(): global debugLevel, slaveTWCRoundRobin, wiringMaxAmpsAllTWCs @@ -2559,17 +2563,19 @@ def set_last_amps_offered(self, desiredAmpsOffered): now = time.time() if(fakeMaster == 1): + # If we have no slaves, try to re-establish the connection + if (numInitMsgsToSend == 0 and slave_count() == 0): + numInitMsgsToSend = 10 + # A real master sends 5 copies of linkready1 and linkready2 whenever # it starts up, which we do here. - # It doesn't seem to matter if we send these once per second or once - # per 100ms so I do once per 100ms to get them over with. if(numInitMsgsToSend > 5): send_master_linkready1() - time.sleep(0.1) # give slave time to respond + time.sleep(1) # give slave time to respond numInitMsgsToSend -= 1 elif(numInitMsgsToSend > 0): send_master_linkready2() - time.sleep(0.1) # give slave time to respond + time.sleep(1) # give slave time to respond numInitMsgsToSend = numInitMsgsToSend - 1 else: # After finishing the 5 startup linkready1 and linkready2 From ee21cafdba3fcdc8366cdfb61b4dce3c120a7f2d Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 29 Oct 2019 11:00:12 +1100 Subject: [PATCH 2/2] Reopen serial port if all slaves drop Signed-off-by: Alastair D'Silva --- TWCManager.py | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 TWCManager.py diff --git a/TWCManager.py b/TWCManager.py old mode 100644 new mode 100755 index feaa0a90..c1500f82 --- a/TWCManager.py +++ b/TWCManager.py @@ -2566,6 +2566,8 @@ def set_last_amps_offered(self, desiredAmpsOffered): # If we have no slaves, try to re-establish the connection if (numInitMsgsToSend == 0 and slave_count() == 0): numInitMsgsToSend = 10 + ser.close() + ser.open() # A real master sends 5 copies of linkready1 and linkready2 whenever # it starts up, which we do here.