Skip to content

Commit c95a2da

Browse files
authored
Merge pull request #2 from caternuson/basic_uart
Add basic UART xfer
2 parents 95f3171 + 4575a14 commit c95a2da

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

adafruit_rockblock.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,35 @@
4242
4343
"""
4444

45-
# imports
46-
4745
__version__ = "0.0.0-auto.0"
4846
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RockBlock.git"
47+
48+
49+
class RockBlock:
50+
"""Driver for RockBLOCK Iridium satellite modem."""
51+
52+
def __init__(self, uart, baudrate=19200):
53+
self._uart = uart
54+
self._uart.baudrate = baudrate
55+
56+
def _uart_xfer(self, cmd):
57+
"""Send AT command and return response."""
58+
# response = ATCMD\r\nRESP\r\n\r\nOK\r\n
59+
# or = ATCMD\r\nERROR\r\n
60+
61+
cmd = str.encode("AT" + cmd)
62+
63+
self._uart.reset_input_buffer()
64+
self._uart.write(cmd + "\r")
65+
66+
resp = None
67+
if self._uart.readline().strip() == cmd:
68+
resp = self._uart.readline().strip().decode()
69+
70+
self._uart.reset_input_buffer()
71+
return resp
72+
73+
@property
74+
def model(self):
75+
"""Return phone model."""
76+
return self._uart_xfer("+GMM")

0 commit comments

Comments
 (0)