From 331ff2291b95f5681d388e2acb284f6c54143c7c Mon Sep 17 00:00:00 2001 From: Alexandre Bard Date: Thu, 13 Jun 2019 15:39:46 +0200 Subject: [PATCH] ublox-gsm-config: Improve check of bridge and ecm modes BugzID: 57325 --- .../files/modem-config-dump.py | 27 ++++++++++++++++--- .../files/ublox-gsm-config.py | 7 ++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/recipes-connectivity/ublox-gsm-config/files/modem-config-dump.py b/recipes-connectivity/ublox-gsm-config/files/modem-config-dump.py index ff4dec2..8d2492f 100755 --- a/recipes-connectivity/ublox-gsm-config/files/modem-config-dump.py +++ b/recipes-connectivity/ublox-gsm-config/files/modem-config-dump.py @@ -30,8 +30,7 @@ def default_parser(output): x = re.search('(.*)\n.*\nOK',output) return x.group(1) -def read_config(ser, config_file, full_config_file, cmd, label='', parser=default_parser): - +def execute_command(ser, cmd): while True: try: ser.flushInput() @@ -45,6 +44,13 @@ def read_config(ser, config_file, full_config_file, cmd, label='', parser=defaul print("Exception : " + str(e)) time.sleep(1) continue + return s + +def read_config(ser, config_file, full_config_file, cmd, label='', parser=default_parser): + s = execute_command(ser, cmd) + if s is None: + print('Failed to execute command : ' + str(cmd)) + return full_conf = label + '\n' + s.decode('utf-8').strip("OK") conf = (label + ':').ljust(20) + parser(s.decode('utf-8')) + '\n' @@ -65,4 +71,19 @@ def dump_modem_config(ser): read_config(ser, config_file, full_config_file, b'AT+UCGDFLT?', 'Default APN', apn_parser) read_config(ser, config_file, full_config_file, b'AT+UBMCONF?', 'Mode', mode_parser) - read_config(ser, config_file, full_config_file, b'AT+UUSBCONF?', 'USBprofile', usb_profile_parser) \ No newline at end of file + read_config(ser, config_file, full_config_file, b'AT+UUSBCONF?', 'USBprofile', usb_profile_parser) + +def get_usb_profile(ser): + s = execute_command(ser, b'AT+UUSBCONF?') + if s is None: + print('Failed to get UUSBCONF') + return None + + return usb_profile_parser(s.decode('utf-8')) + +def get_mode(ser): + s = execute_command(ser, b'AT+UBMCONF?') + if s is None: + print('Failed to get UBMCONF') + return None + return mode_parser(s.decode('utf-8')) diff --git a/recipes-connectivity/ublox-gsm-config/files/ublox-gsm-config.py b/recipes-connectivity/ublox-gsm-config/files/ublox-gsm-config.py index 8cb1c5d..956d41e 100755 --- a/recipes-connectivity/ublox-gsm-config/files/ublox-gsm-config.py +++ b/recipes-connectivity/ublox-gsm-config/files/ublox-gsm-config.py @@ -144,14 +144,19 @@ def main(): ser = serial.Serial(SERIAL_DEV, 115200, timeout=0.5) rst = False - if not os.path.exists(WWAN_DEV): + + if 'Bridge' != config_dump.get_mode(ser): print("Setting up bridge mode") execute_and_check(ser, b'AT+UBMCONF=2') + rst = True + if 'ECM' != config_dump.get_usb_profile(ser): print("Setting up USB mode to ECM") execute_and_check(ser, b'AT+UUSBCONF=2,"ECM",0') rst = True + rst = sim_config(ser) or rst + if rst: print("Resetting modem") ser.write(b'AT+CFUN=16\r')