CK-InoDrive-API 0.2.8__tar.gz → 0.2.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CK_InoDrive_API.egg-info/PKG-INFO +5 -4
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/IO.py +107 -6
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/defines.py +36 -3
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/discoverLan.py +12 -15
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/discoverWs.py +15 -15
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/file.py +10 -1
- CK-InoDrive-API-0.2.9/CkInoDriveAPI/inoDrive.py +56 -0
- CK-InoDrive-API-0.2.9/CkInoDriveAPI/sysControl.py +101 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/userApp.py +3 -6
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/utils.py +77 -28
- CK-InoDrive-API-0.2.9/CkInoDriveAPI/wsHandle.py +498 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/PKG-INFO +5 -4
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/README.txt +2 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/setup.py +1 -0
- CK-InoDrive-API-0.2.8/CkInoDriveAPI/inoDrive.py +0 -110
- CK-InoDrive-API-0.2.8/CkInoDriveAPI/sysControl.py +0 -36
- CK-InoDrive-API-0.2.8/CkInoDriveAPI/wsHandle.py +0 -354
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CK_InoDrive_API.egg-info/SOURCES.txt +0 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CK_InoDrive_API.egg-info/dependency_links.txt +0 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CK_InoDrive_API.egg-info/requires.txt +0 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CK_InoDrive_API.egg-info/top_level.txt +0 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/__init__.py +0 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/LICENSE.txt +0 -0
- {CK-InoDrive-API-0.2.8 → CK-InoDrive-API-0.2.9}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CK-InoDrive-API
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: InoDrive API Library
|
|
5
5
|
Home-page: https://cardinalkinetic.com
|
|
6
6
|
Author: Cardinal Kinetic
|
|
@@ -14,6 +14,7 @@ Classifier: Operating System :: Microsoft :: Windows
|
|
|
14
14
|
Classifier: Topic :: Scientific/Engineering
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
18
|
Description-Content-Type: text/markdown
|
|
18
19
|
License-File: LICENSE.txt
|
|
19
20
|
License-File: README.txt
|
|
@@ -71,7 +72,7 @@ Drive.UserApp.write_var('VariableName', 1)
|
|
|
71
72
|
Drive.disconnect()
|
|
72
73
|
|
|
73
74
|
# Drive object cleanup
|
|
74
|
-
Drive.
|
|
75
|
+
Drive.dispose()
|
|
75
76
|
```
|
|
76
77
|
|
|
77
78
|
Get and Set Output's
|
|
@@ -97,7 +98,7 @@ Drive.SysControl.take_control(False)
|
|
|
97
98
|
Drive.disconnect()
|
|
98
99
|
|
|
99
100
|
# Drive object cleanup
|
|
100
|
-
Drive.
|
|
101
|
+
Drive.dispose()
|
|
101
102
|
```
|
|
102
103
|
|
|
103
104
|
Change Module Name (Power cycle InoDrive for changes to take effect)
|
|
@@ -119,7 +120,7 @@ Drive.File.write_module_config(config_file)
|
|
|
119
120
|
Drive.disconnect()
|
|
120
121
|
|
|
121
122
|
# Drive object cleanup
|
|
122
|
-
Drive.
|
|
123
|
+
Drive.dispose()
|
|
123
124
|
```
|
|
124
125
|
|
|
125
126
|
#### **Links**
|
|
@@ -2,32 +2,107 @@ import logging
|
|
|
2
2
|
|
|
3
3
|
from .wsHandle import InoDriveWS
|
|
4
4
|
from .defines import CK
|
|
5
|
+
from .defines import OP_STATE
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class IO(object):
|
|
8
9
|
def __init__(self, **kwargs):
|
|
9
10
|
self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
|
|
10
11
|
|
|
11
|
-
def
|
|
12
|
+
def dispose(self):
|
|
13
|
+
return
|
|
14
|
+
|
|
15
|
+
def get_metrics(self):
|
|
12
16
|
try:
|
|
13
|
-
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.
|
|
17
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_METRICS])
|
|
14
18
|
|
|
15
19
|
if response.get('error'):
|
|
16
|
-
return {'success': False, 'Error': f'
|
|
20
|
+
return {'success': False, 'Error': f'InoDrive GetMetrics Error: {str(response.get("error"))}'}
|
|
17
21
|
|
|
18
22
|
data = response['data'][0]
|
|
23
|
+
|
|
24
|
+
# Operational State
|
|
25
|
+
if data.get('state'):
|
|
26
|
+
for key, value in data['state'].items():
|
|
27
|
+
data['state'][key] = OP_STATE.get_state_by_value(value)
|
|
28
|
+
|
|
29
|
+
# Ethernet Ports
|
|
30
|
+
ports = {}
|
|
31
|
+
for port in data['eth_ports']:
|
|
32
|
+
ports.update({
|
|
33
|
+
port['name']: {
|
|
34
|
+
'link': port['link'],
|
|
35
|
+
'errors': port['errors'],
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
data['eth_ports'] = ports
|
|
39
|
+
|
|
19
40
|
data.update({'success': True})
|
|
20
41
|
|
|
21
42
|
return data
|
|
22
43
|
except Exception as ex:
|
|
23
44
|
return {'success': False, 'error': str(ex)}
|
|
24
45
|
|
|
25
|
-
def
|
|
46
|
+
def get_temperatures(self):
|
|
26
47
|
try:
|
|
27
|
-
|
|
48
|
+
data = self.get_metrics()
|
|
49
|
+
if data.get('error'):
|
|
50
|
+
logging.error(data['error'])
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
'case': data['temperatures']['case'],
|
|
55
|
+
'cpu': data['temperatures']['cpu'],
|
|
56
|
+
'fets': data['temperatures']['fets'],
|
|
57
|
+
'outputs': data['temperatures']['outputs'],
|
|
58
|
+
'regen': data['temperatures']['regen']
|
|
59
|
+
}
|
|
60
|
+
except Exception as ex:
|
|
61
|
+
logging.exception(ex)
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
def get_input_voltage(self):
|
|
65
|
+
try:
|
|
66
|
+
data = self.get_metrics()
|
|
67
|
+
if data.get('error'):
|
|
68
|
+
logging.error(data['error'])
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
return data['v_in']
|
|
72
|
+
except Exception as ex:
|
|
73
|
+
logging.exception(ex)
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
def get_operational_state(self):
|
|
77
|
+
try:
|
|
78
|
+
data = self.get_metrics()
|
|
79
|
+
if data.get('error'):
|
|
80
|
+
logging.error(data['error'])
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
return data['state']
|
|
84
|
+
except Exception as ex:
|
|
85
|
+
logging.exception(ex)
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
def get_ethernet_ports(self):
|
|
89
|
+
try:
|
|
90
|
+
data = self.get_metrics()
|
|
91
|
+
if data.get('error'):
|
|
92
|
+
logging.error(data['error'])
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
return data['eth_ports']
|
|
96
|
+
except Exception as ex:
|
|
97
|
+
logging.exception(ex)
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
def get_inputs_data(self):
|
|
101
|
+
try:
|
|
102
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_INPUTS])
|
|
28
103
|
|
|
29
104
|
if response.get('error'):
|
|
30
|
-
return {'success': False, 'Error': f'
|
|
105
|
+
return {'success': False, 'Error': f'InoDrive GetInputData Error: {str(response.get("error"))}'}
|
|
31
106
|
|
|
32
107
|
data = response['data'][0]
|
|
33
108
|
data.update({'success': True})
|
|
@@ -36,6 +111,18 @@ class IO(object):
|
|
|
36
111
|
except Exception as ex:
|
|
37
112
|
return {'success': False, 'error': str(ex)}
|
|
38
113
|
|
|
114
|
+
def get_accelerometer(self):
|
|
115
|
+
try:
|
|
116
|
+
data = self.get_inputs_data()
|
|
117
|
+
if data.get('error'):
|
|
118
|
+
logging.error(data['error'])
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
return {'x': data['g_forces'][0], 'y': data['g_forces'][1], 'z': data['g_forces'][2]}
|
|
122
|
+
except Exception as ex:
|
|
123
|
+
logging.exception(ex)
|
|
124
|
+
return None
|
|
125
|
+
|
|
39
126
|
def get_input(self, input=None):
|
|
40
127
|
try:
|
|
41
128
|
data = self.get_inputs_data()
|
|
@@ -129,6 +216,20 @@ class IO(object):
|
|
|
129
216
|
|
|
130
217
|
return None
|
|
131
218
|
|
|
219
|
+
def get_outputs_data(self):
|
|
220
|
+
try:
|
|
221
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_OUTPUTS])
|
|
222
|
+
|
|
223
|
+
if response.get('error'):
|
|
224
|
+
return {'success': False, 'Error': f'InoDrive GetOutputData Error: {str(response.get("error"))}'}
|
|
225
|
+
|
|
226
|
+
data = response['data'][0]
|
|
227
|
+
data.update({'success': True})
|
|
228
|
+
|
|
229
|
+
return data
|
|
230
|
+
except Exception as ex:
|
|
231
|
+
return {'success': False, 'error': str(ex)}
|
|
232
|
+
|
|
132
233
|
def set_output(self, target=None, state=None):
|
|
133
234
|
try:
|
|
134
235
|
if target == 'all' and state is not None:
|
|
@@ -8,7 +8,6 @@ class _MsgTypes(object):
|
|
|
8
8
|
IPv6 = 0x17
|
|
9
9
|
IPv6_CIDR = 0x18
|
|
10
10
|
NTP_TIME = 0x19
|
|
11
|
-
NTP_TIME = 0x19
|
|
12
11
|
PTP_TIME = 0x2a
|
|
13
12
|
RESERVED_TIME = 0x2b
|
|
14
13
|
MSG_PACK = 0x2c
|
|
@@ -33,6 +32,7 @@ class _MsgFile(object):
|
|
|
33
32
|
BACKUP_FW_TRANSFER = 0x203
|
|
34
33
|
TRANSFER = 0x204
|
|
35
34
|
LIST = 0x205
|
|
35
|
+
WEBPAGE_TRANSFER = 0x208
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
class _MsgSpecial(object):
|
|
@@ -76,11 +76,11 @@ class _MsgPack(object):
|
|
|
76
76
|
BEACON = 0x1
|
|
77
77
|
CONSOLE_ENABLE = 0x2
|
|
78
78
|
TAKE_CONTROL = 0x3
|
|
79
|
-
|
|
79
|
+
MODULE_INFO = 0x4
|
|
80
80
|
|
|
81
81
|
GET_INPUTS = 0x10
|
|
82
82
|
GET_OUTPUTS = 0x11
|
|
83
|
-
|
|
83
|
+
GET_METRICS = 0x12
|
|
84
84
|
LIST_VARIABLES = 0x16
|
|
85
85
|
ACCESS_VARIABLES = 0x17
|
|
86
86
|
|
|
@@ -99,6 +99,38 @@ class _MsgPackErrors(object):
|
|
|
99
99
|
NOT_ALLOWED = 0x6
|
|
100
100
|
|
|
101
101
|
|
|
102
|
+
class _OPState(object):
|
|
103
|
+
STATES = {
|
|
104
|
+
"invalid": 0,
|
|
105
|
+
"initializing": 1,
|
|
106
|
+
"initFailed": 2,
|
|
107
|
+
"faulted": 3,
|
|
108
|
+
"operational": 4,
|
|
109
|
+
|
|
110
|
+
"inFailSafeMode": 10,
|
|
111
|
+
"connectingToPeers": 11,
|
|
112
|
+
|
|
113
|
+
"motorNotConfigured": 20,
|
|
114
|
+
"motorDisabled": 21,
|
|
115
|
+
"motorI2tLimited": 22,
|
|
116
|
+
"motorInSto": 23,
|
|
117
|
+
"motorLimitSwitchActive": 24,
|
|
118
|
+
"motorHoldingBrakeFault": 25,
|
|
119
|
+
"motorStopped": 26,
|
|
120
|
+
"motorRunning": 27,
|
|
121
|
+
|
|
122
|
+
"externalControl": 40,
|
|
123
|
+
"uAppNotPresent": 41,
|
|
124
|
+
"uAppStartDelay": 42,
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
def get_state_by_value(self, state):
|
|
128
|
+
for key, value in self.STATES.items():
|
|
129
|
+
if state == value:
|
|
130
|
+
return key
|
|
131
|
+
return "invalid"
|
|
132
|
+
|
|
133
|
+
|
|
102
134
|
class _CkDefines(object):
|
|
103
135
|
NOP = 0x0
|
|
104
136
|
RESPONSE = 0x1
|
|
@@ -413,3 +445,4 @@ class _CkDefines(object):
|
|
|
413
445
|
|
|
414
446
|
|
|
415
447
|
CK = _CkDefines()
|
|
448
|
+
OP_STATE = _OPState()
|
|
@@ -220,10 +220,7 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
220
220
|
fw_type = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
221
221
|
data = data[item_size:]
|
|
222
222
|
|
|
223
|
-
firmware_flags =
|
|
224
|
-
'production': True if fw_type & (1 << 6) else False,
|
|
225
|
-
'failSafe': True if fw_type & (1 << 7) else False,
|
|
226
|
-
}
|
|
223
|
+
firmware_flags = Utils.get_firmware_flags(fw_type)
|
|
227
224
|
# =======================================================================
|
|
228
225
|
|
|
229
226
|
# Networking
|
|
@@ -251,31 +248,30 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
251
248
|
|
|
252
249
|
# PCB Version
|
|
253
250
|
# =======================================================================
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
'type': 0,
|
|
259
|
-
}
|
|
251
|
+
pcb_major = 1
|
|
252
|
+
pcb_minor = 1
|
|
253
|
+
pcb_build = 1
|
|
254
|
+
pcb_type = 0
|
|
260
255
|
|
|
261
256
|
if discover_version >= 2:
|
|
262
257
|
item_size = 1
|
|
263
|
-
|
|
258
|
+
pcb_major = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
264
259
|
data = data[item_size:]
|
|
265
260
|
|
|
266
261
|
item_size = 1
|
|
267
|
-
|
|
262
|
+
pcb_minor = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
268
263
|
data = data[item_size:]
|
|
269
264
|
|
|
270
265
|
item_size = 1
|
|
271
|
-
|
|
266
|
+
pcb_build = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
272
267
|
data = data[item_size:]
|
|
273
268
|
|
|
274
269
|
if discover_version >= 3:
|
|
275
270
|
item_size = 1
|
|
276
|
-
|
|
271
|
+
pcb_type = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
277
272
|
data = data[item_size:]
|
|
278
273
|
|
|
274
|
+
pcb_flags = Utils.get_pcb_flags(pcb_type)
|
|
279
275
|
# =======================================================================
|
|
280
276
|
|
|
281
277
|
except struct.error:
|
|
@@ -299,7 +295,8 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
299
295
|
'dns': dns,
|
|
300
296
|
'mac': mac_address,
|
|
301
297
|
},
|
|
302
|
-
'
|
|
298
|
+
'pcb': '.'.join([str(pcb_major), str(pcb_minor), str(pcb_build)]),
|
|
299
|
+
'pcbFlags': pcb_flags,
|
|
303
300
|
"netif": netif_ip_tuple[0]
|
|
304
301
|
}
|
|
305
302
|
modules_found[sn] = new_module_d
|
|
@@ -9,6 +9,9 @@ class DiscoverWs(object):
|
|
|
9
9
|
def __init__(self, **kwargs):
|
|
10
10
|
self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
|
|
11
11
|
|
|
12
|
+
def dispose(self):
|
|
13
|
+
return
|
|
14
|
+
|
|
12
15
|
def get_info(self):
|
|
13
16
|
try:
|
|
14
17
|
# Send request and wait for response
|
|
@@ -70,10 +73,7 @@ class DiscoverWs(object):
|
|
|
70
73
|
fw_type = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
71
74
|
data = data[item_size:]
|
|
72
75
|
|
|
73
|
-
firmware_flags =
|
|
74
|
-
'production': True if fw_type & (1 << 6) else False,
|
|
75
|
-
'failSafe': True if fw_type & (1 << 7) else False,
|
|
76
|
-
}
|
|
76
|
+
firmware_flags = Utils.get_firmware_flags(fw_type)
|
|
77
77
|
# =======================================================================
|
|
78
78
|
|
|
79
79
|
# Networking
|
|
@@ -101,31 +101,30 @@ class DiscoverWs(object):
|
|
|
101
101
|
|
|
102
102
|
# PCB Version
|
|
103
103
|
# =======================================================================
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
'type': 0,
|
|
109
|
-
}
|
|
104
|
+
pcb_major = 1
|
|
105
|
+
pcb_minor = 1
|
|
106
|
+
pcb_build = 1
|
|
107
|
+
pcb_type = 0
|
|
110
108
|
|
|
111
109
|
if discover_version >= 2:
|
|
112
110
|
item_size = 1
|
|
113
|
-
|
|
111
|
+
pcb_major = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
114
112
|
data = data[item_size:]
|
|
115
113
|
|
|
116
114
|
item_size = 1
|
|
117
|
-
|
|
115
|
+
pcb_minor = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
118
116
|
data = data[item_size:]
|
|
119
117
|
|
|
120
118
|
item_size = 1
|
|
121
|
-
|
|
119
|
+
pcb_build = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
122
120
|
data = data[item_size:]
|
|
123
121
|
|
|
124
122
|
if discover_version >= 3:
|
|
125
123
|
item_size = 1
|
|
126
|
-
|
|
124
|
+
pcb_type = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
127
125
|
data = data[item_size:]
|
|
128
126
|
|
|
127
|
+
pcb_flags = Utils.get_pcb_flags(pcb_type)
|
|
129
128
|
# =======================================================================
|
|
130
129
|
|
|
131
130
|
result = {
|
|
@@ -142,7 +141,8 @@ class DiscoverWs(object):
|
|
|
142
141
|
'dns': dns,
|
|
143
142
|
'mac': mac_address,
|
|
144
143
|
},
|
|
145
|
-
'
|
|
144
|
+
'pcb': '.'.join([str(pcb_major), str(pcb_minor), str(pcb_build)]),
|
|
145
|
+
'pcbFlags': pcb_flags
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
return result
|
|
@@ -10,6 +10,9 @@ class File(object):
|
|
|
10
10
|
def __init__(self, **kwargs):
|
|
11
11
|
self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
|
|
12
12
|
|
|
13
|
+
def dispose(self):
|
|
14
|
+
return
|
|
15
|
+
|
|
13
16
|
def read(self, files=None, transfer_type=None):
|
|
14
17
|
try:
|
|
15
18
|
if files is None:
|
|
@@ -159,7 +162,13 @@ class File(object):
|
|
|
159
162
|
|
|
160
163
|
def upload_firmware(self, content=None):
|
|
161
164
|
try:
|
|
162
|
-
return self.write({'path': "/firmware/firmware.
|
|
165
|
+
return self.write({'path': "/firmware/firmware.ckfw", 'content': content}, CK.FILE.FIRMWARE_TRANSFER)
|
|
166
|
+
except Exception as ex:
|
|
167
|
+
logging.exception(ex)
|
|
168
|
+
|
|
169
|
+
def upload_webpage(self, content=None):
|
|
170
|
+
try:
|
|
171
|
+
return self.write({'path': "web.bfb", 'content': content}, CK.FILE.WEBPAGE_TRANSFER)
|
|
163
172
|
except Exception as ex:
|
|
164
173
|
logging.exception(ex)
|
|
165
174
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import weakref
|
|
3
|
+
|
|
4
|
+
from .wsHandle import InoDriveWS
|
|
5
|
+
from .file import File
|
|
6
|
+
from .discoverWs import DiscoverWs
|
|
7
|
+
from .IO import IO
|
|
8
|
+
from .sysControl import SysControl
|
|
9
|
+
from .userApp import UserApp
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class InoDrive(object):
|
|
13
|
+
def __init__(self, **kwargs):
|
|
14
|
+
logging.debug('Create InoDrive instance...')
|
|
15
|
+
self._auto_connect = kwargs.get('autoConnect', False)
|
|
16
|
+
|
|
17
|
+
# ==============================================================================================================
|
|
18
|
+
# MODULES BEGIN
|
|
19
|
+
# ==============================================================================================================
|
|
20
|
+
self._connection_handle = InoDriveWS(**kwargs)
|
|
21
|
+
self.File = File(connection_handle=self._connection_handle, **kwargs)
|
|
22
|
+
self.Discover = DiscoverWs(connection_handle=self._connection_handle, **kwargs)
|
|
23
|
+
self.IO = IO(connection_handle=self._connection_handle, **kwargs)
|
|
24
|
+
self.SysControl = SysControl(connection_handle=self._connection_handle, **kwargs)
|
|
25
|
+
self.UserApp = UserApp(connection_handle=self._connection_handle, **kwargs)
|
|
26
|
+
# ==============================================================================================================
|
|
27
|
+
# MODULES END
|
|
28
|
+
# ==============================================================================================================
|
|
29
|
+
|
|
30
|
+
# ==============================================================================================================
|
|
31
|
+
# CONNECTION
|
|
32
|
+
# ==============================================================================================================
|
|
33
|
+
self.on = self._connection_handle.on
|
|
34
|
+
self.connected = self._connection_handle.connected
|
|
35
|
+
self.connect = self._connection_handle.connect
|
|
36
|
+
self.disconnect = self._connection_handle.disconnect
|
|
37
|
+
self.set_target = self._connection_handle.set_target
|
|
38
|
+
# ==============================================================================================================
|
|
39
|
+
# CONNECTION END
|
|
40
|
+
# ==============================================================================================================
|
|
41
|
+
|
|
42
|
+
# Finalizer weak reference to ensure InoDrive Object is cleaned up on code exit
|
|
43
|
+
self._finalizer = weakref.finalize(self, self.dispose)
|
|
44
|
+
|
|
45
|
+
if self._auto_connect:
|
|
46
|
+
self._connection_handle.connect()
|
|
47
|
+
|
|
48
|
+
def __del__(self):
|
|
49
|
+
self._finalizer()
|
|
50
|
+
|
|
51
|
+
def dispose(self):
|
|
52
|
+
if self.UserApp:
|
|
53
|
+
self.UserApp.dispose()
|
|
54
|
+
|
|
55
|
+
if self._connection_handle:
|
|
56
|
+
self._connection_handle.dispose()
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from .wsHandle import InoDriveWS
|
|
4
|
+
from .defines import CK
|
|
5
|
+
from .utils import Utils
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SysControl(object):
|
|
9
|
+
def __init__(self, **kwargs):
|
|
10
|
+
self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
|
|
11
|
+
|
|
12
|
+
def dispose(self):
|
|
13
|
+
return
|
|
14
|
+
|
|
15
|
+
def console_enable(self, state=False):
|
|
16
|
+
try:
|
|
17
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.CONSOLE_ENABLE, True if state else False])
|
|
18
|
+
|
|
19
|
+
if response.get('error'):
|
|
20
|
+
logging.error(f'InoDrive ConsoleEnable Error: {str(response)}')
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
return True
|
|
24
|
+
except Exception as ex:
|
|
25
|
+
logging.exception(ex)
|
|
26
|
+
|
|
27
|
+
def take_control(self, state=False):
|
|
28
|
+
try:
|
|
29
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.TAKE_CONTROL, True if state else False])
|
|
30
|
+
|
|
31
|
+
if response.get('error'):
|
|
32
|
+
logging.error(f'InoDrive TakeControl Error: {str(response)}')
|
|
33
|
+
return None
|
|
34
|
+
|
|
35
|
+
return True
|
|
36
|
+
except Exception as ex:
|
|
37
|
+
logging.exception(ex)
|
|
38
|
+
|
|
39
|
+
def get_module_info(self):
|
|
40
|
+
try:
|
|
41
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.MODULE_INFO])
|
|
42
|
+
|
|
43
|
+
if response.get('error'):
|
|
44
|
+
logging.error(f'InoDrive GetModuleInfo Error: {str(response)}')
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
data = response['data'][0]
|
|
48
|
+
|
|
49
|
+
# Firmware
|
|
50
|
+
if data.get('firmware'):
|
|
51
|
+
data['firmwareFlags'] = Utils.get_firmware_flags(data['firmware']['type'])
|
|
52
|
+
data['firmware'] = ".".join([
|
|
53
|
+
str(data['firmware']["major"]),
|
|
54
|
+
str(data['firmware']["minor"]),
|
|
55
|
+
str(data['firmware']["build"])
|
|
56
|
+
])
|
|
57
|
+
else:
|
|
58
|
+
data['firmwareFlags'] = Utils.get_firmware_flags(0)
|
|
59
|
+
data['firmware'] = "0.0.0"
|
|
60
|
+
|
|
61
|
+
# PCB
|
|
62
|
+
if data.get('pcb'):
|
|
63
|
+
data['pcbFlags'] = Utils.get_pcb_flags(data['pcb']['type'])
|
|
64
|
+
data['pcb'] = ".".join([
|
|
65
|
+
str(data['pcb']["major"]),
|
|
66
|
+
str(data['pcb']["minor"]),
|
|
67
|
+
str(data['pcb']["build"])
|
|
68
|
+
])
|
|
69
|
+
else:
|
|
70
|
+
data['pcbFlags'] = Utils.get_pcb_flags(0)
|
|
71
|
+
data['pcb'] = "1.1.1"
|
|
72
|
+
|
|
73
|
+
# Web
|
|
74
|
+
if data.get('web'):
|
|
75
|
+
data['webpage'] = data['web']['version']
|
|
76
|
+
else:
|
|
77
|
+
data['webpage'] = None
|
|
78
|
+
|
|
79
|
+
if 'web' in data:
|
|
80
|
+
del data['web']
|
|
81
|
+
|
|
82
|
+
# Failsafe Firmware
|
|
83
|
+
if data.get('failsafe_fw'):
|
|
84
|
+
data['fsFirmwareFlags'] = Utils.get_fs_firmware_flags(data['failsafe_fw']['type'])
|
|
85
|
+
data['fsFirmware'] = ".".join([
|
|
86
|
+
str(data['failsafe_fw']['major']),
|
|
87
|
+
str(data['failsafe_fw']['minor']),
|
|
88
|
+
str(data['failsafe_fw']['build'])
|
|
89
|
+
])
|
|
90
|
+
else:
|
|
91
|
+
data['fsFirmwareFlags'] = Utils.get_fs_firmware_flags(0)
|
|
92
|
+
data['fsFirmware'] = None
|
|
93
|
+
|
|
94
|
+
if 'failsafe_fw' in data:
|
|
95
|
+
del data['failsafe_fw']
|
|
96
|
+
|
|
97
|
+
return data
|
|
98
|
+
except Exception as ex:
|
|
99
|
+
logging.exception(ex)
|
|
100
|
+
|
|
101
|
+
return None
|
|
@@ -32,9 +32,6 @@ class UserApp(object):
|
|
|
32
32
|
self._program_id = None
|
|
33
33
|
self._ntp_poll_time = 0
|
|
34
34
|
|
|
35
|
-
def __del__(self):
|
|
36
|
-
self.dispose()
|
|
37
|
-
|
|
38
35
|
def dispose(self):
|
|
39
36
|
self.stop_poll()
|
|
40
37
|
|
|
@@ -87,7 +84,7 @@ class UserApp(object):
|
|
|
87
84
|
|
|
88
85
|
def get_variable_list(self, access=None):
|
|
89
86
|
try:
|
|
90
|
-
if self._connection_handle.connected and self._var_list_updated is False:
|
|
87
|
+
if self._connection_handle.connected() and self._var_list_updated is False:
|
|
91
88
|
self.update_variable_list()
|
|
92
89
|
|
|
93
90
|
var_list = []
|
|
@@ -188,7 +185,7 @@ class UserApp(object):
|
|
|
188
185
|
|
|
189
186
|
def read_var(self, argv=None, **kwargs):
|
|
190
187
|
try:
|
|
191
|
-
if self._connection_handle.connected and self._var_list_updated is False:
|
|
188
|
+
if self._connection_handle.connected() and self._var_list_updated is False:
|
|
192
189
|
self.update_variable_list()
|
|
193
190
|
|
|
194
191
|
var_list = []
|
|
@@ -254,7 +251,7 @@ class UserApp(object):
|
|
|
254
251
|
|
|
255
252
|
def write_var(self, argv=None, value=None, **kwarg):
|
|
256
253
|
try:
|
|
257
|
-
if self._connection_handle.connected and self._var_list_updated is False:
|
|
254
|
+
if self._connection_handle.connected() and self._var_list_updated is False:
|
|
258
255
|
self.update_variable_list()
|
|
259
256
|
|
|
260
257
|
var_dict = {}
|