Skip to content

minor lora sx126x _cmd optimization #895

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

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 6 additions & 6 deletions micropython/lora/lora-sx126x/lora/sx126x.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(
dio3_tcxo_start_time_us if dio3_tcxo_millivolts else 0
)

self._buf = bytearray(9) # shared buffer for commands
self._buf_view = memoryview(bytearray(9)) # shared buffer for commands

# These settings are kept in the object (as can't read them back from the modem)
self._output_power = 14
Expand Down Expand Up @@ -704,11 +704,11 @@ def _cmd(self, fmt, *write_args, n_read=0, write_buf=None, read_buf=None):
# have happened well before _cmd() is called again.
self._wait_not_busy(self._busy_timeout)

# Pack write_args into _buf and wrap a memoryview of the correct length around it
# Pack write_args into slice of _buf_view memoryview of correct length
wrlen = struct.calcsize(fmt)
assert n_read + wrlen <= len(self._buf) # if this fails, make _buf bigger!
struct.pack_into(fmt, self._buf, 0, *write_args)
buf = memoryview(self._buf)[: (wrlen + n_read)]
assert n_read + wrlen <= len(self._buf_view) # if this fails, make _buf bigger!
struct.pack_into(fmt, self._buf_view, 0, *write_args)
buf = self._buf_view[: (wrlen + n_read)]

if _DEBUG:
print(">>> {}".format(buf[:wrlen].hex()))
Expand All @@ -723,7 +723,7 @@ def _cmd(self, fmt, *write_args, n_read=0, write_buf=None, read_buf=None):
self._cs(1)

if n_read > 0:
res = memoryview(buf)[wrlen : (wrlen + n_read)] # noqa: E203
res = self._buf_view[wrlen : (wrlen + n_read)] # noqa: E203
if _DEBUG:
print("<<< {}".format(res.hex()))
return res
Expand Down
2 changes: 1 addition & 1 deletion micropython/lora/lora-sx126x/manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metadata(version="0.1.2")
metadata(version="0.1.3")
require("lora")
package("lora")
Loading