OceanDirectLighthouse  3.1.1
OceanDirect Lighthouse Python API
LighthouseTypes.py
Go to the documentation of this file.
1 
2 from ctypes import Structure, cast, c_uint8, c_uint64, c_size_t, c_float, POINTER
3 
4 class 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_error_code = errorCode
11  self._error_msg_error_msg = errorMsg
12 
13  def get_error_details(self) -> tuple[int, str]:
14  return (self._error_code_error_code, self._error_msg_error_msg)
15 
16 class 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.bufferbuffer = cast(spectraBuffer, POINTER(c_float))
32  self.bufferLengthbufferLength = c_size_t(spectraLength)
33  self.tickCounttickCount = c_uint64(0)
34 
35  def getSpectra(self)->list[float]:
36  #Convert the native type array into a python list
37  return self.bufferbuffer[:self.bufferLengthbufferLength]
38 
40  """!
41  Python class containing spectrum and metadata (tickcount).
42  """
43  def __init__(self, newSpectrum: list[float], newTickCount: int):
44  self.spectrumspectrum = newSpectrum
45  self.tickCounttickCount = 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.ipv4Addressipv4Address = ipv4Address
54  self.subnetMasksubnetMask = subnetMask
55  self.defaultGatewaydefaultGateway = defaultGateway
56  self.dnsServerdnsServer = dnsServer
57 
59  networkConfig = LighthouseNetworkConfiguration_C()
60 
61  for i in range(len(self.ipv4Addressipv4Address)):
62  networkConfig.ipv4Address[i] = self.ipv4Addressipv4Address[i]
63  networkConfig.subnetMask[i] = self.subnetMasksubnetMask[i]
64  networkConfig.defaultGateway[i] = self.defaultGatewaydefaultGateway[i]
65  networkConfig.dnsServer[i] = self.dnsServerdnsServer[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.ipv4AddressSizeipv4AddressSize = c_size_t(4)
90  self.subnetMaskSizesubnetMaskSize = c_size_t(4)
91  self.defaultGatewaySizedefaultGatewaySize = c_size_t(4)
92  self.dnsServerSizednsServerSize = 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.ipv4Addressipv4Address = cast(ipv4AddressBuffer, POINTER(c_uint8))
100  self.subnetMasksubnetMask = cast(subnetMaskBuffer, POINTER(c_uint8))
101  self.defaultGatewaydefaultGateway = cast(defaultGatewayBuffer, POINTER(c_uint8))
102  self.dnsServerdnsServer = cast(dnsServerBuffer, POINTER(c_uint8))
103 
104  def getLighthouseNetworkConfiguration(self)->LighthouseNetworkConfiguration:
105  #Convert the native type array into a python list
106  return LighthouseNetworkConfiguration(self.ipv4Addressipv4Address[:self.ipv4AddressSizeipv4AddressSize],
107  self.subnetMasksubnetMask[:self.subnetMaskSizesubnetMaskSize],
108  self.defaultGatewaydefaultGateway[:self.defaultGatewaySizedefaultGatewaySize],
109  self.dnsServerdnsServer[:self.dnsServerSizednsServerSize])
110 
111 
112 
113 
114 
Python wrapper for C-structure, LighthouseNetworkConfiguration.
LighthouseNetworkConfiguration getLighthouseNetworkConfiguration(self)
Python class containing network configuration (tickcount).
def __init__(self, list[int] ipv4Address, list[int] subnetMask, list[int] defaultGateway, list[int] dnsServer)
An error code and error message object wrapper.
def __init__(self, int errorCode, str errorMsg)
Python wrapper for C-structure, SpectrumWithMetadata.
Python class containing spectrum and metadata (tickcount).
def __init__(self, list[float] newSpectrum, int newTickCount)