Coverage for d7a/alp/operands/lorawan_interface_configuration_otaa.py: 97%
30 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 LoRaWANInterfaceConfigurationOTAA(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 # "device_eui": Types.BYTES(),
33 # "app_eui": Types.BYTES(),
34 # "app_key": Types.BYTES()
35 }]
37 def __init__(self, adr_enabled, request_ack, app_port, data_rate):
38 self.adr_enabled = adr_enabled
39 self.request_ack = request_ack
40 self.app_port = app_port
41 self.data_rate = data_rate
42 super(LoRaWANInterfaceConfigurationOTAA, self).__init__()
44 def __iter__(self):
45 byte = 0
46 if self.request_ack:
47 byte |= 1 << 1
49 if self.adr_enabled:
50 byte |= 1 << 2
52 yield byte
53 yield self.app_port
54 yield self.data_rate
57 def __str__(self):
58 return str(self.as_dict())
60 @staticmethod
61 def parse(s):
62 _rfu = s.read("bits:5")
63 adr_enabled = s.read("bool")
64 request_ack = s.read("bool")
65 _rfu = s.read("bits:1")
66 app_port = s.read("uint:8")
67 data_rate = s.read("uint:8")
69 return LoRaWANInterfaceConfigurationOTAA(
70 request_ack=request_ack,
71 adr_enabled=adr_enabled,
72 app_port=app_port,
73 data_rate=data_rate
74 )