get-diagnostics (1071B)
1 #!/usr/bin/python3 2 3 import sys 4 import dbus 5 6 # Map dict keys to units. Units can be a function/lambda which should return the 7 # entire value with units as a string. 8 unit_map = { 9 "ConnectedBss" : None, 10 "RSSI" : "dBm", 11 "RxMode" : None, 12 "RxBitrate" : lambda k : str(100 * int(k)) + ' Kbps', 13 "RxMCS" : lambda i : str(int(i)), 14 "TxMode" : None, 15 "TxBitrate" : lambda k : str(100 * int(k)) + ' Kbps', 16 "TxMCS" : lambda i : str(int(i)), 17 "ExpectedThroughput" : "Kbps" 18 } 19 20 if (len(sys.argv) != 2): 21 print("Usage: %s <device>" % (sys.argv[0])) 22 sys.exit(1) 23 24 bus = dbus.SystemBus() 25 device = dbus.Interface(bus.get_object("net.connman.iwd", sys.argv[1]), 26 "net.connman.iwd.StationDiagnostic") 27 diagnostics = device.GetDiagnostics() 28 29 for key, value in diagnostics.items(): 30 if key in unit_map: 31 units = unit_map[key] 32 if units is None: 33 units = '' 34 elif callable(units): 35 value = units(value) 36 units = '' 37 38 print('%s : %s %s' % (key, value, units))