Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, code):
"""Just assign return codes."""
try:
self.errno = int(code)
except ValueError:
self.errno = code
if self.errno in ERROR_MESSAGE:
self.strerror = ERROR_MESSAGE[self.errno]
else:
self.strerror = ERROR_MESSAGE[ErrorCode.UNKNOWN_ERR]
super().__init__(('[Errno {}] {}').format(self.errno, self.strerror))
class Rak811EventError(Rak811Error):
"""Exception raised by module events.
Attributes:
errno -- as returned by the module
strerror -- textual representation
"""
def __init__(self, status):
"""Just assign return status."""
try:
self.errno = int(status)
except ValueError:
self.errno = status
if self.errno in EVENT_MESSAGE:
class Reset(IntEnum):
"""Module reset type."""
Module = 0
LoRa = 1
class RecvEx(IntEnum):
"""Receive RSSI/SNR data with downlink packets."""
Enabled = 0
Disabled = 1
class Rak811ResponseError(Rak811Error):
"""Exception raised by response from the module.
Attributes:
errno -- as returned by the module
strerror -- textual representation
"""
def __init__(self, code):
"""Just assign return codes."""
try:
self.errno = int(code)
except ValueError:
self.errno = code
if self.errno in ERROR_MESSAGE:
# Timeout for the reader thread. Any value will do, the only impact is the time
# needed to stop the thread when the instance is destroyed...
TIMEOUT = 2
# Timeout for response and events
# The RAK811 typically respond in less than 1.5 seconds
RESPONSE_TIMEOUT = 5
# Event wait time strongly depends on duty cycle, when sending often at high SF
# the module will wait to respect the duty cycle.
# In normal operation, 5 minutes should be more than enough.
EVENT_TIMEOUT = 5 * 60
# Constants
EOL = '\r\n'
class Rak811TimeoutError(Rak811Error):
"""Read timeout exception."""
pass
class Rak811Serial(object):
"""Handles serial communication between the RPi and the RAK811 module."""
def __init__(self,
port=PORT,
baudrate=BAUDRATE,
timeout=TIMEOUT,
response_timeout=RESPONSE_TIMEOUT,
event_timeout=EVENT_TIMEOUT,
**kwargs):
"""Initialise class.