-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
136 additions
and
12 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pygsmmodule.uart_support.base_uart import BaseUart | ||
|
||
|
||
class AtProtocolSupport(BaseUart): | ||
def __init__(self, serial): | ||
super().__init__(serial) | ||
|
||
def initialize_port(self): | ||
commands_to_execute = [ | ||
"ATE0" | ||
] | ||
for command in commands_to_execute: | ||
res = self.send_simple_request(command, remove_result=False) | ||
|
||
res = res.split("\n") | ||
if "OK" not in res: | ||
return False | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
from pygsmmodule.uart_support.base_uart import BaseUart | ||
|
||
|
||
class GetImei(object): | ||
def __init__(self): | ||
pass | ||
|
||
@staticmethod | ||
def get_imei(serial, timeout=1000): | ||
communicator = BaseUart(serial) | ||
|
||
res = communicator.send_simple_request("AT+GSN", timeout) | ||
def exec_command(at_executor, timeout=1000): | ||
res = at_executor.send_simple_request("AT+GSN", timeout) | ||
return str(res).strip() if res else res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class UssdExecutor(object): | ||
def __init__(self): | ||
pass | ||
|
||
@staticmethod | ||
def exec_command(at_executor, command, timeout=1000, read_timeout=20000): | ||
cmd = "AT+CUSD=1,\"{0}\",15".format(command) | ||
|
||
res = at_executor.send_simple_request(cmd, timeout, remove_result=False) | ||
if not res: | ||
return None | ||
|
||
res = str(res).strip() | ||
|
||
if res != "OK": | ||
return None | ||
|
||
ntr = at_executor.read_pattern_terminated_string(read_timeout) | ||
|
||
ntr = str(ntr).strip() | ||
|
||
ntr = UssdExecutor._remove_prefix(ntr, "+CUSD:") | ||
|
||
return UssdExecutor._remove_quotes(ntr) | ||
|
||
@staticmethod | ||
def _remove_prefix(value, prefix): | ||
if not str(value).startswith(prefix): | ||
return value | ||
|
||
return value[len(prefix):] | ||
|
||
@staticmethod | ||
def _remove_quotes(value): | ||
lindex = str(value).index("\"") | ||
rindex = str(value).rindex("\"") | ||
|
||
if (lindex == rindex) or (-1 in [lindex, rindex]): | ||
return value | ||
|
||
return value[lindex + 1: rindex] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from pygsmmodule.at_protocol_support.at_protocol_support import AtProtocolSupport | ||
from pygsmmodule.supplementary.ussd_executor import UssdExecutor | ||
|
||
from .shared import init_serial, load_dev_config | ||
|
||
|
||
def main(**kwargs): | ||
settings = load_dev_config() | ||
serial = init_serial(settings.uart.name, settings.uart.speed) | ||
at_executor = AtProtocolSupport(serial) | ||
|
||
print("initializing port...") | ||
ok = at_executor.initialize_port() | ||
|
||
if ok: | ||
print("initialization [ OK ]") | ||
else: | ||
print("initialization [FAILED]") | ||
return 1 | ||
|
||
ussd_command = "*111#" | ||
result = UssdExecutor.exec_command(at_executor, ussd_command) | ||
|
||
result = str(result).strip() | ||
print("executing USSD command '{}' result:\n---\n{}\n---".format(ussd_command, result)) | ||
|
||
serial.close() | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
res = main() | ||
exit(res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters