Coverage for d7a/sp/status.py: 98%

55 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 

20# author: Christophe VG <contact@christophe.vg> 

21# class implementation of status meta-data 

22 

23# D7ASP Status 

24# 

25# STATUS 1 byte Slave D7ASP Status 9.2.9.1 

26# b7 NLS NWL Security Enabled 

27# b6 MISSED Always 0 for Responses. For Requests - set to 0 when the  

28# D7ATP ACK_BITMAP is empty. 

29# b5 RETRY Always 0 for Responses. For Request - depends on the value of  

30# the D7ATP Transaction ID bit in ACK_BITMAP before reception  

31# of the current Request. When set to 1, a segment with the  

32# same REQUEST_ID and FIFO_TOKEN has already been vectored to  

33# upper layer. 

34# b4-b3 RFU 

35# b2-b0 STATE Session State 

36# FIFO_TOKEN 1 byte Value of the D7ATP Dialog ID 

37# REQUEST_ID 1 bytes Value of the D7ATP Transaction ID 

38# RESPONSE_TO 1 byte D7ATP Addressee Access Profile's Tc in Compressed  

39# Time Format. 

40# ADDRESSEE 1/3/9 bytes D7ATP Addressee 

41import struct 

42 

43from d7a.phy.channel_id import ChannelID 

44from d7a.support.schema import Validatable, Types 

45from d7a.types.ct import CT 

46from d7a.d7anp.addressee import Addressee 

47from d7a.phy.channel_header import ChannelHeader 

48 

49class Status(Validatable): 

50 

51 SCHEMA = [{ 

52 "channel_id" : Types.OBJECT(ChannelID), 

53 "rx_level" : Types.BYTE(), 

54 "link_budget": Types.BYTE(), 

55 "target_rx_level": Types.BYTE(), 

56 "nls" : Types.BOOLEAN(), 

57 "missed" : Types.BOOLEAN(), 

58 "retry" : Types.BOOLEAN(), 

59 "ucast" : Types.BOOLEAN(), 

60 "fifo_token" : Types.BYTE(), 

61 "seq_nr" : Types.BYTE(), 

62 "response_to": Types.OBJECT(CT), 

63 "addressee" : Types.OBJECT(Addressee) 

64 }] 

65 

66 def __init__(self, channel_id, rx_level, link_budget, target_rx_level, nls, missed, retry, unicast, 

67 fifo_token, seq_nr, response_to, addressee): 

68 self.channel_id = channel_id 

69 self.rx_level = rx_level 

70 self.link_budget = link_budget 

71 self.target_rx_level = target_rx_level 

72 self.nls = nls 

73 self.missed = missed 

74 self.retry = retry 

75 self.unicast = unicast 

76 self.fifo_token = fifo_token 

77 self.seq_nr = seq_nr 

78 self.response_to = response_to 

79 self.addressee = addressee 

80 super(Status, self).__init__() 

81 

82 

83 @staticmethod 

84 def parse(s): 

85 channel_id = ChannelID.parse(s) 

86 rx_level = s.read("int:8") 

87 link_budget = s.read("uint:8") 

88 target_rx_level = s.read("uint:8") 

89 nls = s.read("bool") 

90 missed = s.read("bool") 

91 retry = s.read("bool") 

92 unicast = s.read("bool" ) 

93 _ = s.read("pad:4") 

94 fifo_token = s.read("uint:8") 

95 seq_nr = s.read("uint:8") 

96 response_to = CT.parse(s) 

97 addressee = Addressee.parse(s) 

98 

99 return Status(channel_id=channel_id, 

100 rx_level=rx_level, link_budget=link_budget, 

101 target_rx_level=target_rx_level, nls=nls, missed=missed, 

102 retry=retry, unicast=unicast, fifo_token=fifo_token, 

103 seq_nr=seq_nr, response_to=response_to, addressee=addressee) 

104 

105 def __iter__(self): 

106 for byte in self.channel_id: yield byte 

107 yield self.rx_level 

108 yield self.link_budget 

109 yield self.target_rx_level 

110 byte = 0 

111 if self.nls: byte |= 1 << 7 

112 if self.missed: byte |= 1 << 6 

113 if self.retry: byte |= 1 << 5 

114 if self.unicast: byte |= 1 << 4 

115 yield byte 

116 yield self.fifo_token 

117 yield self.seq_nr 

118 for byte in self.response_to: yield byte 

119 for byte in self.addressee: yield byte 

120 

121 def __str__(self): 

122 return "unicast={}, nls={}, retry={}, missed={}, fifo_token={}, rx_level={}, seq_nr={}, target_rx_level={}, " \ 

123 "addressee={}, response_to={}, link_budget={}, channel_id={}".format( 

124 self.unicast, 

125 self.nls, 

126 self.retry, 

127 self.missed, 

128 self.fifo_token, 

129 self.rx_level, 

130 self.seq_nr, 

131 self.target_rx_level, 

132 self.addressee, 

133 self.response_to, 

134 self.link_budget, 

135 self.channel_id 

136 )