Coverage for d7a/phy/subband.py: 96%
28 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
22from d7a.support.schema import Validatable, Types
25class SubBand(Validatable):
26 # TODO update to D7AP v1.1
28 SCHEMA = [{
29 "channel_index_start": Types.INTEGER(min=0, max=0xFFFF),
30 "channel_index_end": Types.INTEGER(min=0, max=0xFFFF),
31 "eirp": Types.INTEGER(min=-128, max=127),
32 "cca": Types.INTEGER(min=0, max=255),
33 "duty": Types.INTEGER(min=0, max=255),
34 }]
36 def __init__(self, channel_index_start=0, channel_index_end=0, eirp=0, cca=86, duty=255):
37 self.channel_index_start = channel_index_start
38 self.channel_index_end = channel_index_end
39 self.eirp = eirp
40 self.cca = cca
41 self.duty = duty
42 super(SubBand, self).__init__()
44 def __iter__(self):
45 for byte in bytearray(struct.pack(">H", self.channel_index_start)): yield byte
46 for byte in bytearray(struct.pack(">H", self.channel_index_end)): yield byte
47 for byte in bytearray(struct.pack("b", self.eirp)): yield byte
48 yield self.cca
49 yield self.duty
51 @staticmethod
52 def parse(s):
53 channel_index_start = struct.unpack(">H", s.read("bytes:2"))[0]
54 channel_index_end = struct.unpack(">H", s.read("bytes:2"))[0]
55 eirp = s.read("int:8")
56 cca = s.read("uint:8")
57 duty = s.read("uint:8")
59 return SubBand(channel_index_start=channel_index_start,
60 channel_index_end=channel_index_end,
61 eirp=eirp,
62 cca=cca,
63 duty=duty)
65 def __str__(self):
66 return "channel_index_start={}, channel_index_end={}, eirp={}, cca={}, duty={}".format(
67 self.channel_index_start,
68 self.channel_index_end,
69 self.eirp,
70 self.cca,
71 self.duty
72 )