Coverage for d7a/system_files/vid.py: 95%

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

19import struct 

20 

21from d7a.support.schema import Validatable, Types 

22from d7a.system_files.file import File 

23from d7a.system_files.system_file_ids import SystemFileIds 

24 

25 

26class VidFile(File, Validatable): 

27 SCHEMA = [{ 

28 "vid": Types.INTEGER(min=0, max=0xFFFF), 

29 "control": Types.INTEGER(min=0, max=0xFF) 

30 }] 

31 

32 

33 def __init__(self, vid=0xFFFF, control=0x00): 

34 self.vid = vid 

35 self.control = control 

36 File.__init__(self, SystemFileIds.VID.value, 3) 

37 Validatable.__init__(self) 

38 

39 @staticmethod 

40 def parse(s, offset=0, length=3): 

41 vid = s.read("uint:16") 

42 control = s.read("uint:8") 

43 return VidFile(vid=vid, control=control) 

44 

45 def __iter__(self): 

46 for byte in bytearray(struct.pack(">H", self.vid)): 

47 yield byte 

48 yield self.control 

49 

50 

51 def __str__(self): 

52 return "vid={}, control={}".format(hex(self.vid), hex(self.control))