def unpack_echo(lwm: LoraWanMsg, *, orig: Optional[bytes] = None, **kwargs: Any) -> bytes: assert lwm.rtm is not None payload: bytes = lwm.rtm['FRMPayload'] expect.assert_equal(0x04, payload[0], explain('Invalid echo packet', **kwargs)) echo = payload[1:] if orig is not None: expected = bytes((x + 1) & 0xff for x in orig) expect.assert_equal(expected, echo, explain('Unexpected echo response', **kwargs)) return echo
def check_ncr_o(o: lo.Opt, ChnlAck: Optional[int] = 1, DRAck: Optional[int] = 1, **kwargs: Any) -> None: expect.assert_equal(type(o), lo.NewChannelAns, explain('Unexpected MAC command', **kwargs)) o = cast(lo.NewChannelAns, o) if ChnlAck is not None: expect.assert_equal(o.ChnlAck.value, ChnlAck, explain('Unexpected ChnlAck value', **kwargs)) # type: ignore if DRAck is not None: expect.assert_equal(o.DRAck.value, DRAck, explain('Unexpected DRAck value', **kwargs)) # type: ignore
def check_laa_o(o: lo.Opt, ChAck: Optional[int] = 1, DRAck: Optional[int] = 1, TXPowAck: Optional[int] = 1, **kwargs: Any) -> None: expect.assert_equal(type(o), lo.LinkADRAns, explain('Unexpected MAC command', **kwargs)) o = cast(lo.LinkADRAns, o) if ChAck is not None: expect.assert_equal(o.ChAck.value, ChAck, explain('Unexpected ChAck', **kwargs)) # type: ignore if DRAck is not None: expect.assert_equal(o.DRAck.value, DRAck, explain('Unexpected DRAck', **kwargs)) # type: ignore if TXPowAck is not None: expect.assert_equal(o.TXPowAck.value, TXPowAck, explain('Unexpected TXPowAck', **kwargs)) # type: ignore
async def check_freqs(self, m: LoraWanMsg, freqs: Set[int], count: Optional[int] = None, **kwargs: Any) -> LoraWanMsg: if count is None: count = 16 * len(freqs) fstats: Dict[int, int] = {} m = await self.upstats(m, count, fstats=fstats) expect.assert_equal(fstats.keys(), freqs, explain('Unexpected channel usage', **kwargs)) return m
def unpack_dnctr(lwm: LoraWanMsg, *, expected: Optional[int] = None, **kwargs: Any) -> int: assert lwm.rtm is not None payload = lwm.rtm['FRMPayload'] try: dnctr, = cast(Tuple[int], struct.unpack('>H', payload)) except struct.error as e: raise ValueError(f'invalid payload: {payload.hex()}') from e if expected is not None: expect.assert_equal( expected, dnctr, explain('Unexpected downlink counter', **kwargs)) return dnctr