Browse Source

support importing this w/o the lib...

this is more of a problem w/ the utility function being in lora
which loraserv imports...  if/when that happens this could be reverted..
irr_shared
John-Mark Gurney 3 years ago
parent
commit
3a6deb531e
1 changed files with 28 additions and 21 deletions
  1. +28
    -21
      lora_comms.py

+ 28
- 21
lora_comms.py View File

@@ -62,11 +62,17 @@ def make_pktbuf(s):

process_msgfunc_t = CFUNCTYPE(None, PktBuf, POINTER(PktBuf))

_lib = CDLL('liblora_test.dylib')

_lib._strobe_state_size.restype = c_size_t
_lib._strobe_state_size.argtypes = ()
_strobe_state_u64_cnt = (_lib._strobe_state_size() + 7) // 8
try:
_lib = CDLL('liblora_test.dylib')
except OSError:
_lib = None

if _lib is not None:
_lib._strobe_state_size.restype = c_size_t
_lib._strobe_state_size.argtypes = ()
_strobe_state_u64_cnt = (_lib._strobe_state_size() + 7) // 8
else:
_strobe_state_u64_cnt = 1

class CommsSession(Structure,StructureRepr):
_fields_ = [
@@ -89,22 +95,23 @@ class CommsState(Structure,StructureRepr):
('cs_prevmsgrespbuf', c_uint8 * 64),
]

_lib._comms_state_size.restype = c_size_t
_lib._comms_state_size.argtypes = ()

if _lib._comms_state_size() != sizeof(CommsState): # pragma: no cover
raise RuntimeError('CommsState structure size mismatch!')

for func, ret, args in [
('comms_init', None, (POINTER(CommsState), process_msgfunc_t,
POINTER(PktBuf))),
('comms_process', None, (POINTER(CommsState), PktBuf, POINTER(PktBuf))),
('strobe_seed_prng', None, (POINTER(c_uint8), c_ssize_t)),
]:
f = getattr(_lib, func)
f.restype = ret
f.argtypes = args
locals()[func] = f
if _lib is not None:
_lib._comms_state_size.restype = c_size_t
_lib._comms_state_size.argtypes = ()

if _lib._comms_state_size() != sizeof(CommsState): # pragma: no cover
raise RuntimeError('CommsState structure size mismatch!')

for func, ret, args in [
('comms_init', None, (POINTER(CommsState), process_msgfunc_t,
POINTER(PktBuf))),
('comms_process', None, (POINTER(CommsState), PktBuf, POINTER(PktBuf))),
('strobe_seed_prng', None, (POINTER(c_uint8), c_ssize_t)),
]:
f = getattr(_lib, func)
f.restype = ret
f.argtypes = args
locals()[func] = f

def comms_process_wrap(state, input):
'''A wrapper around comms_process that converts the argument


Loading…
Cancel
Save