Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle glitched connections #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions TWCManager.py
100644 → 100755
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,21 @@ 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
ser.close()
ser.open()

# 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