1616
1717import meshtastic .test
1818import meshtastic .util
19- from meshtastic import globals
19+ from meshtastic import mt_config
2020from meshtastic import channel_pb2 , config_pb2 , portnums_pb2 , remote_hardware , BROADCAST_ADDR
2121from meshtastic .version import get_active_version
2222from meshtastic .ble_interface import BLEInterface
2323
2424def onReceive (packet , interface ):
2525 """Callback invoked when a packet arrives"""
26- args = globals .args
26+ args = mt_config .args
2727 try :
2828 d = packet .get ("decoded" )
2929 logging .debug (f"in onReceive() d:{ d } " )
@@ -67,7 +67,7 @@ def getPref(node, comp_name):
6767 # Note: protobufs has the keys in snake_case, so snake internally
6868 snake_name = meshtastic .util .camel_to_snake (name [1 ])
6969 logging .debug (f"snake_name:{ snake_name } camel_name:{ camel_name } " )
70- logging .debug (f"use camel:{ globals .camel_case } " )
70+ logging .debug (f"use camel:{ mt_config .camel_case } " )
7171
7272 # First validate the input
7373 localConfig = node .localConfig
@@ -84,7 +84,7 @@ def getPref(node, comp_name):
8484 break
8585
8686 if not found :
87- if globals .camel_case :
87+ if mt_config .camel_case :
8888 print (
8989 f"{ localConfig .__class__ .__name__ } and { moduleConfig .__class__ .__name__ } do not have an attribute { snake_name } ."
9090 )
@@ -103,7 +103,7 @@ def getPref(node, comp_name):
103103 config_values = getattr (config , config_type .name )
104104 if not wholeField :
105105 pref_value = getattr (config_values , pref .name )
106- if globals .camel_case :
106+ if mt_config .camel_case :
107107 print (f"{ str (config_type .name )} .{ camel_name } : { str (pref_value )} " )
108108 logging .debug (
109109 f"{ str (config_type .name )} .{ camel_name } : { str (pref_value )} "
@@ -169,7 +169,7 @@ def setPref(config, comp_name, valStr) -> bool:
169169 if e :
170170 val = e .number
171171 else :
172- if globals .camel_case :
172+ if mt_config .camel_case :
173173 print (
174174 f"{ name [0 ]} .{ camel_name } does not have an enum called { val } , so you can not set it."
175175 )
@@ -208,7 +208,7 @@ def setPref(config, comp_name, valStr) -> bool:
208208 config_type .message_type .ignore_incoming .extend ([val ])
209209
210210 prefix = f"{ name [0 ]} ." if config_type .message_type is not None else ""
211- if globals .camel_case :
211+ if mt_config .camel_case :
212212 print (f"Set { prefix } { camel_name } to { valStr } " )
213213 else :
214214 print (f"Set { prefix } { snake_name } to { valStr } " )
@@ -223,7 +223,7 @@ def onConnected(interface):
223223 False # Should we wait for an acknowledgment if we send to a remote node?
224224 )
225225 try :
226- args = globals .args
226+ args = mt_config .args
227227
228228 # do not print this line if we are exporting the config
229229 if not args .export_config :
@@ -474,7 +474,7 @@ def onConnected(interface):
474474 print ("Writing modified preferences to device" )
475475 node .writeConfig (field )
476476 else :
477- if globals .camel_case :
477+ if mt_config .camel_case :
478478 print (
479479 f"{ node .localConfig .__class__ .__name__ } and { node .moduleConfig .__class__ .__name__ } do not have an attribute { pref [0 ]} ."
480480 )
@@ -587,7 +587,7 @@ def onConnected(interface):
587587 # handle changing channels
588588
589589 if args .ch_add :
590- channelIndex = globals .channel_index
590+ channelIndex = mt_config .channel_index
591591 if channelIndex is not None :
592592 # Since we set the channel index after adding a channel, don't allow --ch-index
593593 meshtastic .util .our_exit (
@@ -618,12 +618,12 @@ def onConnected(interface):
618618 n .writeChannel (ch .index )
619619 if channelIndex is None :
620620 print (f"Setting newly-added channel's { ch .index } as '--ch-index' for further modifications" )
621- globals .channel_index = ch .index
621+ mt_config .channel_index = ch .index
622622
623623 if args .ch_del :
624624 closeNow = True
625625
626- channelIndex = globals .channel_index
626+ channelIndex = mt_config .channel_index
627627 if channelIndex is None :
628628 meshtastic .util .our_exit (
629629 "Warning: Need to specify '--ch-index' for '--ch-del'." , 1
@@ -639,7 +639,7 @@ def onConnected(interface):
639639
640640 def setSimpleConfig (modem_preset ):
641641 """Set one of the simple modem_config"""
642- channelIndex = globals .channel_index
642+ channelIndex = mt_config .channel_index
643643 if channelIndex is not None and channelIndex > 0 :
644644 meshtastic .util .our_exit (
645645 "Warning: Cannot set modem preset for non-primary channel" , 1
@@ -674,7 +674,7 @@ def setSimpleConfig(modem_preset):
674674 if args .ch_set or args .ch_enable or args .ch_disable :
675675 closeNow = True
676676
677- channelIndex = globals .channel_index
677+ channelIndex = mt_config .channel_index
678678 if channelIndex is None :
679679 meshtastic .util .our_exit ("Warning: Need to specify '--ch-index'." , 1 )
680680 ch = interface .getNode (args .dest ).channels [channelIndex ]
@@ -829,7 +829,7 @@ def printConfig(config):
829829 names = []
830830 for field in config .message_type .fields :
831831 tmp_name = f"{ config_section .name } .{ field .name } "
832- if globals .camel_case :
832+ if mt_config .camel_case :
833833 tmp_name = meshtastic .util .snake_to_camel (tmp_name )
834834 names .append (tmp_name )
835835 for temp_name in sorted (names ):
@@ -874,7 +874,7 @@ def export_config(interface):
874874 if owner_short :
875875 configObj ["owner_short" ] = owner_short
876876 if channel_url :
877- if globals .camel_case :
877+ if mt_config .camel_case :
878878 configObj ["channelUrl" ] = channel_url
879879 else :
880880 configObj ["channel_url" ] = channel_url
@@ -886,11 +886,11 @@ def export_config(interface):
886886 # Convert inner keys to correct snake/camelCase
887887 prefs = {}
888888 for pref in config :
889- if globals .camel_case :
889+ if mt_config .camel_case :
890890 prefs [meshtastic .util .snake_to_camel (pref )] = config [pref ]
891891 else :
892892 prefs [pref ] = config [pref ]
893- if globals .camel_case :
893+ if mt_config .camel_case :
894894 configObj ["config" ] = config
895895 else :
896896 configObj ["config" ] = config
@@ -902,7 +902,7 @@ def export_config(interface):
902902 for pref in module_config :
903903 if len (module_config [pref ]) > 0 :
904904 prefs [pref ] = module_config [pref ]
905- if globals .camel_case :
905+ if mt_config .camel_case :
906906 configObj ["module_config" ] = prefs
907907 else :
908908 configObj ["module_config" ] = prefs
@@ -916,8 +916,8 @@ def export_config(interface):
916916def common ():
917917 """Shared code for all of our command line wrappers"""
918918 logfile = None
919- args = globals .args
920- parser = globals .parser
919+ args = mt_config .args
920+ parser = mt_config .parser
921921 logging .basicConfig (
922922 level = logging .DEBUG if (args .debug or args .listen ) else logging .INFO ,
923923 format = "%(levelname)s file:%(filename)s %(funcName)s line:%(lineno)s %(message)s" ,
@@ -933,7 +933,7 @@ def common():
933933
934934 if args .ch_index is not None :
935935 channelIndex = int (args .ch_index )
936- globals .channel_index = channelIndex
936+ mt_config .channel_index = channelIndex
937937
938938 if not args .dest :
939939 args .dest = BROADCAST_ADDR
@@ -968,7 +968,7 @@ def common():
968968 # Note: using "line buffering"
969969 # pylint: disable=R1732
970970 logfile = open (args .seriallog , "w+" , buffering = 1 , encoding = "utf8" )
971- globals .logfile = logfile
971+ mt_config .logfile = logfile
972972
973973 subscribe ()
974974 if args .ble_scan :
@@ -1059,8 +1059,8 @@ def addConnectionArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentParse
10591059
10601060def initParser ():
10611061 """Initialize the command line argument parsing."""
1062- parser = globals .parser
1063- args = globals .args
1062+ parser = mt_config .parser
1063+ args = mt_config .args
10641064
10651065 # The "Help" group includes the help option and other informational stuff about the CLI itself
10661066 outerHelpGroup = parser .add_argument_group ('Help' )
@@ -1426,8 +1426,8 @@ def initParser():
14261426
14271427
14281428 args = parser .parse_args ()
1429- globals .args = args
1430- globals .parser = parser
1429+ mt_config .args = args
1430+ mt_config .parser = parser
14311431
14321432
14331433def main ():
@@ -1436,22 +1436,22 @@ def main():
14361436 add_help = False ,
14371437 epilog = "If no connection arguments are specified, we search for a compatible serial device, "
14381438 "and if none is found, then attempt a TCP connection to localhost." )
1439- globals .parser = parser
1439+ mt_config .parser = parser
14401440 initParser ()
14411441 common ()
1442- logfile = globals .logfile
1442+ logfile = mt_config .logfile
14431443 if logfile :
14441444 logfile .close ()
14451445
14461446
14471447def tunnelMain ():
14481448 """Run a meshtastic IP tunnel"""
14491449 parser = argparse .ArgumentParser (add_help = False )
1450- globals .parser = parser
1450+ mt_config .parser = parser
14511451 initParser ()
1452- args = globals .args
1452+ args = mt_config .args
14531453 args .tunnel = True
1454- globals .args = args
1454+ mt_config .args = args
14551455 common ()
14561456
14571457
0 commit comments