Update OTA GUI to v1.6
This commit is contained in:
parent
95e6e1526c
commit
ac9b1acf8b
|
|
@ -41,6 +41,7 @@
|
||||||
import time, sys, serial
|
import time, sys, serial
|
||||||
import collections
|
import collections
|
||||||
import re
|
import re
|
||||||
|
from sys import exit
|
||||||
|
|
||||||
### GENERAL SETTINGS ###
|
### GENERAL SETTINGS ###
|
||||||
SERIALPORT = "COM100" # the default com/serial port the receiver is connected to
|
SERIALPORT = "COM100" # the default com/serial port the receiver is connected to
|
||||||
|
|
@ -87,6 +88,12 @@ if (sys.argv and len(sys.argv) > 1):
|
||||||
exit(1)
|
exit(1)
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
def LOG(message):
|
||||||
|
sys.stdout.write(message)
|
||||||
|
|
||||||
|
def LOGln(message):
|
||||||
|
sys.stdout.write('\n' + message)
|
||||||
|
|
||||||
def millis():
|
def millis():
|
||||||
return int(round(time.time() * 1000))
|
return int(round(time.time() * 1000))
|
||||||
|
|
||||||
|
|
@ -108,21 +115,21 @@ def waitForHandshake(isEOF=False):
|
||||||
serWriteln(ser, "FLX?EOF")
|
serWriteln(ser, "FLX?EOF")
|
||||||
else:
|
else:
|
||||||
serWriteln(ser, "FLX?")
|
serWriteln(ser, "FLX?")
|
||||||
print "FLX?\n"
|
LOGln("FLX?")
|
||||||
ser.flush()
|
ser.flush()
|
||||||
rx = ser.readline().rstrip().upper()
|
rx = ser.readline().rstrip().upper()
|
||||||
|
|
||||||
if len(rx) > 0:
|
if len(rx) > 0:
|
||||||
#{
|
#{
|
||||||
print "Moteino: [" + rx + "]"
|
LOGln("Moteino: [" + rx + "]")
|
||||||
if rx == "FLX?OK":
|
if rx == "FLX?OK":
|
||||||
print "HANDSHAKE OK!"
|
LOGln("HANDSHAKE OK!")
|
||||||
return HANDSHAKE_OK
|
return HANDSHAKE_OK
|
||||||
elif rx == "FLX?NOK":
|
elif rx == "FLX?NOK":
|
||||||
print "HANDSHAKE FAIL [TIMEOUT]: " + rx
|
LOGln("HANDSHAKE FAIL [TIMEOUT]: " + rx)
|
||||||
return HANDSHAKE_FAIL
|
return HANDSHAKE_FAIL
|
||||||
elif (len(rx)>7 and rx.startswith("FLX?NOK") or rx.startswith("FLX?ERR")):
|
elif (len(rx)>7 and rx.startswith("FLX?NOK") or rx.startswith("FLX?ERR")):
|
||||||
print "HANDSHAKE FAIL [HEX IMG refused by target node], reason: " + rx
|
LOGln("HANDSHAKE FAIL [HEX IMG refused by target node], reason: " + rx)
|
||||||
return HANDSHAKE_FAIL_ERROR
|
return HANDSHAKE_FAIL_ERROR
|
||||||
#}
|
#}
|
||||||
#}
|
#}
|
||||||
|
|
@ -131,7 +138,7 @@ def waitForHandshake(isEOF=False):
|
||||||
def waitForTargetSet(targetNode):
|
def waitForTargetSet(targetNode):
|
||||||
now = millis()
|
now = millis()
|
||||||
to = "TO:" + str(TARGET)
|
to = "TO:" + str(TARGET)
|
||||||
print to
|
LOGln(to)
|
||||||
serWriteln(ser, to)
|
serWriteln(ser, to)
|
||||||
ser.flush()
|
ser.flush()
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -141,7 +148,7 @@ def waitForTargetSet(targetNode):
|
||||||
rx = ser.readline().rstrip()
|
rx = ser.readline().rstrip()
|
||||||
if len(rx) > 0:
|
if len(rx) > 0:
|
||||||
#{
|
#{
|
||||||
print "Moteino: [" + rx + "]"
|
LOGln("Moteino: [" + rx + "]")
|
||||||
if rx == to + ":OK":
|
if rx == to + ":OK":
|
||||||
return True
|
return True
|
||||||
else: return False
|
else: return False
|
||||||
|
|
@ -159,19 +166,21 @@ def waitForSEQ(seq):
|
||||||
|
|
||||||
if (rx.upper().startswith("RFTX >") or rx.upper().startswith("RFACK >")):
|
if (rx.upper().startswith("RFTX >") or rx.upper().startswith("RFACK >")):
|
||||||
#{
|
#{
|
||||||
print "Moteino DEBUG: " + rx
|
LOGln("Moteino DEBUG: " + rx)
|
||||||
rx = ""
|
rx = ""
|
||||||
continue
|
continue
|
||||||
#}
|
#}
|
||||||
|
|
||||||
if len(rx) > 0:
|
if len(rx) > 0:
|
||||||
#{
|
#{
|
||||||
print "Moteino: " + rx
|
pattern = "FLX:([0-9]*):OK"
|
||||||
result = re.match("FLX:([0-9]*):OK", rx)
|
LOG(" RX > " + rx)
|
||||||
|
result = re.match(pattern, rx)
|
||||||
if result != None:
|
if result != None:
|
||||||
if int(result.group(1)) == seq:
|
if int(result.group(1)) == seq:
|
||||||
return 1
|
return 1
|
||||||
else: return 2
|
else: return 2
|
||||||
|
else: LOGln("Programmer reply '"+rx+"' does not match expected pattern: '"+pattern+"'")
|
||||||
#}
|
#}
|
||||||
else: return 0
|
else: return 0
|
||||||
|
|
||||||
|
|
@ -186,23 +195,23 @@ try:
|
||||||
time.sleep(2) #wait for Programmer Moteino reset after port open and potential bootloader time (~1.6s)
|
time.sleep(2) #wait for Programmer Moteino reset after port open and potential bootloader time (~1.6s)
|
||||||
ser.flushInput();
|
ser.flushInput();
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print "COM Port [", SERIALPORT, "] not found, exiting..."
|
LOGln("COM Port [", SERIALPORT, "] not found, exiting...")
|
||||||
exit(1)
|
exitNow(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not 0<TARGET<= 255:
|
if not 0<TARGET<= 255:
|
||||||
print "TARGET not provided (use -h for help), now exiting..."
|
LOGln("TARGET not provided (use -h for help), now exiting...")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
#send target ID first
|
#send target ID first
|
||||||
if waitForTargetSet(TARGET):
|
if waitForTargetSet(TARGET):
|
||||||
print "TARGET SET OK"
|
LOGln("TARGET SET OK")
|
||||||
else:
|
else:
|
||||||
print "TARGET SET FAIL, exiting..."
|
LOGln("TARGET SET FAIL, exiting...")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
with open(HEX) as f:
|
with open(HEX) as f:
|
||||||
print "File found, passing to Moteino..."
|
LOGln("File found, passing to Moteino OTA Programmer...")
|
||||||
|
|
||||||
handshakeResponse = waitForHandshake()
|
handshakeResponse = waitForHandshake()
|
||||||
if (handshakeResponse == HANDSHAKE_OK):
|
if (handshakeResponse == HANDSHAKE_OK):
|
||||||
|
|
@ -222,44 +231,46 @@ try:
|
||||||
hexDataToSend = currentLine
|
hexDataToSend = currentLine
|
||||||
|
|
||||||
#bundle 2 or 3 HEX lines in 1 RF packet (assuming: 1 HEX line has 16 bytes of data, following HEX lines also each being 16 bytes)
|
#bundle 2 or 3 HEX lines in 1 RF packet (assuming: 1 HEX line has 16 bytes of data, following HEX lines also each being 16 bytes)
|
||||||
if LINESPERPACKET > 1 and currentLine[1:3] == '10' and len(currentLine)==43:
|
if LINESPERPACKET > 1 and currentLine[7:9] == '00':
|
||||||
#{
|
#{
|
||||||
#check if next line != EOF, so we can bundle 2 lines
|
#check if next line != EOF, so we can bundle 2 lines
|
||||||
nextLine = content[seq+1].strip()
|
nextLine = content[seq+1].strip()
|
||||||
if nextLine != ":00000001FF" and nextLine[1:3] == "10" and len(nextLine) == 43:
|
if nextLine != ":00000001FF" and nextLine[7:9] == '00':
|
||||||
#{
|
#{
|
||||||
#need to sum: the 2 lines checksums + address bytes of nextLine (to arrive at a correct final checksum of combined 2 lines
|
#need to sum: the 2 lines checksums + address bytes of nextLine (to arrive at a correct final checksum of combined 2 lines
|
||||||
checksum = int(currentLine[41:43], 16) + int(nextLine[41:43], 16) + int(nextLine[3:5], 16) + int(nextLine[5:7], 16)
|
checksum = int(currentLine[len(currentLine)-2:len(currentLine)], 16) + int(nextLine[len(nextLine)-2:len(nextLine)], 16) + int(nextLine[3:5], 16) + int(nextLine[5:7], 16)
|
||||||
|
addressByte = int(currentLine[1:3], 16) + int(nextLine[1:3], 16)
|
||||||
|
|
||||||
#check if a third line != EOF, so we can bundle 3 lines
|
#check if a third line != EOF, so we can bundle 3 lines
|
||||||
nextLine2 = content[seq+2].strip()
|
nextLine2 = content[seq+2].strip()
|
||||||
if LINESPERPACKET==3 and nextLine2 != ":00000001FF" and nextLine2[1:3] == "10" and len(nextLine2) == 43:
|
if LINESPERPACKET==3 and nextLine2 != ":00000001FF" and nextLine2[7:9] == "00":
|
||||||
#{
|
#{
|
||||||
#need to sum: the previous checksum + address bytes of nextLine2 (to arrive at a correct final checksum of combined 3 lines
|
#need to sum: the previous checksum + address bytes of nextLine2 (to arrive at a correct final checksum of combined 3 lines
|
||||||
checksum += int(nextLine2[41:43], 16) + int(nextLine2[3:5], 16) + int(nextLine2[5:7], 16)
|
checksum += int(nextLine2[len(nextLine2)-2:len(nextLine2)], 16) + int(nextLine2[3:5], 16) + int(nextLine2[5:7], 16)
|
||||||
hexDataToSend = ":3" + hexDataToSend[2:(len(hexDataToSend)-2)] + nextLine[9:41] + nextLine2[9:41] + ('%0*X' % (2,checksum%256))
|
addressByte += int(nextLine2[1:3], 16)
|
||||||
|
hexDataToSend = ":" + ('%0*X' % (2,addressByte%256)) + hexDataToSend[3:len(hexDataToSend)-2] + nextLine[9:len(nextLine)-2] + nextLine2[9:len(nextLine)-2] + ('%0*X' % (2,checksum%256))
|
||||||
bundledLines=3
|
bundledLines=3
|
||||||
#}
|
#}
|
||||||
else:
|
else:
|
||||||
#{
|
#{
|
||||||
hexDataToSend = ":2" + hexDataToSend[2:(len(hexDataToSend)-2)] + nextLine[9:41] + ('%0*X' % (2,checksum%256))
|
hexDataToSend = ":" + ('%0*X' % (2,addressByte%256)) + hexDataToSend[3:len(hexDataToSend)-2] + nextLine[9:len(nextLine)-2] + ('%0*X' % (2,checksum%256))
|
||||||
bundledLines=2;
|
bundledLines=2;
|
||||||
#}
|
#}
|
||||||
#}
|
#}
|
||||||
#}
|
#}
|
||||||
tx = "FLX:" + str(packetCounter) + hexDataToSend
|
tx = "FLX:" + str(packetCounter) + hexDataToSend
|
||||||
print "TX > " + tx
|
LOGln("TX > " + tx)
|
||||||
serWriteln(ser, tx)
|
serWriteln(ser, tx)
|
||||||
result = waitForSEQ(packetCounter)
|
result = waitForSEQ(packetCounter)
|
||||||
#}
|
#}
|
||||||
elif waitForHandshake(True) == HANDSHAKE_OK:
|
elif waitForHandshake(True) == HANDSHAKE_OK:
|
||||||
#{
|
#{
|
||||||
print "SUCCESS! (time elapsed: " + ("%.2f" % ((millis()-start)/1000.0)) + "s)"
|
LOGln("SUCCESS! (time elapsed: " + ("%.2f" % ((millis()-start)/1000.0)) + "s)")
|
||||||
exit(0);
|
exit(0);
|
||||||
#}
|
#}
|
||||||
else:
|
else:
|
||||||
#{
|
#{
|
||||||
print "FAIL, IMG REFUSED BY TARGET (size exceeded? verify target MCU matches compiled target)"
|
LOGln("FAIL, IMG REFUSED BY TARGET (size exceeded? verify target MCU matches compiled target)")
|
||||||
exit(99)
|
exit(99)
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
|
@ -272,21 +283,21 @@ try:
|
||||||
#{
|
#{
|
||||||
if retries > 0:
|
if retries > 0:
|
||||||
retries-=1
|
retries-=1
|
||||||
print "OUT OF SYNC: retrying...\n"
|
LOGln("OUT OF SYNC: retrying...\n")
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
print "FAIL: out of sync (are you running the latest OTA libs/sources?)"
|
LOGln("FAIL: out of sync (are you running the latest OTA libs/sources?)")
|
||||||
exit(1)
|
exit(1)
|
||||||
#}
|
#}
|
||||||
else:
|
else:
|
||||||
#{
|
#{
|
||||||
if retries > 0:
|
if retries > 0:
|
||||||
retries-=1
|
retries-=1
|
||||||
print "Timeout, retry...\n"
|
LOGln("Timeout, retry...\n")
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
#{
|
#{
|
||||||
print "FAIL: timeout (are you running the latest OTA libs/sources?)"
|
LOGln("FAIL: timeout (are you running the latest OTA libs/sources?)")
|
||||||
exit(1)
|
exit(1)
|
||||||
#}
|
#}
|
||||||
#}
|
#}
|
||||||
|
|
@ -295,21 +306,21 @@ try:
|
||||||
while 1:
|
while 1:
|
||||||
#{
|
#{
|
||||||
rx = ser.readline()
|
rx = ser.readline()
|
||||||
if (len(rx) > 0): print rx.strip()
|
if (len(rx) > 0): LOGln(rx.strip())
|
||||||
#}
|
#}
|
||||||
|
|
||||||
elif (handshakeResponse == HANDSHAKE_FAIL_TIMEOUT):
|
elif (handshakeResponse == HANDSHAKE_FAIL_TIMEOUT):
|
||||||
print "FAIL: No response from Moteino programmer, is it connected to " + port
|
LOGln("FAIL: No response from Moteino programmer, is it connected to " + port)
|
||||||
exit(1)
|
exit(1)
|
||||||
elif (handshakeResponse == HANDSHAKE_FAIL_TIMEOUT):
|
elif (handshakeResponse == HANDSHAKE_FAIL_TIMEOUT):
|
||||||
print "FAIL: No response from Moteino programmer, is it connected to " + port
|
LOGln("FAIL: No response from Moteino programmer, is it connected to " + port)
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
print "FAIL: No response from Moteino Target, is Target listening on same Freq/NetworkID & OTA enabled?"
|
LOGln("FAIL: No response from Moteino Target, is Target listening on same Freq/NetworkID & OTA enabled?")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
except IOError:
|
except IOError:
|
||||||
print "File [", HEX, "] not found, exiting..."
|
LOGln("File [", HEX, "] not found, exiting...")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
Loading…
Reference in New Issue