meta-netmodule-bsp/recipes-connectivity/ublox-configuration/files/ublox-config.py

51 lines
977 B
Python
Executable File

#!/usr/bin/env python3
import serial
import sys
import time
import os
MAX_TRY = 5
tries = 0
SERIAL_DEV = '/dev/ttyACM0'
while not os.path.exists(SERIAL_DEV):
time.sleep(1)
ser = serial.Serial(SERIAL_DEV, 115200, timeout=0.5)
def execute_and_check(cmd):
global tries
ser.flushInput()
ser.write(cmd)
ser.write(b'\r')
s = ser.read_until(b'OK')
if b'OK' not in s:
print("Failed cmd : " + str(cmd))
print("Output: " + str(s))
tries += 1
if tries < MAX_TRY:
time.sleep(1)
execute_and_check(cmd)
else:
sys.exit(-1)
tries = 0
print("Setting up bridge mode")
execute_and_check(b'AT+UBMCONF=2')
print("Setting up USB mode to ECM")
execute_and_check(b'AT+UUSBCONF=2,"ECM",0')
print("Resetting modem")
# Let the reset be done by sim-config to avoid 2 resets
# ser.write(b'AT+CFUN=16\r')
f = open('/tmp/modem-reset-required', 'w')
f.write('1')
f.close()
ser.close()