Coverage for d7a/dll/background_frame_control.py: 78%

18 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.d7anp.addressee import IdType 

20from d7a.support.schema import Validatable, Types 

21 

22class BackgroundFrameControl(Validatable): 

23 

24 SCHEMA = [{ 

25 "id_type": Types.ENUM(IdType), 

26 "tag": Types.INTEGER(None, 0, 63) 

27 }] 

28 

29 def __init__(self, id_type, tag): 

30 self.id_type = id_type 

31 self.tag = tag 

32 super(BackgroundFrameControl, self).__init__() 

33 

34 @staticmethod 

35 def parse(s): 

36 id_type = IdType(s.read("uint:2")) 

37 tag = s.read("uint:6") 

38 return BackgroundFrameControl( 

39 id_type=id_type, 

40 tag=tag 

41 ) 

42 

43 def __iter__(self): 

44 byte = 0 

45 byte |= self.id_type.value << 6 

46 byte += self.tag 

47 yield byte