Skip to content

Commit

Permalink
Resend Linkready if all slaves have dropped
Browse files Browse the repository at this point in the history
Signed-off-by: Alastair D'Silva <[email protected]>
  • Loading branch information
deece committed Nov 2, 2019
1 parent 18b5d08 commit 2be59b8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions TWCManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2be59b8

Please sign in to comment.