11#!/usr/bin/env python2
22
3- # Copyright (c) 2016-2020 , Pycom Limited.
3+ # Copyright (c) 2016-2019 , Pycom Limited.
44#
55# This software is licensed under the GNU GPL version 3 or any
66# later version, with permitted additional terms. For more information
4343FAST_BAUD_RATE = 921600
4444MAXPICREAD_BAUD_RATE = 230400
4545
46- LORA_REGIONS = ["EU868" , "US915" , "AS923" , "AU915" ]
46+ LORA_REGIONS = ["EU868" , "US915" , "AS923" , "AU915" , "IN865" ]
4747
4848PIC_BOARDS = ["04D8:F013" , "04D8:F012" , "04D8:EF98" , "04D8:EF38" ]
4949
@@ -678,6 +678,55 @@ def set_wifi_config(self, config_block, wifi_ssid=None, wifi_pwd=None, wifi_on_b
678678 + config_block [152 :]
679679 return self .set_pybytes_config (new_config_block , force_update = True )
680680
681+ def set_lte_config (self , config_block , carrier = None , apn = None , lte_type = None , cid = None , band = None , reset = None ):
682+ config_block = config_block .ljust (int (PARTITIONS .get ('config' )[1 ], 16 ), b'\x00 ' )
683+
684+ if carrier is not None :
685+ cb_carrier = str (carrier [0 :128 ]).ljust (129 , b'\x00 ' )
686+ print (cb_carrier )
687+ else :
688+ cb_carrier = config_block [634 :763 ]
689+
690+ if apn is not None :
691+ cb_apn = str (apn [0 :128 ]).ljust (129 , b'\x00 ' )
692+ else :
693+ cb_apn = config_block [763 :892 ]
694+
695+ if lte_type is not None :
696+ cb_lte_type = str (lte_type [0 :16 ]).ljust (17 , b'\x00 ' )
697+ else :
698+ cb_lte_type = config_block [892 :909 ]
699+
700+ if cid is not None :
701+ cb_cid = struct .pack ('>B' , int (cid ))
702+ else :
703+ cb_cid = config_block [909 ]
704+
705+ if band is not None :
706+ cb_band = struct .pack ('>B' , int (band ))
707+ else :
708+ cb_band = config_block [910 ]
709+
710+ if reset is not None :
711+ cb_reset = struct .pack ('>B' , int (reset == 'True' ))
712+ else :
713+ cb_reset = config_block [911 ]
714+ print (cb_reset )
715+
716+ new_config_block = config_block [0 :634 ] \
717+ + cb_carrier \
718+ + cb_apn \
719+ + cb_lte_type \
720+ + cb_cid \
721+ + cb_band \
722+ + cb_reset \
723+ + config_block [912 :]
724+ return self .set_pybytes_config (new_config_block , force_update = True )
725+
726+
727+
728+
729+
681730 def set_pycom_config (self , config_block , boot_fs_type = None ):
682731 print_debug ('This is set_pycom_config with boot_fs_type={} [{}]' .format (boot_fs_type , type (boot_fs_type )))
683732 config_block = config_block .ljust (int (PARTITIONS .get ('config' )[1 ], 16 ), b'\x00 ' )
@@ -702,7 +751,7 @@ def set_pycom_config(self, config_block, boot_fs_type=None):
702751 return self .set_pybytes_config (new_config_block , force_update = True )
703752
704753 def print_cb (self , config_block ):
705- for x in range (0 , 20 ):
754+ for x in range (0 , 30 ):
706755 print (binascii .hexlify (config_block [x * 32 :x * 32 + 32 ]))
707756
708757 def set_pybytes_config (self , config_block , userid = None , device_token = None , mqttServiceAddress = None , network_preferences = None , extra_preferences = None , force_update = None ):
@@ -918,6 +967,12 @@ def process_arguments():
918967 cmd_parser_pybytes .add_argument ('--uid' , default = None , help = 'Set userId' )
919968 cmd_parser_pybytes .add_argument ('--nwprefs' , default = None , help = 'Set network preferences' )
920969 cmd_parser_pybytes .add_argument ('--extraprefs' , default = None , help = 'Set extra preferences' )
970+ cmd_parser_pybytes .add_argument ('--carrier' , default = None , help = 'Set LTE carrier' )
971+ cmd_parser_pybytes .add_argument ('--apn' , default = None , help = 'Set LTE apn' )
972+ cmd_parser_pybytes .add_argument ('--type' , default = None , help = 'Set LTE type' )
973+ cmd_parser_pybytes .add_argument ('--cid' , default = None , help = 'Set LTE cid' )
974+ cmd_parser_pybytes .add_argument ('--band' , default = None , help = 'Set LTE band' )
975+ cmd_parser_pybytes .add_argument ('--reset' , default = None , help = 'Set LTE reset' )
921976
922977 cmd_parser_cb = subparsers .add_parser ('cb' , help = 'Read/Write config block' )
923978 cmd_parser_cb .add_argument ('-f' , '--file' , default = None , help = 'name of the backup file (default: <wmac>.cb)' )
@@ -1389,8 +1444,16 @@ def progress_fs(msg):
13891444 or (hasattr (args , "mqtt" ) and args .mqtt is not None ) \
13901445 or (hasattr (args , "uid" ) and args .uid is not None ) \
13911446 or (hasattr (args , "nwprefs" ) and args .nwprefs is not None ) \
1447+ or (hasattr (args , "carrier" ) and args .carrier is not None ) \
1448+ or (hasattr (args , "apn" ) and args .apn is not None ) \
1449+ or (hasattr (args , "type" ) and args .type is not None ) \
1450+ or (hasattr (args , "cid" ) and args .cid is not None ) \
1451+ or (hasattr (args , "band" ) and args .band is not None ) \
1452+ or (hasattr (args , "reset" ) and args .reset is not None ) \
13921453 or (hasattr (args , "extraprefs" ) and args .extraprefs is not None ):
13931454 new_config_block = nPy .set_pybytes_config (config_block , args .uid , args .token , args .mqtt , args .nwprefs , args .extraprefs , True )
1455+ new_config_block = nPy .set_lte_config (new_config_block , args .carrier , args .apn , args .type , args .cid , args .band , args .reset )
1456+ print (nPy .print_cb (new_config_block ))
13941457 nPy .write (int (PARTITIONS .get ('config' )[0 ], 16 ), new_config_block )
13951458 sys .stdout = old_stdout
13961459 else :
0 commit comments