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

[LoRaWAN] Add monkeypatch for Dragino SX-127x #113

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions src/lib/terkin_cpython/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,16 @@ def exc(self, e, msg, *args):
self.log(logging.ERROR, msg + "\n" + buf.getvalue(), *args)

logging.Logger.exc = exc


def monkeypatch_sx127x():
from unittest.mock import MagicMock
sys.modules["dragino.SX127x.board_config"] = MagicMock()
import dragino
from dragino.SX127x.LoRa import LoRa as orig
orig.get_freq = lambda x: 5.
def set_mode(self, mode):
self.mode = 0x80
orig.set_mode = set_mode
orig.get_agc_auto_on = lambda x: 1
dragino.SX127x.LoRa.LoRa = orig
2 changes: 2 additions & 0 deletions src/lib/terkin_cpython/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def patch_system():
log.info('Setting up CPython compatibility layer')
from terkin_cpython.compat import monkeypatch_cpython
monkeypatch_cpython()
from terkin_cpython.compat import monkeypatch_sx127x
monkeypatch_sx127x()


def setup_logging():
Expand Down