modem-config-dump: Create a nice human readable config file
Full config file under /run/modem/modem-at.config New easily readable file under /run/modem/modem.config BugzID: 56305
This commit is contained in:
		
							parent
							
								
									c3a7e34286
								
							
						
					
					
						commit
						23c770a9a3
					
				|  | @ -3,6 +3,8 @@ | |||
| import serial | ||||
| import os | ||||
| import time | ||||
| import re | ||||
| 
 | ||||
| 
 | ||||
| CONF_PATH = '/run/modem' | ||||
| ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0.5) | ||||
|  | @ -15,9 +17,33 @@ while True: | |||
| 
 | ||||
| 
 | ||||
| os.makedirs(CONF_PATH, exist_ok=True) | ||||
| config_file = open(CONF_PATH + '/modem-at.config', 'w') | ||||
| config_full_file = open(CONF_PATH + '/modem-at.config', 'w') | ||||
| config_file = open(CONF_PATH + '/modem.config', 'w') | ||||
| 
 | ||||
| def read_config(cmd, label=''): | ||||
| 
 | ||||
| def usb_profile_parser(output): | ||||
|     x = re.search('UUSBCONF:\s\d,"(.*)",', output) | ||||
|     return x.group(1) | ||||
| 
 | ||||
| def mode_parser(output): | ||||
|     x = re.search('UBMCONF:\s(\d)', output) | ||||
|     mode = int(x.group(1)) | ||||
|     if mode == 1: | ||||
|         return "Router" | ||||
|     elif mode == 2: | ||||
|         return "Bridge" | ||||
|     else: | ||||
|         return "unsupported" | ||||
| 
 | ||||
| def apn_parser(output): | ||||
|     x = re.search('","(.*)",', output) | ||||
|     return x.group(1) | ||||
| 
 | ||||
| def default_parser(output): | ||||
|     x = re.search('(.*)\n.*\nOK',output) | ||||
|     return x.group(1) | ||||
| 
 | ||||
| def read_config(cmd, label='', parser=default_parser): | ||||
|     while True: | ||||
|         try: | ||||
|             ser.flushInput() | ||||
|  | @ -32,20 +58,19 @@ def read_config(cmd, label=''): | |||
|             time.sleep(1) | ||||
|             continue | ||||
|          | ||||
|     config_file.write(label + '\n') | ||||
|     config_file.write(s.decode('utf-8').strip("OK")) | ||||
|     config_full_file.write(label + '\n') | ||||
|     config_full_file.write(s.decode('utf-8').strip("OK")) | ||||
| 
 | ||||
|     config_file.write((label + ':').ljust(20)) | ||||
|     config_file.write(parser(s.decode('utf-8')) + '\n') | ||||
| 
 | ||||
| read_config(b'AT+CGMI', 'Manufacturer identification'); | ||||
| read_config(b'AT+GMI', 'Manufacturer identification'); | ||||
| read_config(b'AT+CGMM', 'Model identification'); | ||||
| read_config(b'AT+GMM', 'Model identification'); | ||||
| read_config(b'AT+CGMR', 'Firmware version identification'); | ||||
| read_config(b'AT+GMR', 'Firmware version identification'); | ||||
| read_config(b'AT+CGMI', 'VendorID') | ||||
| read_config(b'AT+CGMM', 'ModelID') | ||||
| read_config(b'AT+CGMR', 'Firmware') | ||||
| 
 | ||||
| config_file.write('-' * 80 + '\n' * 2) | ||||
| config_full_file.write('-' * 80 + '\n' * 2) | ||||
| 
 | ||||
| read_config(b'AT+UCGDFLT?', 'Initial EPS bearer / PDP context'); | ||||
| read_config(b'AT+UBMCONF?', 'Boot mode configuration, 1 = router, 2 = bridge') | ||||
| read_config(b'AT+UUSBCONF?', 'USB profiles configuration') | ||||
| read_config(b'AT+UCGDFLT?', 'Default APN', apn_parser) | ||||
| read_config(b'AT+UBMCONF?', 'Mode', mode_parser) | ||||
| read_config(b'AT+UUSBCONF?', 'USBprofile', usb_profile_parser) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue