Coverage for d7a/alp/operands/lorawan_interface_configuration_abp.py: 97%
38 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
1#
2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV.
3#
4# This file is part of pyd7a.
5# See https://github.com/Sub-IoT/pyd7a for further info.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19import struct
21from d7a.support.schema import Validatable, Types
24class LoRaWANInterfaceConfigurationABP(Validatable):
26 SCHEMA = [{
27 # # TODO first byte is extensible with other fields
28 # "adr_enabled": Types.BOOLEAN(),
29 # "request_ack": Types.BOOLEAN(),
30 # "application_port": Types.BYTE(),
31 # "data_rate": Types.BYTE(),
32 # "netw_session_key": Types.BYTES(),
33 # "app_session_key": Types.BYTES(),
34 # "dev_addr": Types.BYTES(),
35 # "netw_id": Types.BYTES(),
36 }]
38 def __init__(self, adr_enabled, request_ack, app_port, data_rate, dev_addr, netw_id):
39 self.adr_enabled = adr_enabled
40 self.request_ack = request_ack
41 self.app_port = app_port
42 self.data_rate = data_rate
43 self.dev_addr = dev_addr
44 self.netw_id = netw_id
45 super(LoRaWANInterfaceConfigurationABP, self).__init__()
47 def __iter__(self):
48 byte = 0
49 if self.request_ack:
50 byte |= 1 << 1
52 if self.adr_enabled:
53 byte |= 1 << 2
55 yield byte
56 yield self.app_port
57 yield self.data_rate
59 for byte in bytearray(struct.pack(">I", self.dev_addr)):
60 yield byte
62 for byte in bytearray(struct.pack(">I", self.netw_id)):
63 yield byte
65 def __str__(self):
66 return str(self.as_dict())
68 @staticmethod
69 def parse(s):
70 _rfu = s.read("bits:5")
71 adr_enabled = s.read("bool")
72 request_ack = s.read("bool")
73 _rfu = s.read("bits:1")
74 app_port = s.read("uint:8")
75 data_rate = s.read("uint:8")
76 dev_addr = s.read("uint:32")
77 netw_id = s.read("uint:32")
79 return LoRaWANInterfaceConfigurationABP(
80 request_ack=request_ack,
81 adr_enabled=adr_enabled,
82 app_port=app_port,
83 data_rate=data_rate,
84 dev_addr=dev_addr,
85 netw_id=netw_id,
86 )