Coverage for d7a/d7atp/control.py: 100%

33 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 d7a.support.schema import Validatable, Types 

20 

21class Control(Validatable): 

22 

23 SCHEMA = [{ 

24 "is_dialog_start": Types.BOOLEAN(), 

25 "has_tl": Types.BOOLEAN(), 

26 "has_te": Types.BOOLEAN(), 

27 "is_ack_requested": Types.BOOLEAN(), 

28 "is_ack_not_void": Types.BOOLEAN(), 

29 "is_ack_record_requested": Types.BOOLEAN(), 

30 "has_agc": Types.BOOLEAN() 

31 }] 

32 

33 def __init__(self, is_dialog_start, has_tl, has_te, is_ack_requested, is_ack_not_void, is_ack_record_requested, has_agc): 

34 self.is_dialog_start = is_dialog_start 

35 self.has_tl = has_tl 

36 self.has_te = has_te 

37 self.is_ack_requested = is_ack_requested 

38 self.is_ack_not_void = is_ack_not_void 

39 self.is_ack_record_requested = is_ack_record_requested 

40 self.has_agc = has_agc 

41 super(Control, self).__init__() 

42 

43 @staticmethod 

44 def parse(s): 

45 is_dialog_start = s.read("bool") 

46 _ = s.read("bool") # RFU 

47 has_tl = s.read("bool") 

48 has_te = s.read("bool") 

49 is_ack_requested = s.read("bool") 

50 is_ack_not_void = s.read("bool") 

51 is_ack_record_requested = s.read("bool") 

52 has_agc = s.read("bool") 

53 

54 return Control( 

55 is_dialog_start=is_dialog_start, 

56 has_tl=has_tl, 

57 has_te=has_te, 

58 is_ack_requested=is_ack_requested, 

59 is_ack_not_void=is_ack_not_void, 

60 is_ack_record_requested=is_ack_record_requested, 

61 has_agc=has_agc 

62 ) 

63 

64 def __iter__(self): 

65 byte = 0 

66 if self.is_dialog_start: byte |= 1 << 7 

67 if self.has_tl: byte |= 1 << 5 

68 if self.has_te: byte |= 1 << 4 

69 if self.is_ack_requested: byte |= 1 << 3 

70 if self.is_ack_not_void: byte |= 1 << 2 

71 if self.is_ack_record_requested: byte |= 1 << 1 

72 byte += self.has_agc 

73 yield byte