ublox-config: Improve python script performances and reliability
This commit is contained in:
parent
b8e6585022
commit
0bc18d93c6
|
|
@ -6,26 +6,32 @@ import time
|
||||||
|
|
||||||
MAX_TRY = 5
|
MAX_TRY = 5
|
||||||
tries = 0
|
tries = 0
|
||||||
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=2)
|
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0.5)
|
||||||
|
|
||||||
def execute_and_check(cmd):
|
def execute_and_check(cmd):
|
||||||
|
global tries
|
||||||
|
ser.flushInput()
|
||||||
ser.write(cmd)
|
ser.write(cmd)
|
||||||
s = ser.read(200)
|
ser.write(b'\r')
|
||||||
if b"OK" not in s:
|
s = ser.read_until(b'OK')
|
||||||
|
if b'OK' not in s:
|
||||||
print("Failed cmd : " + str(cmd))
|
print("Failed cmd : " + str(cmd))
|
||||||
print(s)
|
print("Output: " + str(s))
|
||||||
if ++tries < MAX_TRY:
|
tries += 1
|
||||||
|
if tries < MAX_TRY:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
execute_and_check(cmd)
|
execute_and_check(cmd)
|
||||||
else:
|
else:
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
tries = 0
|
||||||
|
|
||||||
|
|
||||||
print("Setting up bridge mode")
|
print("Setting up bridge mode")
|
||||||
execute_and_check(b'AT+UBMCONF=2\r')
|
execute_and_check(b'AT+UBMCONF=2')
|
||||||
|
|
||||||
|
|
||||||
print("Setting up USB mode to ECM")
|
print("Setting up USB mode to ECM")
|
||||||
execute_and_check(b'AT+UUSBCONF=2,"ECM",0\r')
|
execute_and_check(b'AT+UUSBCONF=2,"ECM",0')
|
||||||
|
|
||||||
|
|
||||||
print("Resetting modem")
|
print("Resetting modem")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue