From d015da3ca1bb02955274fa9cb703a0f9e7aa4cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 18 Jun 2022 14:53:04 +0200 Subject: [PATCH 1/5] Get and Set general attributes almost working. --- meshtastic/__main__.py | 70 ++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 49e5777..8bdea0b 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -52,18 +52,27 @@ def onConnection(interface, topic=pub.AUTO_TOPIC): # pylint: disable=W0613 print(f"Connection changed: {topic.getName()}") -def getPref(attributes, name): +def getPref(attributes, comp_name): """Get a channel or preferences value""" - camel_name = meshtastic.util.snake_to_camel(name) + name=comp_name.split(".",1) + if len(name) != 2: + name[0]=comp_name + name.append(comp_name) + + camel_name = meshtastic.util.snake_to_camel(name[1]) # Note: protobufs has the keys in snake_case, so snake internally - snake_name = meshtastic.util.camel_to_snake(name) + snake_name = meshtastic.util.camel_to_snake(name[1]) logging.debug(f'snake_name:{snake_name} camel_name:{camel_name}') logging.debug(f'use camel:{Globals.getInstance().get_camel_case()}') objDesc = attributes.DESCRIPTOR - field = objDesc.fields_by_name.get(snake_name) - if not field: + section = objDesc.fields_by_name.get(name[0]) + field = False + if section: + field = section.message_type.fields_by_name.get(snake_name) + + if (not field) or (not section): if Globals.getInstance().get_camel_case(): print(f"{attributes.__class__.__name__} does not have an attribute called {camel_name}, so you can not get it.") else: @@ -71,16 +80,19 @@ def getPref(attributes, name): print(f"Choices in sorted order are:") names = [] for f in objDesc.fields: - tmp_name = f'{f.name}' - if Globals.getInstance().get_camel_case(): - tmp_name = meshtastic.util.snake_to_camel(tmp_name) - names.append(tmp_name) + tmp_path = f'{f.name}' + if(f.message_type): + for ff in f.message_type.fields: + tmp_name = f'{ff.name}' + if Globals.getInstance().get_camel_case(): + tmp_name = meshtastic.util.snake_to_camel(tmp_name) + names.append(tmp_path + "." +tmp_name) for temp_name in sorted(names): print(f" {temp_name}") return # read the value - val = getattr(attributes, snake_name) + val = getattr(section.message_type, snake_name) if Globals.getInstance().get_camel_case(): print(f"{camel_name}: {str(val)}") @@ -90,17 +102,26 @@ def getPref(attributes, name): logging.debug(f"{snake_name}: {str(val)}") -def setPref(attributes, name, valStr): +def setPref(attributes, comp_name, valStr): """Set a channel or preferences value""" - snake_name = meshtastic.util.camel_to_snake(name) - camel_name = meshtastic.util.snake_to_camel(name) + name=comp_name.split(".",1) + if len(name) != 2: + name[0]=comp_name + name.append(comp_name) + + snake_name = meshtastic.util.camel_to_snake(name[1]) + camel_name = meshtastic.util.snake_to_camel(name[1]) logging.debug(f'snake_name:{snake_name}') logging.debug(f'camel_name:{camel_name}') objDesc = attributes.DESCRIPTOR - field = objDesc.fields_by_name.get(snake_name) - if not field: + section = objDesc.fields_by_name.get(name[0]) + field = False + if section: + field = section.message_type.fields_by_name.get(snake_name) + + if (not field) or (not section): if Globals.getInstance().get_camel_case(): print(f"{attributes.__class__.__name__} does not have an attribute called {camel_name}, so you can not set it.") else: @@ -108,10 +129,13 @@ def setPref(attributes, name, valStr): print(f"Choices in sorted order are:") names = [] for f in objDesc.fields: - tmp_name = f'{f.name}' - if Globals.getInstance().get_camel_case(): - tmp_name = meshtastic.util.snake_to_camel(tmp_name) - names.append(tmp_name) + tmp_path = f'{f.name}' + if(f.message_type): + for ff in f.message_type.fields: + tmp_name = f'{ff.name}' + if Globals.getInstance().get_camel_case(): + tmp_name = meshtastic.util.snake_to_camel(tmp_name) + names.append(tmp_path + "." + tmp_name) for temp_name in sorted(names): print(f" {temp_name}") return @@ -147,18 +171,18 @@ def setPref(attributes, name, valStr): # note: 'ignore_incoming' is a repeating field if snake_name != 'ignore_incoming': try: - setattr(attributes, snake_name, val) + setattr(section.message_type, snake_name, val) except TypeError: # The setter didn't like our arg type guess try again as a string - setattr(attributes, snake_name, valStr) + setattr(section.message_type, snake_name, valStr) else: if val == 0: # clear values print("Clearing ignore_incoming list") - del attributes.ignore_incoming[:] + del section.message_type.ignore_incoming[:] else: print(f"Adding '{val}' to the ignore_incoming list") - attributes.ignore_incoming.extend([val]) + section.message_type.ignore_incoming.extend([val]) if Globals.getInstance().get_camel_case(): print(f"Set {camel_name} to {valStr}") From ce7b1d9916f2089d69d247098eafb0f47245d2aa Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 19 Jun 2022 08:17:28 -0500 Subject: [PATCH 2/5] Get preferences now working --- .vscode/launch.json | 12 ++++++++++-- meshtastic/__main__.py | 25 +++++++++++++------------ meshtastic/config_pb2.py | 34 +++++++++++++++++----------------- proto | 2 +- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 16a9ded..4623000 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -42,7 +42,15 @@ "request": "launch", "module": "meshtastic", "justMyCode": true, - "args": ["--debug" ] + "args": ["--debug"] + }, + { + "name": "meshtastic debug getPref", + "type": "python", + "request": "launch", + "module": "meshtastic", + "justMyCode": true, + "args": ["--debug", "--get", "power.is_power_saving"] }, { "name": "meshtastic setpref", @@ -92,7 +100,7 @@ "module": "meshtastic", "justMyCode": true, "args": ["--debug", "--sendtext", "pytest"] - } + }, { "name": "meshtastic showNodes", "type": "python", diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 8bdea0b..50febb9 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -55,7 +55,7 @@ def onConnection(interface, topic=pub.AUTO_TOPIC): # pylint: disable=W0613 def getPref(attributes, comp_name): """Get a channel or preferences value""" - name=comp_name.split(".",1) + name = comp_name.split(".",1) if len(name) != 2: name[0]=comp_name name.append(comp_name) @@ -67,12 +67,12 @@ def getPref(attributes, comp_name): logging.debug(f'use camel:{Globals.getInstance().get_camel_case()}') objDesc = attributes.DESCRIPTOR - section = objDesc.fields_by_name.get(name[0]) - field = False - if section: - field = section.message_type.fields_by_name.get(snake_name) - - if (not field) or (not section): + config_type = objDesc.fields_by_name.get(name[0]) + pref = False + if config_type: + pref = config_type.message_type.fields_by_name.get(snake_name) + + if (not pref) or (not config_type): if Globals.getInstance().get_camel_case(): print(f"{attributes.__class__.__name__} does not have an attribute called {camel_name}, so you can not get it.") else: @@ -92,14 +92,15 @@ def getPref(attributes, comp_name): return # read the value - val = getattr(section.message_type, snake_name) + config_values = getattr(attributes, config_type.name) + pref_value = getattr(config_values, pref.name) if Globals.getInstance().get_camel_case(): - print(f"{camel_name}: {str(val)}") - logging.debug(f"{camel_name}: {str(val)}") + print(f"{camel_name}: {str(pref_value)}") + logging.debug(f"{camel_name}: {str(pref_value)}") else: - print(f"{snake_name}: {str(val)}") - logging.debug(f"{snake_name}: {str(val)}") + print(f"{snake_name}: {str(pref_value)}") + logging.debug(f"{snake_name}: {str(pref_value)}") def setPref(attributes, comp_name, valStr): diff --git a/meshtastic/config_pb2.py b/meshtastic/config_pb2.py index cb7983e..7562de5 100644 --- a/meshtastic/config_pb2.py +++ b/meshtastic/config_pb2.py @@ -14,7 +14,7 @@ _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0c\x63onfig.proto\"\xf1\x11\n\x06\x43onfig\x12&\n\x06\x64\x65vice\x18\x01 \x01(\x0b\x32\x14.Config.DeviceConfigH\x00\x12*\n\x08position\x18\x02 \x01(\x0b\x32\x16.Config.PositionConfigH\x00\x12$\n\x05power\x18\x03 \x01(\x0b\x32\x13.Config.PowerConfigH\x00\x12\"\n\x04wifi\x18\x04 \x01(\x0b\x32\x12.Config.WiFiConfigH\x00\x12(\n\x07\x64isplay\x18\x05 \x01(\x0b\x32\x15.Config.DisplayConfigH\x00\x12\"\n\x04lora\x18\x06 \x01(\x0b\x32\x12.Config.LoRaConfigH\x00\x1a\xd8\x01\n\x0c\x44\x65viceConfig\x12\'\n\x04role\x18\x01 \x01(\x0e\x32\x19.Config.DeviceConfig.Role\x12\x17\n\x0fserial_disabled\x18\x02 \x01(\x08\x12\x15\n\rfactory_reset\x18\x03 \x01(\x08\x12\x19\n\x11\x64\x65\x62ug_log_enabled\x18\x04 \x01(\x08\x12\x12\n\nntp_server\x18\x05 \x01(\t\"@\n\x04Role\x12\n\n\x06\x43lient\x10\x00\x12\x0e\n\nClientMute\x10\x01\x12\n\n\x06Router\x10\x02\x12\x10\n\x0cRouterClient\x10\x03\x1a\x86\x03\n\x0ePositionConfig\x12\x1f\n\x17position_broadcast_secs\x18\x01 \x01(\r\x12)\n!position_broadcast_smart_disabled\x18\x02 \x01(\x08\x12\x16\n\x0e\x66ixed_position\x18\x03 \x01(\x08\x12\x14\n\x0cgps_disabled\x18\x05 \x01(\x08\x12\x1b\n\x13gps_update_interval\x18\x06 \x01(\r\x12\x18\n\x10gps_attempt_time\x18\x07 \x01(\r\x12\x16\n\x0eposition_flags\x18\n \x01(\r\"\xaa\x01\n\rPositionFlags\x12\x11\n\rPOS_UNDEFINED\x10\x00\x12\x10\n\x0cPOS_ALTITUDE\x10\x01\x12\x0f\n\x0bPOS_ALT_MSL\x10\x02\x12\x0f\n\x0bPOS_GEO_SEP\x10\x04\x12\x0b\n\x07POS_DOP\x10\x08\x12\r\n\tPOS_HVDOP\x10\x10\x12\x11\n\rPOS_SATINVIEW\x10 \x12\x0f\n\x0bPOS_SEQ_NOS\x10@\x12\x12\n\rPOS_TIMESTAMP\x10\x80\x01\x1a\x8f\x04\n\x0bPowerConfig\x12\x39\n\x0e\x63harge_current\x18\x01 \x01(\x0e\x32!.Config.PowerConfig.ChargeCurrent\x12\x17\n\x0fis_power_saving\x18\x02 \x01(\x08\x12\x19\n\x11is_always_powered\x18\x03 \x01(\x08\x12&\n\x1eon_battery_shutdown_after_secs\x18\x04 \x01(\r\x12\x1f\n\x17\x61\x64\x63_multiplier_override\x18\x06 \x01(\x02\x12\x1b\n\x13wait_bluetooth_secs\x18\x07 \x01(\r\x12\x1d\n\x15mesh_sds_timeout_secs\x18\t \x01(\r\x12\x10\n\x08sds_secs\x18\n \x01(\r\x12\x0f\n\x07ls_secs\x18\x0b \x01(\r\x12\x15\n\rmin_wake_secs\x18\x0c \x01(\r\"\xd1\x01\n\rChargeCurrent\x12\x0b\n\x07MAUnset\x10\x00\x12\t\n\x05MA100\x10\x01\x12\t\n\x05MA190\x10\x02\x12\t\n\x05MA280\x10\x03\x12\t\n\x05MA360\x10\x04\x12\t\n\x05MA450\x10\x05\x12\t\n\x05MA550\x10\x06\x12\t\n\x05MA630\x10\x07\x12\t\n\x05MA700\x10\x08\x12\t\n\x05MA780\x10\t\x12\t\n\x05MA880\x10\n\x12\t\n\x05MA960\x10\x0b\x12\n\n\x06MA1000\x10\x0c\x12\n\n\x06MA1080\x10\r\x12\n\n\x06MA1160\x10\x0e\x12\n\n\x06MA1240\x10\x0f\x12\n\n\x06MA1320\x10\x10\x1aK\n\nWiFiConfig\x12\x0c\n\x04ssid\x18\x01 \x01(\t\x12\x0b\n\x03psk\x18\x02 \x01(\t\x12\x0f\n\x07\x61p_mode\x18\x03 \x01(\x08\x12\x11\n\tap_hidden\x18\x04 \x01(\x08\x1a\x8f\x02\n\rDisplayConfig\x12\x16\n\x0escreen_on_secs\x18\x01 \x01(\r\x12=\n\ngps_format\x18\x02 \x01(\x0e\x32).Config.DisplayConfig.GpsCoordinateFormat\x12!\n\x19\x61uto_screen_carousel_secs\x18\x03 \x01(\r\"\x83\x01\n\x13GpsCoordinateFormat\x12\x10\n\x0cGpsFormatDec\x10\x00\x12\x10\n\x0cGpsFormatDMS\x10\x01\x12\x10\n\x0cGpsFormatUTM\x10\x02\x12\x11\n\rGpsFormatMGRS\x10\x03\x12\x10\n\x0cGpsFormatOLC\x10\x04\x12\x11\n\rGpsFormatOSGR\x10\x05\x1a\x93\x04\n\nLoRaConfig\x12\x10\n\x08tx_power\x18\x01 \x01(\x05\x12\x34\n\x0cmodem_preset\x18\x02 \x01(\x0e\x32\x1e.Config.LoRaConfig.ModemPreset\x12\x11\n\tbandwidth\x18\x03 \x01(\r\x12\x15\n\rspread_factor\x18\x04 \x01(\r\x12\x13\n\x0b\x63oding_rate\x18\x05 \x01(\r\x12\x18\n\x10\x66requency_offset\x18\x06 \x01(\x02\x12-\n\x06region\x18\x07 \x01(\x0e\x32\x1d.Config.LoRaConfig.RegionCode\x12\x11\n\thop_limit\x18\x08 \x01(\r\x12\x13\n\x0btx_disabled\x18\t \x01(\x08\x12\x17\n\x0fignore_incoming\x18g \x03(\r\"\x81\x01\n\nRegionCode\x12\t\n\x05Unset\x10\x00\x12\x06\n\x02US\x10\x01\x12\t\n\x05\x45U433\x10\x02\x12\t\n\x05\x45U868\x10\x03\x12\x06\n\x02\x43N\x10\x04\x12\x06\n\x02JP\x10\x05\x12\x07\n\x03\x41NZ\x10\x06\x12\x06\n\x02KR\x10\x07\x12\x06\n\x02TW\x10\x08\x12\x06\n\x02RU\x10\t\x12\x06\n\x02IN\x10\n\x12\t\n\x05NZ865\x10\x0b\x12\x06\n\x02TH\x10\x0c\"p\n\x0bModemPreset\x12\x0c\n\x08LongFast\x10\x00\x12\x0c\n\x08LongSlow\x10\x01\x12\r\n\tVLongSlow\x10\x02\x12\x0b\n\x07MidSlow\x10\x03\x12\x0b\n\x07MidFast\x10\x04\x12\r\n\tShortSlow\x10\x05\x12\r\n\tShortFast\x10\x06\x42\x10\n\x0epayloadVariantBH\n\x13\x63om.geeksville.meshB\x0c\x43onfigProtosH\x03Z!github.com/meshtastic/gomeshprotob\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0c\x63onfig.proto\"\xd6\x11\n\x06\x43onfig\x12&\n\x06\x64\x65vice\x18\x01 \x01(\x0b\x32\x14.Config.DeviceConfigH\x00\x12*\n\x08position\x18\x02 \x01(\x0b\x32\x16.Config.PositionConfigH\x00\x12$\n\x05power\x18\x03 \x01(\x0b\x32\x13.Config.PowerConfigH\x00\x12\"\n\x04wifi\x18\x04 \x01(\x0b\x32\x12.Config.WiFiConfigH\x00\x12(\n\x07\x64isplay\x18\x05 \x01(\x0b\x32\x15.Config.DisplayConfigH\x00\x12\"\n\x04lora\x18\x06 \x01(\x0b\x32\x12.Config.LoRaConfigH\x00\x1a\xd8\x01\n\x0c\x44\x65viceConfig\x12\'\n\x04role\x18\x01 \x01(\x0e\x32\x19.Config.DeviceConfig.Role\x12\x17\n\x0fserial_disabled\x18\x02 \x01(\x08\x12\x15\n\rfactory_reset\x18\x03 \x01(\x08\x12\x19\n\x11\x64\x65\x62ug_log_enabled\x18\x04 \x01(\x08\x12\x12\n\nntp_server\x18\x05 \x01(\t\"@\n\x04Role\x12\n\n\x06\x43lient\x10\x00\x12\x0e\n\nClientMute\x10\x01\x12\n\n\x06Router\x10\x02\x12\x10\n\x0cRouterClient\x10\x03\x1a\x86\x03\n\x0ePositionConfig\x12\x1f\n\x17position_broadcast_secs\x18\x01 \x01(\r\x12)\n!position_broadcast_smart_disabled\x18\x02 \x01(\x08\x12\x16\n\x0e\x66ixed_position\x18\x03 \x01(\x08\x12\x14\n\x0cgps_disabled\x18\x05 \x01(\x08\x12\x1b\n\x13gps_update_interval\x18\x06 \x01(\r\x12\x18\n\x10gps_attempt_time\x18\x07 \x01(\r\x12\x16\n\x0eposition_flags\x18\n \x01(\r\"\xaa\x01\n\rPositionFlags\x12\x11\n\rPOS_UNDEFINED\x10\x00\x12\x10\n\x0cPOS_ALTITUDE\x10\x01\x12\x0f\n\x0bPOS_ALT_MSL\x10\x02\x12\x0f\n\x0bPOS_GEO_SEP\x10\x04\x12\x0b\n\x07POS_DOP\x10\x08\x12\r\n\tPOS_HVDOP\x10\x10\x12\x11\n\rPOS_SATINVIEW\x10 \x12\x0f\n\x0bPOS_SEQ_NOS\x10@\x12\x12\n\rPOS_TIMESTAMP\x10\x80\x01\x1a\xf4\x03\n\x0bPowerConfig\x12\x39\n\x0e\x63harge_current\x18\x01 \x01(\x0e\x32!.Config.PowerConfig.ChargeCurrent\x12\x17\n\x0fis_power_saving\x18\x02 \x01(\x08\x12&\n\x1eon_battery_shutdown_after_secs\x18\x04 \x01(\r\x12\x1f\n\x17\x61\x64\x63_multiplier_override\x18\x06 \x01(\x02\x12\x1b\n\x13wait_bluetooth_secs\x18\x07 \x01(\r\x12\x1d\n\x15mesh_sds_timeout_secs\x18\t \x01(\r\x12\x10\n\x08sds_secs\x18\n \x01(\r\x12\x0f\n\x07ls_secs\x18\x0b \x01(\r\x12\x15\n\rmin_wake_secs\x18\x0c \x01(\r\"\xd1\x01\n\rChargeCurrent\x12\x0b\n\x07MAUnset\x10\x00\x12\t\n\x05MA100\x10\x01\x12\t\n\x05MA190\x10\x02\x12\t\n\x05MA280\x10\x03\x12\t\n\x05MA360\x10\x04\x12\t\n\x05MA450\x10\x05\x12\t\n\x05MA550\x10\x06\x12\t\n\x05MA630\x10\x07\x12\t\n\x05MA700\x10\x08\x12\t\n\x05MA780\x10\t\x12\t\n\x05MA880\x10\n\x12\t\n\x05MA960\x10\x0b\x12\n\n\x06MA1000\x10\x0c\x12\n\n\x06MA1080\x10\r\x12\n\n\x06MA1160\x10\x0e\x12\n\n\x06MA1240\x10\x0f\x12\n\n\x06MA1320\x10\x10\x1aK\n\nWiFiConfig\x12\x0c\n\x04ssid\x18\x01 \x01(\t\x12\x0b\n\x03psk\x18\x02 \x01(\t\x12\x0f\n\x07\x61p_mode\x18\x03 \x01(\x08\x12\x11\n\tap_hidden\x18\x04 \x01(\x08\x1a\x8f\x02\n\rDisplayConfig\x12\x16\n\x0escreen_on_secs\x18\x01 \x01(\r\x12=\n\ngps_format\x18\x02 \x01(\x0e\x32).Config.DisplayConfig.GpsCoordinateFormat\x12!\n\x19\x61uto_screen_carousel_secs\x18\x03 \x01(\r\"\x83\x01\n\x13GpsCoordinateFormat\x12\x10\n\x0cGpsFormatDec\x10\x00\x12\x10\n\x0cGpsFormatDMS\x10\x01\x12\x10\n\x0cGpsFormatUTM\x10\x02\x12\x11\n\rGpsFormatMGRS\x10\x03\x12\x10\n\x0cGpsFormatOLC\x10\x04\x12\x11\n\rGpsFormatOSGR\x10\x05\x1a\x93\x04\n\nLoRaConfig\x12\x10\n\x08tx_power\x18\x01 \x01(\x05\x12\x34\n\x0cmodem_preset\x18\x02 \x01(\x0e\x32\x1e.Config.LoRaConfig.ModemPreset\x12\x11\n\tbandwidth\x18\x03 \x01(\r\x12\x15\n\rspread_factor\x18\x04 \x01(\r\x12\x13\n\x0b\x63oding_rate\x18\x05 \x01(\r\x12\x18\n\x10\x66requency_offset\x18\x06 \x01(\x02\x12-\n\x06region\x18\x07 \x01(\x0e\x32\x1d.Config.LoRaConfig.RegionCode\x12\x11\n\thop_limit\x18\x08 \x01(\r\x12\x13\n\x0btx_disabled\x18\t \x01(\x08\x12\x17\n\x0fignore_incoming\x18g \x03(\r\"\x81\x01\n\nRegionCode\x12\t\n\x05Unset\x10\x00\x12\x06\n\x02US\x10\x01\x12\t\n\x05\x45U433\x10\x02\x12\t\n\x05\x45U868\x10\x03\x12\x06\n\x02\x43N\x10\x04\x12\x06\n\x02JP\x10\x05\x12\x07\n\x03\x41NZ\x10\x06\x12\x06\n\x02KR\x10\x07\x12\x06\n\x02TW\x10\x08\x12\x06\n\x02RU\x10\t\x12\x06\n\x02IN\x10\n\x12\t\n\x05NZ865\x10\x0b\x12\x06\n\x02TH\x10\x0c\"p\n\x0bModemPreset\x12\x0c\n\x08LongFast\x10\x00\x12\x0c\n\x08LongSlow\x10\x01\x12\r\n\tVLongSlow\x10\x02\x12\x0b\n\x07MidSlow\x10\x03\x12\x0b\n\x07MidFast\x10\x04\x12\r\n\tShortSlow\x10\x05\x12\r\n\tShortFast\x10\x06\x42\x10\n\x0epayloadVariantBH\n\x13\x63om.geeksville.meshB\x0c\x43onfigProtosH\x03Z!github.com/meshtastic/gomeshprotob\x06proto3') @@ -91,7 +91,7 @@ if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\014ConfigProtosH\003Z!github.com/meshtastic/gomeshproto' _CONFIG._serialized_start=17 - _CONFIG._serialized_end=2306 + _CONFIG._serialized_end=2279 _CONFIG_DEVICECONFIG._serialized_start=264 _CONFIG_DEVICECONFIG._serialized_end=480 _CONFIG_DEVICECONFIG_ROLE._serialized_start=416 @@ -101,19 +101,19 @@ if _descriptor._USE_C_DESCRIPTORS == False: _CONFIG_POSITIONCONFIG_POSITIONFLAGS._serialized_start=703 _CONFIG_POSITIONCONFIG_POSITIONFLAGS._serialized_end=873 _CONFIG_POWERCONFIG._serialized_start=876 - _CONFIG_POWERCONFIG._serialized_end=1403 - _CONFIG_POWERCONFIG_CHARGECURRENT._serialized_start=1194 - _CONFIG_POWERCONFIG_CHARGECURRENT._serialized_end=1403 - _CONFIG_WIFICONFIG._serialized_start=1405 - _CONFIG_WIFICONFIG._serialized_end=1480 - _CONFIG_DISPLAYCONFIG._serialized_start=1483 - _CONFIG_DISPLAYCONFIG._serialized_end=1754 - _CONFIG_DISPLAYCONFIG_GPSCOORDINATEFORMAT._serialized_start=1623 - _CONFIG_DISPLAYCONFIG_GPSCOORDINATEFORMAT._serialized_end=1754 - _CONFIG_LORACONFIG._serialized_start=1757 - _CONFIG_LORACONFIG._serialized_end=2288 - _CONFIG_LORACONFIG_REGIONCODE._serialized_start=2045 - _CONFIG_LORACONFIG_REGIONCODE._serialized_end=2174 - _CONFIG_LORACONFIG_MODEMPRESET._serialized_start=2176 - _CONFIG_LORACONFIG_MODEMPRESET._serialized_end=2288 + _CONFIG_POWERCONFIG._serialized_end=1376 + _CONFIG_POWERCONFIG_CHARGECURRENT._serialized_start=1167 + _CONFIG_POWERCONFIG_CHARGECURRENT._serialized_end=1376 + _CONFIG_WIFICONFIG._serialized_start=1378 + _CONFIG_WIFICONFIG._serialized_end=1453 + _CONFIG_DISPLAYCONFIG._serialized_start=1456 + _CONFIG_DISPLAYCONFIG._serialized_end=1727 + _CONFIG_DISPLAYCONFIG_GPSCOORDINATEFORMAT._serialized_start=1596 + _CONFIG_DISPLAYCONFIG_GPSCOORDINATEFORMAT._serialized_end=1727 + _CONFIG_LORACONFIG._serialized_start=1730 + _CONFIG_LORACONFIG._serialized_end=2261 + _CONFIG_LORACONFIG_REGIONCODE._serialized_start=2018 + _CONFIG_LORACONFIG_REGIONCODE._serialized_end=2147 + _CONFIG_LORACONFIG_MODEMPRESET._serialized_start=2149 + _CONFIG_LORACONFIG_MODEMPRESET._serialized_end=2261 # @@protoc_insertion_point(module_scope) diff --git a/proto b/proto index 94a4dbb..274aa01 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 94a4dbb842961e75f89de13dc6d0437a256098aa +Subproject commit 274aa01a3862ee83b1ae791c36205e661c4af7ca From 032072d2f3434caef8f11d253999371bb1ff2278 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 19 Jun 2022 09:55:09 -0500 Subject: [PATCH 3/5] Started on set --- .vscode/launch.json | 8 ++++++++ meshtastic/__main__.py | 34 ++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4623000..59d47d9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -52,6 +52,14 @@ "justMyCode": true, "args": ["--debug", "--get", "power.is_power_saving"] }, + { + "name": "meshtastic debug setPref", + "type": "python", + "request": "launch", + "module": "meshtastic", + "justMyCode": true, + "args": ["--debug", "--set", "power.is_power_saving", "1"] + }, { "name": "meshtastic setpref", "type": "python", diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 50febb9..b801301 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -103,10 +103,10 @@ def getPref(attributes, comp_name): logging.debug(f"{snake_name}: {str(pref_value)}") -def setPref(attributes, comp_name, valStr): +def setPref(attributes, comp_name, valStr, nodeInterface): """Set a channel or preferences value""" - name=comp_name.split(".",1) + name = comp_name.split(".",1) if len(name) != 2: name[0]=comp_name name.append(comp_name) @@ -117,12 +117,12 @@ def setPref(attributes, comp_name, valStr): logging.debug(f'camel_name:{camel_name}') objDesc = attributes.DESCRIPTOR - section = objDesc.fields_by_name.get(name[0]) - field = False - if section: - field = section.message_type.fields_by_name.get(snake_name) + config_type = objDesc.fields_by_name.get(name[0]) + pref = False + if config_type: + pref = config_type.message_type.fields_by_name.get(snake_name) - if (not field) or (not section): + if (not pref) or (not config_type): if Globals.getInstance().get_camel_case(): print(f"{attributes.__class__.__name__} does not have an attribute called {camel_name}, so you can not set it.") else: @@ -148,7 +148,7 @@ def setPref(attributes, comp_name, valStr): print(f"Warning: wifi_password must be 8 or more characters.") return - enumType = field.enum_type + enumType = pref.enum_type # pylint: disable=C0123 if enumType and type(val) == str: # We've failed so far to convert this string into an enum, try to find it by reflection @@ -171,19 +171,24 @@ def setPref(attributes, comp_name, valStr): # note: 'ignore_incoming' is a repeating field if snake_name != 'ignore_incoming': + print("Writing modified preference to device") try: - setattr(section.message_type, snake_name, val) + config_values = getattr(attributes, config_type.name) + setattr(config_values, pref.name, val) + nodeInterface.writeConfig() except TypeError: # The setter didn't like our arg type guess try again as a string - setattr(section.message_type, snake_name, valStr) + config_values = getattr(attributes, config_type.name) + setattr(config_values, pref.name, valStr) + nodeInterface.writeConfig(config_values) else: if val == 0: # clear values print("Clearing ignore_incoming list") - del section.message_type.ignore_incoming[:] + del config_type.message_type.ignore_incoming[:] else: print(f"Adding '{val}' to the ignore_incoming list") - section.message_type.ignore_incoming.extend([val]) + config_type.message_type.ignore_incoming.extend([val]) if Globals.getInstance().get_camel_case(): print(f"Set {camel_name} to {valStr}") @@ -355,10 +360,7 @@ def onConnected(interface): # Handle the int/float/bool arguments for pref in args.set: - setPref(prefs, pref[0], pref[1]) - - print("Writing modified preferences to device") - interface.getNode(args.dest).writeConfig() + setPref(prefs, pref[0], pref[1], interface.getNode(args.dest)) if args.configure: with open(args.configure[0], encoding='utf8') as file: From 4fa93989fa35e3e780ed3d64bd234098479ffc47 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 19 Jun 2022 15:41:21 -0500 Subject: [PATCH 4/5] Don't need to pass interface down --- meshtastic/__main__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index b801301..a6eaab5 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -103,7 +103,7 @@ def getPref(attributes, comp_name): logging.debug(f"{snake_name}: {str(pref_value)}") -def setPref(attributes, comp_name, valStr, nodeInterface): +def setPref(attributes, comp_name, valStr): """Set a channel or preferences value""" name = comp_name.split(".",1) @@ -171,16 +171,13 @@ def setPref(attributes, comp_name, valStr, nodeInterface): # note: 'ignore_incoming' is a repeating field if snake_name != 'ignore_incoming': - print("Writing modified preference to device") try: config_values = getattr(attributes, config_type.name) setattr(config_values, pref.name, val) - nodeInterface.writeConfig() except TypeError: # The setter didn't like our arg type guess try again as a string config_values = getattr(attributes, config_type.name) setattr(config_values, pref.name, valStr) - nodeInterface.writeConfig(config_values) else: if val == 0: # clear values @@ -360,7 +357,10 @@ def onConnected(interface): # Handle the int/float/bool arguments for pref in args.set: - setPref(prefs, pref[0], pref[1], interface.getNode(args.dest)) + setPref(prefs, pref[0], pref[1]) + + print("Writing modified preferences to device") + interface.getNode(args.dest).writeConfig() if args.configure: with open(args.configure[0], encoding='utf8') as file: From 8a5fd164691da1a722118fc26a17be3bf201a626 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 21 Jun 2022 08:05:15 -0500 Subject: [PATCH 5/5] Don't blow away config please --- meshtastic/node.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/meshtastic/node.py b/meshtastic/node.py index ee4b11c..387b3d0 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -62,18 +62,9 @@ class Node: def requestConfig(self): """Send regular MeshPackets to ask for settings and channels.""" logging.debug(f"requestConfig for nodeNum:{self.nodeNum}") - self.localConfig = localonly_pb2.LocalConfig() self.channels = None self.partialChannels = [] # We keep our channels in a temp array until finished - # Note: We do not get the canned plugin message, unless get_canned_message() is called - self.cannedPluginMessage = None - - self.cannedPluginMessagePart1 = None - self.cannedPluginMessagePart2 = None - self.cannedPluginMessagePart3 = None - self.cannedPluginMessagePart4 = None - self._requestChannel(0) def turnOffEncryptionOnPrimaryChannel(self):