|
17 | 17 | import subprocess
|
18 | 18 | import time
|
19 | 19 |
|
| 20 | +DEFAULT_TIMEOUT = 5 |
| 21 | + |
20 | 22 | help_connect = '''This subcommand establishes a cellular connection.\n
|
21 | 23 | '''
|
22 | 24 |
|
|
40 | 42 | help_location = '''Print the location of the modem based on cell towers if supported\n
|
41 | 43 | '''
|
42 | 44 |
|
| 45 | +help_at_command = '''Send an AT command to the modem and print the result''' |
| 46 | + |
43 | 47 | help_reset = '''Restart the modem\n'''
|
44 | 48 |
|
45 | 49 | help_radio_off = '''Turn off the cellular radio on the modem\n'''
|
@@ -87,6 +91,17 @@ def run_modem_signal(args):
|
87 | 91 | else:
|
88 | 92 | print('Signal strength: ' + str(cloud.network.signal_strength))
|
89 | 93 |
|
| 94 | +def run_at_command(args): |
| 95 | + cloud = CustomCloud(None, network='cellular') |
| 96 | + cmd = '' |
| 97 | + if args['command'] is not None: |
| 98 | + cmd = args['command'].lstrip("AT") |
| 99 | + val = None |
| 100 | + if not cmd.endswith('?') and '=' in cmd: |
| 101 | + cmd, val = cmd.split('=') |
| 102 | + result, response = cloud.network.modem.command(cmd, val, timeout=args['timeout']) |
| 103 | + print('Response: ' + ''.join(map(str, response)) + f'\n{result}') |
| 104 | + |
90 | 105 | def run_modem_version(args):
|
91 | 106 | cloud = CustomCloud(None, network='cellular')
|
92 | 107 | version = cloud.network.modem.version
|
@@ -142,6 +157,7 @@ def run_modem_location(args):
|
142 | 157 | _run_handlers = {
|
143 | 158 | 'modem_connect': run_modem_connect,
|
144 | 159 | 'modem_disconnect': run_modem_disconnect,
|
| 160 | + 'modem_command': run_at_command, |
145 | 161 | 'modem_sim': run_modem_sim,
|
146 | 162 | 'modem_operator': run_modem_operator,
|
147 | 163 | 'modem_signal': run_modem_signal,
|
@@ -212,6 +228,14 @@ def parse_hologram_modem_args(parser):
|
212 | 228 | parser_radio_off.set_defaults(command_selected='modem_radio_off')
|
213 | 229 | parser_radio_off.add_argument('-v', nargs='?', action=VAction, dest='verbose', required=False)
|
214 | 230 |
|
| 231 | + # at-command |
| 232 | + parser_command = subparsers.add_parser('command', help=help_at_command) |
| 233 | + parser_command.set_defaults(command_selected='modem_command') |
| 234 | + parser_command.add_argument('command', nargs='?', help='AT command to send to the modem') |
| 235 | + parser_command.add_argument('-t', '--timeout', type=int, default=DEFAULT_TIMEOUT, nargs='?', |
| 236 | + help='The period in seconds before the command exits if it doesn\'t receive a response') |
| 237 | + parser_command.add_argument('-v', nargs='?', action=VAction, dest='verbose', required=False) |
| 238 | + |
215 | 239 | # version
|
216 | 240 | parser_version = subparsers.add_parser('version', help=help_version)
|
217 | 241 | parser_version.set_defaults(command_selected='modem_version')
|
|
0 commit comments