OceanDirectLighthouse 3.1.3
OceanDirect Lighthouse Python API
LighthouseTypes.py
Go to the documentation of this file.
2from ctypes import Structure, cast, c_uint8, c_uint64, c_size_t, c_float, POINTER
3
4class OceanDirectError(Exception):
5 """!
6 An error code and error message object wrapper.
7 """
8 def __init__(self, errorCode: int, errorMsg: str):
9 super(OceanDirectError, self).__init__(errorMsg)
10 self._error_code = errorCode
11 self._error_msg = errorMsg
12
13 def get_error_details(self) -> tuple[int, str]:
14 return (self._error_code, self._error_msg)
15
16class SpectrumWithMetadata_C(Structure):
17 """!
18 Python wrapper for C-structure, SpectrumWithMetadata. This is use internally
19 by the wrapper.
20 NOTE:
21 The field order and type must match those of the C-structure we defined otherwise
22 python will throw a runtime error. User must not alter this definition.
23 """
24 _fields_ = [("buffer", POINTER(c_float)),
25 ("bufferLength", c_size_t),
26 ("tickCount", c_uint64)]
27
28 def __init__(self, spectraLength: int):
29 #Allocate space for the structure.
30 spectraBuffer = (c_float * spectraLength)(0)
31 self.buffer = cast(spectraBuffer, POINTER(c_float))
32 self.bufferLength = c_size_t(spectraLength)
33 self.tickCount = c_uint64(0)
34
35 def getSpectra(self)->list[float]:
36 #Convert the native type array into a python list
37 return self.buffer[:self.bufferLength]
38
40 """!
41 Python class containing spectrum and metadata (tickcount).
42 """
43 def __init__(self, newSpectrum: list[float], newTickCount: int):
44 self.spectrum = newSpectrum
45 self.tickCount = newTickCount
46
48 """!
49 Python class containing network configuration (tickcount).
50 """
51 def __init__(self, ipv4Address: list[int], subnetMask: list[int],
52 defaultGateway: list[int], dnsServer: list[int]):
53 self.ipv4Address = ipv4Address
54 self.subnetMask = subnetMask
55 self.defaultGateway = defaultGateway
56 self.dnsServer = dnsServer
57
59 networkConfig = LighthouseNetworkConfiguration_C()
60
61 for i in range(len(self.ipv4Address)):
62 networkConfig.ipv4Address[i] = self.ipv4Address[i]
63 networkConfig.subnetMask[i] = self.subnetMask[i]
64 networkConfig.defaultGateway[i] = self.defaultGateway[i]
65 networkConfig.dnsServer[i] = self.dnsServer[i]
66
67 return networkConfig
68
69
71 """!
72 Python wrapper for C-structure, LighthouseNetworkConfiguration. This is use internally
73 by the wrapper.
74 NOTE:
75 The field order and type must match those of the C-structure we defined otherwise
76 python will throw a runtime error. User must not alter this definition.
77 """
78 _fields_ = [("ipv4Address", POINTER(c_uint8)),
79 ("ipv4AddressSize", c_size_t),
80 ("subnetMask", POINTER(c_uint8)),
81 ("subnetMaskSize", c_size_t),
82 ("defaultGateway", POINTER(c_uint8)),
83 ("defaultGatewaySize", c_size_t),
84 ("dnsServer", POINTER(c_uint8)),
85 ("dnsServerSize", c_size_t) ]
86
87 def __init__(self):
88 #Allocate space for the structure.
89 self.ipv4AddressSize = c_size_t(4)
90 self.subnetMaskSize = c_size_t(4)
91 self.defaultGatewaySize = c_size_t(4)
92 self.dnsServerSize = c_size_t(4)
93
94 ipv4AddressBuffer = (c_uint8 * 4)(0)
95 subnetMaskBuffer = (c_uint8 * 4)(0)
96 defaultGatewayBuffer = (c_uint8 * 4)(0)
97 dnsServerBuffer = (c_uint8 * 4)(0)
98
99 self.ipv4Address = cast(ipv4AddressBuffer, POINTER(c_uint8))
100 self.subnetMask = cast(subnetMaskBuffer, POINTER(c_uint8))
101 self.defaultGateway = cast(defaultGatewayBuffer, POINTER(c_uint8))
102 self.dnsServer = cast(dnsServerBuffer, POINTER(c_uint8))
103
104 def getLighthouseNetworkConfiguration(self)->LighthouseNetworkConfiguration:
105 #Convert the native type array into a python list
107 self.subnetMask[:self.subnetMaskSize],
109 self.dnsServer[:self.dnsServerSize])
110
111
112
113
114
Python wrapper for C-structure, LighthouseNetworkConfiguration.
Python class containing network configuration (tickcount).
__init__(self, list[int] ipv4Address, list[int] subnetMask, list[int] defaultGateway, list[int] dnsServer)
An error code and error message object wrapper.
__init__(self, int errorCode, str errorMsg)
Python wrapper for C-structure, SpectrumWithMetadata.
Python class containing spectrum and metadata (tickcount).
__init__(self, list[float] newSpectrum, int newTickCount)