Coverage for d7a/alp/status_action.py: 92%

26 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.alp.action import Action 

20from d7a.alp.operations.nop import NoOperation 

21from d7a.alp.operations.operation import Operation 

22from d7a.support.schema import Types 

23 

24__author__ = 'glenn' 

25 

26class StatusActionOperandExtensions(object): 

27 ACTION_STATUS = 0 

28 INTERFACE_STATUS = 1 

29 ALL = [ ACTION_STATUS, INTERFACE_STATUS ] 

30 

31 @staticmethod 

32 def SCHEMA(): 

33 return { "type": "integer", "allowed" : StatusActionOperandExtensions.ALL } 

34 

35 

36class StatusAction(Action): 

37 SCHEMA = [{ 

38 "status_operand_extension" : Types.INTEGER(values=StatusActionOperandExtensions.ALL), 

39 "operation": Types.OBJECT(Operation), 

40 "operand" : Types.OBJECT(nullable=True) # there is no Operand base-class 

41 }] 

42 

43 def __init__(self, status_operand_extension, operation): 

44 self.status_operand_extension = status_operand_extension 

45 self.operation = operation 

46 super(StatusAction, self).__init__(operation=operation) 

47 

48 def __iter__(self): 

49 byte = 0 

50 byte |= self.status_operand_extension << 6 

51 byte += self.op 

52 yield byte 

53 

54 for byte in self.operation: yield byte 

55 

56 def __str__(self): 

57 return "{}".format(self.operand)