Coverage for d7a/phy/channel_status_identifier.py: 45%

31 statements  

« 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# 

19 

20from d7a.phy.channel_header import ChannelBand 

21from d7a.support.schema import Validatable, Types 

22from enum import Enum 

23 

24class Bandwidth(Enum): 

25 kHz25 = 0x01 

26 kHz200 = 0x00 

27 

28 def to_string(self): 

29 return self.name 

30 

31class ChannelStatusIdentifier(Validatable): 

32 # TODO update to D7AP v1.1 

33 

34 SCHEMA = [{ 

35 "channel_band": Types.ENUM(ChannelBand), 

36 "channel_bandwidth": Types.ENUM(Bandwidth), 

37 "channel_index": Types.INTEGER(min=0, max=1039) 

38 }] 

39 

40 def __init__(self, channel_band=ChannelBand.NOT_IMPL, channel_bandwidth=Bandwidth.kHz25, channel_index=0): 

41 self.channel_band = channel_band 

42 self.channel_bandwidth = channel_bandwidth 

43 self.channel_index = channel_index 

44 super(ChannelStatusIdentifier, self).__init__() 

45 

46 def __iter__(self): 

47 byte = self.channel_band.value << 5 

48 byte += self.channel_bandwidth.value << 4 

49 byte += 0 << 3 # RFU 

50 byte += (self.channel_index >> 8) & 0x07 

51 yield byte 

52 yield self.channel_index & 0xFF 

53 

54 @staticmethod 

55 def parse(s): 

56 channel_band = ChannelBand(s.read("uint:3")) 

57 channel_bandwidth = Bandwidth(s.read("uint:1")) 

58 s.read("uint:1") # RFU 

59 channel_index = s.read("uint:11") 

60 return ChannelStatusIdentifier(channel_band=channel_band, channel_bandwidth=channel_bandwidth, channel_index=channel_index) 

61 

62 def __str__(self): 

63 return "channel_band={}, channel_bandwidth={}, channel_index={}".format( 

64 self.channel_band.name.lstrip("BAND_"), 

65 self.channel_bandwidth.to_string(), 

66 self.channel_index 

67 )