Coverage for d7a/system_files/dll_status.py: 49%
45 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.phy.channel_header import ChannelHeader, ChannelCoding, ChannelBand, ChannelClass
22from d7a.support.schema import Validatable, Types
23from d7a.system_files.file import File
24from d7a.system_files.system_file_ids import SystemFileIds
27class DllStatusFile(File, Validatable):
28 SCHEMA = [{
29 "last_rx_packet_level": Types.INTEGER(min=0, max=0xFF),
30 "last_rx_packet_link_budget": Types.INTEGER(min=0, max=0xFF),
31 "noise_floor": Types.INTEGER(min=0, max=0xFF),
32 "channel_header": Types.OBJECT(ChannelHeader),
33 "channel_index":Types.INTEGER(min=0, max=0xFFFF),
34 "scan_timeout_ratio": Types.INTEGER(min=0, max=0xFFFF),
35 "scan_count": Types.INTEGER(min=0, max=0xFFFFFFFF),
36 "scan_timeout_count": Types.INTEGER(min=0, max=0xFFFFFFFF)
37 }]
39 def __init__(self, last_rx_packet_level=0, last_rx_packet_link_budget=0, noise_floor=0,
40 channel_header=ChannelHeader(channel_coding=ChannelCoding.FEC_PN9, channel_band=ChannelBand.BAND_868, channel_class=ChannelClass.LO_RATE),
41 channel_index=0, scan_timeout_ratio=0, scan_count=0, scan_timeout_count=0):
42 self.last_rx_packet_level=last_rx_packet_level
43 self.last_rx_packet_link_budget=last_rx_packet_link_budget
44 self.noise_floor=noise_floor
45 self.channel_header=channel_header
46 self.channel_index=channel_index
47 self.scan_timeout_ratio=scan_timeout_ratio
48 self.scan_count=scan_count
49 self.scan_timeout_count=scan_timeout_count
50 File.__init__(self, SystemFileIds.DLL_STATUS.value, 16)
51 Validatable.__init__(self)
53 @staticmethod
54 def parse(s, offset=0, length=16):
55 last_rx_packet_level = s.read("uint:8")
56 last_rx_packet_link_budget = s.read("uint:8")
57 noise_floor = s.read("uint:8")
58 channel_header = ChannelHeader.parse(s)
59 channel_index = s.read("uint:16")
60 scan_timeout_ratio = s.read("uint:16")
61 scan_count = s.read("uint:32")
62 scan_timeout_count = s.read("uint:32")
63 return DllStatusFile(last_rx_packet_level=last_rx_packet_level, last_rx_packet_link_budget=last_rx_packet_link_budget,
64 noise_floor=noise_floor, channel_header=channel_header, channel_index=channel_index,
65 scan_timeout_ratio=scan_timeout_ratio, scan_count=scan_count, scan_timeout_count=scan_timeout_count)
67 def __iter__(self):
68 yield self.last_rx_packet_level
69 yield self.last_rx_packet_link_budget
70 yield self.noise_floor
71 for byte in self.channel_header:
72 yield byte
73 for byte in bytearray(struct.pack(">H", self.channel_index)):
74 yield byte
75 for byte in bytearray(struct.pack(">H", self.scan_timeout_ratio)):
76 yield byte
77 for byte in bytearray(struct.pack(">I", self.scan_count)):
78 yield byte
79 for byte in bytearray(struct.pack(">I", self.scan_timeout_count)):
80 yield byte
83 def __str__(self):
84 return "last_rx_packet_level={}, last_rx_packet_link_budget={}, noise_floor={}, channel={}{}, scan_timeout_ratio={}, scan_count={}, scan_timeout_count={}".format(self.last_rx_packet_level, self.last_rx_packet_link_budget, self.noise_floor, self.channel_header, self.channel_index, self.scan_timeout_ratio, self.scan_count, self.scan_timeout_count)