Coverage for d7a/dll/access_profile.py: 84%

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

19from enum import Enum 

20 

21from d7a.dll.sub_profile import SubProfile 

22from d7a.phy.channel_header import ChannelHeader 

23from d7a.phy.subband import SubBand 

24from d7a.support.schema import Validatable, Types 

25from d7a.types.ct import CT 

26 

27 

28class CsmaCaMode(Enum): 

29 UNC = 0 

30 AIND = 1 

31 RAIND = 2 

32 RIGD = 3 

33 

34 

35class AccessProfile(Validatable): 

36 NUMBER_OF_SUB_PROFILES = 4 

37 MAX_NUMBER_OF_SUB_BANDS = 8 

38 

39 # TODO update to D7AP v1.1 

40 SCHEMA = [{ 

41 "channel_header": Types.OBJECT(ChannelHeader), 

42 "sub_profiles": Types.LIST(SubProfile, minlength=4, maxlength=4), 

43 "sub_bands": Types.LIST(SubBand, minlength=0, maxlength=8) 

44 }] 

45 

46 def __init__(self, channel_header, sub_profiles, sub_bands): 

47 self.channel_header = channel_header 

48 self.sub_profiles = sub_profiles 

49 self.sub_bands = sub_bands 

50 super(AccessProfile, self).__init__() 

51 

52 @staticmethod 

53 def parse(s): 

54 channel_header = ChannelHeader.parse(s) 

55 sub_profiles = [] 

56 for _ in range(AccessProfile.NUMBER_OF_SUB_PROFILES): 

57 sub_profiles.append(SubProfile.parse(s)) 

58 

59 sub_bands = [] 

60 for _ in range(AccessProfile.MAX_NUMBER_OF_SUB_BANDS): 

61 sub_bands.append(SubBand.parse(s)) 

62 

63 return AccessProfile(channel_header=channel_header, 

64 sub_bands=sub_bands, 

65 sub_profiles=sub_profiles 

66 ) 

67 

68 def __iter__(self): 

69 for byte in self.channel_header: yield byte 

70 for sp in self.sub_profiles: 

71 for byte in sp: yield byte 

72 

73 for sb in self.sub_bands: 

74 for byte in sb: yield byte 

75 

76 def __str__(self): 

77 subprofiles_string = "" 

78 for subprofile in self.sub_profiles: 

79 subprofiles_string = subprofiles_string + str(subprofile) 

80 

81 subbands_string = "" 

82 for subband in self.sub_bands: 

83 subbands_string = subbands_string + str(subband) 

84 

85 return "channel_header={}, sub_profiles={}, sub_bands={}".format( 

86 self.channel_header, 

87 subprofiles_string, 

88 subbands_string 

89 )