Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix supportedCommands property for Teleofis modems #62

Merged
merged 2 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gsmmodem/modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .serial_comms import SerialComms
from .exceptions import CommandError, InvalidStateException, CmeError, CmsError, InterruptedException, TimeoutException, PinRequiredError, IncorrectPinError, SmscNumberUnknownError
from .pdu import encodeSmsSubmitPdu, decodeSmsPdu, encodeGsm7, encodeTextMode
from .util import SimpleOffsetTzInfo, lineStartingWith, allLinesMatchingPattern, parseTextModeTimeStr
from .util import SimpleOffsetTzInfo, lineStartingWith, allLinesMatchingPattern, parseTextModeTimeStr, removeAtPrefix

#from . import compat # For Python 2.6 compatibility
from gsmmodem.util import lineMatching
Expand Down Expand Up @@ -554,7 +554,7 @@ def supportedCommands(self):
commands = commands[6:] # remove the +CLAC: prefix before splitting
return commands.split(',')
elif len(response) > 2: # Multi-line response
return [cmd.strip() for cmd in response[:-1]]
return [removeAtPrefix(cmd.strip()) for cmd in response[:-1]]
else:
self.log.debug('Unhandled +CLAC response: {0}'.format(response))
return None
Expand Down
14 changes: 14 additions & 0 deletions gsmmodem/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,17 @@ def allLinesMatchingPattern(pattern, lines):
if m:
result.append(m)
return result


def removeAtPrefix(string):
""" Remove AT prefix from a specified string.

:param string: An original string
:type string: str

:return: A string with AT prefix removed
:rtype: str
"""
if string.startswith('AT'):
return string[2:]
return string
2 changes: 2 additions & 0 deletions test/test_modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def writeCallbackFunc(data):
(['FGH,RTY,UIO\r\n', 'OK\r\n'], ['FGH', 'RTY', 'UIO']), # nasty, but possible
# ZTE-like response: do not start with +CLAC, and use multiple lines
(['A\r\n', 'BCD\r\n', 'EFGH\r\n', 'OK\r\n'], ['A', 'BCD', 'EFGH']),
# Teleofis response: like ZTE but each command has AT prefix
(['AT&F\r\n', 'AT&V\r\n', 'AT&W\r\n', 'AT+CACM\r\n', 'OK\r\n'], ['&F', '&V', '&W', '+CACM']),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Siemens modem actually send & characters?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AT& commands exist.

AT&F = restore factory defaults.

all & commands here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you probably meant '&F', '&V', '&W' part. Let's wait for @ffix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for a reminder! I just got suspicious, because @ffix have not mentioned those commands inside PR description. Sorry for the confusion.

Copy link
Author

@ffix ffix Nov 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Siemens modem actually send & characters?

It's my mistake. It is actually Teleofis modem, not Siemens.
I've updated description.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for a reminder! I just got suspicious, because @ffix have not mentioned those commands inside PR description. Sorry for the confusion.

You're right. I copied these commands from modem response directly.

# Some Huawei modems have a ZTE-like response, but add an addition \r character at the end of each listed command
(['Q\r\r\n', 'QWERTY\r\r\n', '^DTMF\r\r\n', 'OK\r\n'], ['Q', 'QWERTY', '^DTMF']))
for responseSequence, expected in tests:
Expand Down
9 changes: 8 additions & 1 deletion test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from . import compat # For Python 2.6 compatibility

from gsmmodem.util import allLinesMatchingPattern, lineMatching, lineStartingWith, lineMatchingPattern, SimpleOffsetTzInfo
from gsmmodem.util import allLinesMatchingPattern, lineMatching, lineStartingWith, lineMatchingPattern, SimpleOffsetTzInfo, removeAtPrefix

class TestUtil(unittest.TestCase):
""" Tests misc utilities from gsmmodem.util """
Expand Down Expand Up @@ -74,6 +74,13 @@ def test_SimpleOffsetTzInfo(self):
self.assertEqual(tz.dst(None), timedelta(0))
self.assertIsInstance(tz.__repr__(), str)

def test_removeAtPrefix(self):
""" Tests function: removeAtPrefix"""
tests = (('AT+CLAC', '+CLAC'), ('ATZ', 'Z'), ('+CLAC', '+CLAC'), ('Z', 'Z'))
for src, dst in tests:
res = removeAtPrefix(src)
self.assertEqual(res, dst)


if __name__ == "__main__":
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
Expand Down