def mycli(ctx, verbose, config_file): if ctx.obj is None: ctx.obj = {} ctx.obj['verbose'] = verbose loggerutils.set_level(verbose) # print('context:\n' + str(ctx.invoked_subcommand)) doing_config = ctx.invoked_subcommand in ['config'] doing_pi = ctx.invoked_subcommand in ['pi'] if doing_pi: # Get out of here if doing a pi gpio command return config_loaded = load_config(ctx, config_file) # Load config if there is one if doing_config: # Get out of ere if doing a config command return if config_loaded: # In all other cases, we need a valid config global my_module my_module = module_factory().get(Manufacturer[ctx.obj['modemMfg']], ctx.obj['comPort'], ctx.obj['apn'], verbose=ctx.obj['verbose']) aerisutils.vprint(verbose, 'Valid configuration loaded.') if my_module.get_serial() is None: print('Could not open serial port') exit() else: # Not ok print('Valid configuration not found') print('Try running config command') exit()
def test_parse_single_urc(self): expected_payloads = [b'Hello, world!'] urcs = b'' for p in expected_payloads: urcs += self.create_urc(p) my_module = module_factory().get(Manufacturer.quectel, '1', 'anyapn', verbose=True) payloads = my_module.udp_urcs_to_payloads(urcs, verbose=True) self.assertEqual(expected_payloads, payloads)
def test_parse_multiple_urcs(self): expected_payloads = [ b'payload 1', b'second payload', b'this is the third payload' ] urcs = b'' for p in expected_payloads: urcs += self.create_urc(p) my_module = module_factory().get(Manufacturer.quectel, '1', 'anyapn', verbose=True) payloads = my_module.udp_urcs_to_payloads(urcs, verbose=True) self.assertEqual(expected_payloads, payloads)
def test_parse_interrupted_packet(self): """If the URC buffer ends with a cut-off UDP packet, that packet should be ignored.""" sent_payloads = [b'0123456789'] expected_payloads = [] urcs = b'' for p in sent_payloads: urcs += self.create_urc(p) # the URC line should claim that the UDP packet is 10 bytes long # cut it off after 5 bytes lf_index = urcs.find(b'\x0A') urcs = urcs[:lf_index + 1 + 5] my_module = module_factory().get(Manufacturer.quectel, '1', 'anyapn', verbose=True) payloads = my_module.udp_urcs_to_payloads(urcs, verbose=True) self.assertEqual(expected_payloads, payloads)
def test_parse_urcs_with_unexpected_urcs(self): '''Run this with pytest's '-s' flag to observe the printed unexpected URCs: poetry run pytest -s''' expected_payloads = [ b'payload\x0A1', b'second pay\x0Aload', b'this is the third payload' ] urcs = b'' for p in expected_payloads: urcs += self.create_urc(p) # pretend that the modem got an unsolicited result code for a time zone report urcs += b'+CTZV: 1' + b'\x0D\x0A' my_module = module_factory().get(Manufacturer.quectel, '1', 'anyapn', verbose=True) payloads = my_module.udp_urcs_to_payloads(urcs, verbose=True) self.assertEqual(expected_payloads, payloads)
from aerismodsdk import __version__ from aerismodsdk.manufacturer import Manufacturer from aerismodsdk.modulefactory import module_factory telit = module_factory().get(Manufacturer.telit, 'USB2', 'lpiot.aer.net') quectel = module_factory().get(Manufacturer.quectel, 'USB0', 'lpiot.aer.net') ublox = module_factory().get(Manufacturer.ublox, 'USB1', 'lpiot.aer.net') verbose = True def test_version(): assert __version__ == '0.1.0' def test_modem_basic_functions(): print('Testing Basic Functions ****** START') telit.check_modem() print('Testing Basic Functions ****** END') def test_network_functions(): # Call Network APIs print('Testing Network Functions ****** START') telit.get_network_info(verbose) telit.turn_off_network(verbose) telit.set_network('auto', 0) print('Testing Network Functions ****** END') def test_psm_functions():