Coverage for test/d7a/alp/operations/test_forward.py: 100%

29 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 unittest 

20 

21from d7a.alp.interface import InterfaceType 

22from d7a.alp.operands.interface_configuration import InterfaceConfiguration 

23from d7a.alp.operands.lorawan_interface_configuration_abp import LoRaWANInterfaceConfigurationABP 

24from d7a.alp.operands.lorawan_interface_configuration_otaa import LoRaWANInterfaceConfigurationOTAA 

25from d7a.alp.operations.forward import Forward 

26from d7a.sp.configuration import Configuration 

27 

28 

29class TestForward(unittest.TestCase): 

30 def test_byte_generation_forward_D7A_iface(self): 

31 d7asp_config = Configuration() 

32 forward_action = Forward( 

33 operand=InterfaceConfiguration( 

34 interface_id=InterfaceType.D7ASP, 

35 interface_configuration=d7asp_config 

36 ) 

37 ) 

38 

39 bytes = bytearray(forward_action) 

40 self.assertEqual(len(bytes), len(bytearray(d7asp_config)) + 1) 

41 self.assertEqual(bytes[0], 0xD7) 

42 self.assertEqual(bytes[1:], bytearray(d7asp_config)) 

43 # TODO configuration 

44 

45 def test_byte_generation_forward_LoRaWAN_ABP_iface(self): 

46 lorawan_config = LoRaWANInterfaceConfigurationABP( 

47 adr_enabled=True, 

48 request_ack=False, 

49 app_port=0x01, 

50 data_rate=0, 

51 dev_addr=1, 

52 netw_id=1 

53 ) 

54 

55 forward_action = Forward( 

56 operand=InterfaceConfiguration( 

57 interface_id=InterfaceType.LORAWAN_ABP, 

58 interface_configuration=lorawan_config 

59 ) 

60 ) 

61 

62 bytes = bytearray(forward_action) 

63 self.assertEqual(len(bytes), len(bytearray(lorawan_config)) + 1) 

64 self.assertEqual(bytes[0], 0x02) 

65 self.assertEqual(bytes[1:], bytearray(lorawan_config)) 

66 

67 def test_byte_generation_forward_LoRaWAN_OTAA_iface(self): 

68 lorawan_config = LoRaWANInterfaceConfigurationOTAA( 

69 adr_enabled=True, 

70 request_ack=False, 

71 app_port=0x01, 

72 data_rate=0, 

73 ) 

74 

75 forward_action = Forward( 

76 operand=InterfaceConfiguration( 

77 interface_id=InterfaceType.LORAWAN_OTAA, 

78 interface_configuration=lorawan_config 

79 ) 

80 ) 

81 

82 bytes = bytearray(forward_action) 

83 self.assertEqual(len(bytes), len(bytearray(lorawan_config)) + 1) 

84 self.assertEqual(bytes[0], 0x03) 

85 self.assertEqual(bytes[1:], bytearray(lorawan_config)) 

86 

87 

88