CK-InoDrive-API 1.0.0__tar.gz → 1.0.2__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-1.0.0 → ck_inodrive_api-1.0.2}/CK_InoDrive_API.egg-info/PKG-INFO +18 -4
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CK_InoDrive_API.egg-info/SOURCES.txt +2 -0
- ck_inodrive_api-1.0.2/CK_InoDrive_API.egg-info/requires.txt +4 -0
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/IO.py +11 -11
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/__init__.py +1 -0
- ck_inodrive_api-1.0.2/CkInoDriveAPI/_version.py +17 -0
- ck_inodrive_api-1.0.2/CkInoDriveAPI/callback.py +87 -0
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/defines.py +15 -1
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/discoverLan.py +23 -11
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/discoverWs.py +2 -2
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/file.py +41 -28
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/inoDrive.py +54 -36
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/sysControl.py +21 -5
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/userApp.py +140 -42
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/utils.py +48 -15
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/wsHandle.py +125 -62
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/PKG-INFO +18 -4
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/README.txt +120 -45
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/setup.py +28 -9
- ck_inodrive_api-1.0.0/CK_InoDrive_API.egg-info/requires.txt +0 -3
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CK_InoDrive_API.egg-info/dependency_links.txt +0 -0
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CK_InoDrive_API.egg-info/top_level.txt +0 -0
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/CkInoDriveAPI/ck_ca.crt +0 -0
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/LICENSE.txt +0 -0
- {ck_inodrive_api-1.0.0 → ck_inodrive_api-1.0.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: CK-InoDrive-API
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: InoDrive API Library
|
|
5
5
|
Home-page: https://cardinalkinetic.com
|
|
6
6
|
Author: Cardinal Kinetic
|
|
@@ -15,12 +15,26 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
19
|
Description-Content-Type: text/markdown
|
|
19
20
|
License-File: LICENSE.txt
|
|
20
21
|
License-File: README.txt
|
|
21
|
-
Requires-Dist: websocket-client==1.
|
|
22
|
+
Requires-Dist: websocket-client==1.9.0
|
|
22
23
|
Requires-Dist: ifaddr==0.2.0
|
|
23
|
-
Requires-Dist: msgpack==1.
|
|
24
|
+
Requires-Dist: msgpack==1.1.2
|
|
25
|
+
Requires-Dist: getmac==0.9.5
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: description
|
|
30
|
+
Dynamic: description-content-type
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: keywords
|
|
33
|
+
Dynamic: license
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
Dynamic: project-url
|
|
36
|
+
Dynamic: requires-dist
|
|
37
|
+
Dynamic: summary
|
|
24
38
|
|
|
25
39
|
#### **Installation**
|
|
26
40
|
|
|
@@ -8,6 +8,8 @@ CK_InoDrive_API.egg-info/requires.txt
|
|
|
8
8
|
CK_InoDrive_API.egg-info/top_level.txt
|
|
9
9
|
CkInoDriveAPI/IO.py
|
|
10
10
|
CkInoDriveAPI/__init__.py
|
|
11
|
+
CkInoDriveAPI/_version.py
|
|
12
|
+
CkInoDriveAPI/callback.py
|
|
11
13
|
CkInoDriveAPI/ck_ca.crt
|
|
12
14
|
CkInoDriveAPI/defines.py
|
|
13
15
|
CkInoDriveAPI/discoverLan.py
|
|
@@ -6,7 +6,7 @@ from .defines import OP_STATE
|
|
|
6
6
|
|
|
7
7
|
class IO(object):
|
|
8
8
|
def __init__(self, **kwargs):
|
|
9
|
-
self._get_connection_handle = kwargs.get('
|
|
9
|
+
self._get_connection_handle = kwargs.get('getConnectionHandle')
|
|
10
10
|
|
|
11
11
|
@property
|
|
12
12
|
def _connection_handle(self):
|
|
@@ -20,7 +20,7 @@ class IO(object):
|
|
|
20
20
|
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_METRICS])
|
|
21
21
|
|
|
22
22
|
if response.get('error'):
|
|
23
|
-
return {'success': False, 'Error': f
|
|
23
|
+
return {'success': False, 'Error': f"InoDrive GetMetrics Error: {str(response.get('error'))}"}
|
|
24
24
|
|
|
25
25
|
data = response['data'][0]
|
|
26
26
|
|
|
@@ -105,7 +105,7 @@ class IO(object):
|
|
|
105
105
|
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_INPUTS])
|
|
106
106
|
|
|
107
107
|
if response.get('error'):
|
|
108
|
-
return {'success': False, 'Error': f
|
|
108
|
+
return {'success': False, 'Error': f"InoDrive GetInputData Error: {str(response.get('error'))}"}
|
|
109
109
|
|
|
110
110
|
data = response['data'][0]
|
|
111
111
|
data.update({'success': True})
|
|
@@ -188,13 +188,13 @@ class IO(object):
|
|
|
188
188
|
else:
|
|
189
189
|
state = 0x1 if state else 0x0
|
|
190
190
|
else:
|
|
191
|
-
logging.error(f
|
|
191
|
+
logging.error(f"InoDrive SetInputPolarity Error: target or state not supported...")
|
|
192
192
|
return None
|
|
193
193
|
|
|
194
194
|
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_INPUT_POLARITY, target, state])
|
|
195
195
|
|
|
196
196
|
if response.get('error'):
|
|
197
|
-
logging.error(f
|
|
197
|
+
logging.error(f"InoDrive SetInputPolarity Error: {str(response)}")
|
|
198
198
|
return None
|
|
199
199
|
|
|
200
200
|
return True
|
|
@@ -224,7 +224,7 @@ class IO(object):
|
|
|
224
224
|
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_OUTPUTS])
|
|
225
225
|
|
|
226
226
|
if response.get('error'):
|
|
227
|
-
return {'success': False, 'Error': f
|
|
227
|
+
return {'success': False, 'Error': f"InoDrive GetOutputData Error: {str(response.get('error'))}"}
|
|
228
228
|
|
|
229
229
|
data = response['data'][0]
|
|
230
230
|
data.update({'success': True})
|
|
@@ -243,14 +243,14 @@ class IO(object):
|
|
|
243
243
|
elif type(target) is int and 0 <= target <= 2 and state is not None:
|
|
244
244
|
state = 0x1 if state else 0x0
|
|
245
245
|
else:
|
|
246
|
-
logging.error(f
|
|
246
|
+
logging.error(f"InoDrive SetOutput Error: target os state not supported...")
|
|
247
247
|
return None
|
|
248
248
|
|
|
249
249
|
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_OUTPUTS, target, state])
|
|
250
250
|
|
|
251
251
|
if response.get('error'):
|
|
252
|
-
logging.error(f
|
|
253
|
-
return
|
|
252
|
+
logging.error(f"InoDrive SetOutput Error: {str(response)}")
|
|
253
|
+
return False
|
|
254
254
|
|
|
255
255
|
return True
|
|
256
256
|
except Exception as ex:
|
|
@@ -300,8 +300,8 @@ class IO(object):
|
|
|
300
300
|
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_HOLDING_BRAKE, True if state else False])
|
|
301
301
|
|
|
302
302
|
if response.get('error'):
|
|
303
|
-
logging.error(f
|
|
304
|
-
return
|
|
303
|
+
logging.error(f"InoDrive SetHoldingBrake Error: {str(response)}")
|
|
304
|
+
return False
|
|
305
305
|
|
|
306
306
|
return True
|
|
307
307
|
except Exception as ex:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import sys
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_version_number():
|
|
7
|
+
try:
|
|
8
|
+
dir_path = str(Path(os.path.dirname(__file__)).parent)
|
|
9
|
+
sys.path.append(dir_path)
|
|
10
|
+
|
|
11
|
+
from versions import get_latest_number
|
|
12
|
+
version = get_latest_number()
|
|
13
|
+
except ImportError:
|
|
14
|
+
from .__init__ import __version__
|
|
15
|
+
version = __version__
|
|
16
|
+
|
|
17
|
+
return version
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Callback(object):
|
|
5
|
+
_context = None
|
|
6
|
+
_callbacks = {}
|
|
7
|
+
|
|
8
|
+
def __init__(self, **kwargs):
|
|
9
|
+
self._context = kwargs.get('context', self)
|
|
10
|
+
|
|
11
|
+
def on(self, name=None, func=None):
|
|
12
|
+
try:
|
|
13
|
+
callbacks = {}
|
|
14
|
+
|
|
15
|
+
if type(name) is dict:
|
|
16
|
+
callbacks = name
|
|
17
|
+
elif type(name) is str and callable(func):
|
|
18
|
+
callbacks[name] = func
|
|
19
|
+
else:
|
|
20
|
+
return
|
|
21
|
+
|
|
22
|
+
for callback_name, callback_function in callbacks.items():
|
|
23
|
+
if type(callback_name) is not str:
|
|
24
|
+
continue
|
|
25
|
+
|
|
26
|
+
if not callable(callback_function):
|
|
27
|
+
continue
|
|
28
|
+
|
|
29
|
+
if callback_name not in self._callbacks:
|
|
30
|
+
# Callback does not exist
|
|
31
|
+
self._callbacks[callback_name] = [callback_function]
|
|
32
|
+
continue
|
|
33
|
+
|
|
34
|
+
if callback_function not in self._callbacks[callback_name]:
|
|
35
|
+
# Function is not in callback group
|
|
36
|
+
self._callbacks[callback_name].append(callback_function)
|
|
37
|
+
continue
|
|
38
|
+
|
|
39
|
+
except Exception as ex:
|
|
40
|
+
logging.exception(ex)
|
|
41
|
+
|
|
42
|
+
def remove(self, name=None, func=None):
|
|
43
|
+
try:
|
|
44
|
+
if type(name) is not str:
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
if not callable(func):
|
|
48
|
+
return
|
|
49
|
+
|
|
50
|
+
if self._callbacks[name] and func in self._callbacks[name]:
|
|
51
|
+
# Function exist so we need to remove it - removing callback.
|
|
52
|
+
self._callbacks[name].pop(self._callbacks[name].index(func))
|
|
53
|
+
|
|
54
|
+
if len(self._callbacks[name]) == 0:
|
|
55
|
+
# There are no more functions in the group - remove the group
|
|
56
|
+
del self._callbacks[name]
|
|
57
|
+
|
|
58
|
+
except Exception as ex:
|
|
59
|
+
logging.exception(ex)
|
|
60
|
+
|
|
61
|
+
def dispatch(self, callback_name=None, *args):
|
|
62
|
+
try:
|
|
63
|
+
# Get call back group
|
|
64
|
+
if callback_name in self._callbacks:
|
|
65
|
+
callbacks = self._callbacks[callback_name]
|
|
66
|
+
if callbacks is not None:
|
|
67
|
+
for callback in callbacks:
|
|
68
|
+
# Call each callback
|
|
69
|
+
if callable(callback):
|
|
70
|
+
callback(*args)
|
|
71
|
+
|
|
72
|
+
except Exception as ex:
|
|
73
|
+
logging.exception(ex)
|
|
74
|
+
|
|
75
|
+
def dispatch_with_context(self, context=None, callback_name=None, *args):
|
|
76
|
+
try:
|
|
77
|
+
# Get call back group
|
|
78
|
+
if callback_name in self._callbacks:
|
|
79
|
+
callbacks = self._callbacks[callback_name]
|
|
80
|
+
if callbacks is not None:
|
|
81
|
+
for callback in callbacks:
|
|
82
|
+
# Call each callback
|
|
83
|
+
if callable(callback):
|
|
84
|
+
callback(context, *args)
|
|
85
|
+
|
|
86
|
+
except Exception as ex:
|
|
87
|
+
logging.exception(ex)
|
|
@@ -83,6 +83,7 @@ class _MsgPack(object):
|
|
|
83
83
|
GET_METRICS = 0x12
|
|
84
84
|
LIST_VARIABLES = 0x16
|
|
85
85
|
ACCESS_VARIABLES = 0x17
|
|
86
|
+
RPC_SET_FLAG = 0x18
|
|
86
87
|
|
|
87
88
|
SET_INPUT_POLARITY = 0x20
|
|
88
89
|
SET_OUTPUTS = 0x21
|
|
@@ -98,6 +99,18 @@ class _MsgPackErrors(object):
|
|
|
98
99
|
NOT_IMPLEMENTED = 0x5
|
|
99
100
|
NOT_ALLOWED = 0x6
|
|
100
101
|
|
|
102
|
+
class _RPCDefines(object):
|
|
103
|
+
PEER_READY = 0x0
|
|
104
|
+
PEER_NOT_READY = 0x1
|
|
105
|
+
|
|
106
|
+
class _ConsoleMsgTypes(object):
|
|
107
|
+
TYPES = {
|
|
108
|
+
0: "trace",
|
|
109
|
+
1: "info",
|
|
110
|
+
2: "notice",
|
|
111
|
+
3: "warning",
|
|
112
|
+
4: "error"
|
|
113
|
+
}
|
|
101
114
|
|
|
102
115
|
class _OPState(object):
|
|
103
116
|
STATES = {
|
|
@@ -172,7 +185,6 @@ class _CkDefines(object):
|
|
|
172
185
|
'counter': {'type': 12, 'size': 0},
|
|
173
186
|
}
|
|
174
187
|
|
|
175
|
-
|
|
176
188
|
# MessageTypes = _MsgDefines()
|
|
177
189
|
#
|
|
178
190
|
#
|
|
@@ -446,3 +458,5 @@ class _CkDefines(object):
|
|
|
446
458
|
|
|
447
459
|
CK = _CkDefines()
|
|
448
460
|
OP_STATE = _OPState()
|
|
461
|
+
consoleMsgTypes = _ConsoleMsgTypes()
|
|
462
|
+
RPC_FLAGS = _RPCDefines()
|
|
@@ -14,6 +14,7 @@ SMEEX_UDP_WELL_KNOWN_PORT = 17737
|
|
|
14
14
|
def _get_network_interfaces_using_ifaddr(one_ip_per_adapter=False):
|
|
15
15
|
logging.info("List interfaces with ifaddr...")
|
|
16
16
|
netif_ip_list = []
|
|
17
|
+
|
|
17
18
|
try:
|
|
18
19
|
import ifaddr
|
|
19
20
|
except Exception as ex:
|
|
@@ -21,17 +22,25 @@ def _get_network_interfaces_using_ifaddr(one_ip_per_adapter=False):
|
|
|
21
22
|
logging.error("Error, module 'ifaddr' not installed.")
|
|
22
23
|
return None
|
|
23
24
|
|
|
25
|
+
try:
|
|
26
|
+
import getmac
|
|
27
|
+
except Exception as ex:
|
|
28
|
+
print("Error, module 'getmac' not installed.")
|
|
29
|
+
logging.error("Error, module 'getmac' not installed.")
|
|
30
|
+
return None
|
|
31
|
+
|
|
24
32
|
adapters = ifaddr.get_adapters()
|
|
25
33
|
logging.info("Found %d interfaces" % len(adapters))
|
|
26
34
|
for adapter in adapters:
|
|
27
35
|
ipv4_address_found = False
|
|
28
36
|
print("IPs of network adapter ", adapter.nice_name)
|
|
29
37
|
for ip in adapter.ips:
|
|
30
|
-
if ip.ip.count(
|
|
38
|
+
if ip.ip.count(".") != 3:
|
|
31
39
|
continue
|
|
32
40
|
ipv4_address_found = True
|
|
33
41
|
logging.info("--> " + str(ip.ip) + "/" + str(ip.network_prefix))
|
|
34
|
-
|
|
42
|
+
mac = getmac.get_mac_address(interface=ip.nice_name)
|
|
43
|
+
result = (adapter, ip.ip, mac)
|
|
35
44
|
netif_ip_list.append(result)
|
|
36
45
|
if one_ip_per_adapter:
|
|
37
46
|
break
|
|
@@ -42,8 +51,10 @@ def _get_network_interfaces_using_ifaddr(one_ip_per_adapter=False):
|
|
|
42
51
|
return netif_ip_list
|
|
43
52
|
|
|
44
53
|
|
|
45
|
-
def _discover_modules_on_netif(
|
|
46
|
-
|
|
54
|
+
def _discover_modules_on_netif(
|
|
55
|
+
netif_ip_tuple, num_attempts=1, per_attempt_timeout=0.5, ma_sleep_min=0.2, ma_sleep_max=0.5
|
|
56
|
+
):
|
|
57
|
+
"""Discover modules on the network interface with the specified IP address."""
|
|
47
58
|
modules_found = {}
|
|
48
59
|
|
|
49
60
|
# Apply a sensible minimum to the timeout
|
|
@@ -60,7 +71,7 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
60
71
|
local_listen_port = 0
|
|
61
72
|
# I could not get consistently good results with properly calculated size, so just use a big number.
|
|
62
73
|
# Plan for around 300 bytes MINIMUM per module, especially on a CPU constrained system.
|
|
63
|
-
recv_buf_size =
|
|
74
|
+
recv_buf_size = 1000 * 500 # 500k/0.1s-OK, 100k/0.1s-OK
|
|
64
75
|
# Just a safety limit to prevent run-away memory allocation. We should never see 1000 responses, let alone more
|
|
65
76
|
# Do not set this too low though because on Windows, if all modules respond with broadcasts, our internal list
|
|
66
77
|
# will hold all responses twice.
|
|
@@ -101,7 +112,7 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
101
112
|
# Bind to the wildcard address and the same port number as the first socket.
|
|
102
113
|
# Under Linux, this allows us to collect responses sent to 255.255.255.255 which we would not get
|
|
103
114
|
# through the original socket.
|
|
104
|
-
bcast_sock.bind((
|
|
115
|
+
bcast_sock.bind(("", local_listen_port))
|
|
105
116
|
except Exception as exc:
|
|
106
117
|
logging.error(type(exc).__name__)
|
|
107
118
|
# Logger.log(logging.DEBUG, exc.__class__.__name__)
|
|
@@ -126,9 +137,9 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
126
137
|
svc_name = "Identity"
|
|
127
138
|
svc_name_len = min(16, len(svc_name))
|
|
128
139
|
padding = 16 - svc_name_len
|
|
129
|
-
payload = struct.pack(">BII", 0x05, my_session_id, 0) + bytes("Identity",
|
|
140
|
+
payload = struct.pack(">BII", 0x05, my_session_id, 0) + bytes("Identity", "ascii") + bytearray(padding)
|
|
130
141
|
# Send it to 255.255.255.255
|
|
131
|
-
send_sock.sendto(payload, (
|
|
142
|
+
send_sock.sendto(payload, ("<broadcast>", SMEEX_UDP_WELL_KNOWN_PORT))
|
|
132
143
|
|
|
133
144
|
internal_list_full = False
|
|
134
145
|
while not internal_list_full:
|
|
@@ -178,8 +189,9 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
178
189
|
sn = None
|
|
179
190
|
|
|
180
191
|
if module_object is not None:
|
|
181
|
-
module_object[
|
|
182
|
-
|
|
192
|
+
module_object["netif"] = netif_ip_tuple[0]
|
|
193
|
+
module_object["netifMac"] = netif_ip_tuple[2]
|
|
194
|
+
sn = module_object["sn"]
|
|
183
195
|
|
|
184
196
|
except struct.error:
|
|
185
197
|
continue
|
|
@@ -228,5 +240,5 @@ def id_discover_lan(net_adapter_ip=None, num_attempts=2):
|
|
|
228
240
|
|
|
229
241
|
# Return a stripped down version of the dictionary because the serial number key is no longer needed.
|
|
230
242
|
results = list(all_modules_on_all_ifs.values())
|
|
231
|
-
logging.info(f
|
|
243
|
+
logging.info(f"Total modules found: {len(results)}")
|
|
232
244
|
return results
|
|
@@ -6,7 +6,7 @@ from .utils import Utils
|
|
|
6
6
|
|
|
7
7
|
class DiscoverWs(object):
|
|
8
8
|
def __init__(self, **kwargs):
|
|
9
|
-
self._get_connection_handle = kwargs.get('
|
|
9
|
+
self._get_connection_handle = kwargs.get('getConnectionHandle')
|
|
10
10
|
|
|
11
11
|
@property
|
|
12
12
|
def _connection_handle(self):
|
|
@@ -21,7 +21,7 @@ class DiscoverWs(object):
|
|
|
21
21
|
resp = self._connection_handle.request(Utils.get_tlv(CK.SPECIAL.GET_DISCOVER_INFO))
|
|
22
22
|
|
|
23
23
|
if resp.get('error'):
|
|
24
|
-
logging.error(f
|
|
24
|
+
logging.error(f"Retrieving discover info failed...")
|
|
25
25
|
return None
|
|
26
26
|
|
|
27
27
|
result = None
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import base64
|
|
2
3
|
import logging
|
|
3
4
|
|
|
4
5
|
from .defines import CK
|
|
@@ -7,7 +8,7 @@ from .utils import Utils
|
|
|
7
8
|
|
|
8
9
|
class File(object):
|
|
9
10
|
def __init__(self, **kwargs):
|
|
10
|
-
self._get_connection_handle = kwargs.get('
|
|
11
|
+
self._get_connection_handle = kwargs.get('getConnectionHandle')
|
|
11
12
|
|
|
12
13
|
@property
|
|
13
14
|
def _connection_handle(self):
|
|
@@ -16,10 +17,10 @@ class File(object):
|
|
|
16
17
|
def dispose(self):
|
|
17
18
|
return
|
|
18
19
|
|
|
19
|
-
def read(self, files=None, transfer_type=None):
|
|
20
|
+
def read(self, files=None, transfer_type=None, props={}):
|
|
20
21
|
try:
|
|
21
22
|
if files is None:
|
|
22
|
-
logging.error(f
|
|
23
|
+
logging.error(f"Files is None...")
|
|
23
24
|
return None
|
|
24
25
|
|
|
25
26
|
if type(files) is not list:
|
|
@@ -32,14 +33,14 @@ class File(object):
|
|
|
32
33
|
|
|
33
34
|
for file in files:
|
|
34
35
|
if type(file) is not dict:
|
|
35
|
-
logging.error(f
|
|
36
|
+
logging.error(f"File is not a dict...")
|
|
36
37
|
return None
|
|
37
38
|
|
|
38
39
|
file_path = file.get('path')
|
|
39
40
|
content = file.get('content', 'bytes')
|
|
40
41
|
|
|
41
42
|
if type(file_path) is not str:
|
|
42
|
-
logging.error(f
|
|
43
|
+
logging.error(f"File path is not a string...")
|
|
43
44
|
return None
|
|
44
45
|
|
|
45
46
|
file_path = file_path.replace('\\', '/')
|
|
@@ -48,7 +49,7 @@ class File(object):
|
|
|
48
49
|
file_path = file_path[1:]
|
|
49
50
|
|
|
50
51
|
if file_path[0] != '/':
|
|
51
|
-
file_path = f
|
|
52
|
+
file_path = f"/{file_path}"
|
|
52
53
|
|
|
53
54
|
file_path = file_path.replace('\\', '/')
|
|
54
55
|
|
|
@@ -58,7 +59,7 @@ class File(object):
|
|
|
58
59
|
# Add file path TLV to the message
|
|
59
60
|
msg += Utils.get_tlv(CK.TYPE.STRING, file_path)
|
|
60
61
|
|
|
61
|
-
response = self._connection_handle.request(msg)
|
|
62
|
+
response = self._connection_handle.request(msg, props)
|
|
62
63
|
if response.get('error'):
|
|
63
64
|
logging.error('File read error...')
|
|
64
65
|
return None
|
|
@@ -80,10 +81,10 @@ class File(object):
|
|
|
80
81
|
|
|
81
82
|
return None
|
|
82
83
|
|
|
83
|
-
def write(self, files=None, transfer_type=None):
|
|
84
|
+
def write(self, files=None, transfer_type=None, props={}):
|
|
84
85
|
try:
|
|
85
86
|
if files is None:
|
|
86
|
-
logging.error(
|
|
87
|
+
logging.error("Files not provided...")
|
|
87
88
|
return False
|
|
88
89
|
|
|
89
90
|
if type(files) is not list:
|
|
@@ -94,7 +95,7 @@ class File(object):
|
|
|
94
95
|
|
|
95
96
|
for file in files:
|
|
96
97
|
if type(file) is not dict:
|
|
97
|
-
logging.error(f
|
|
98
|
+
logging.error(f"File is not a dict...")
|
|
98
99
|
return False
|
|
99
100
|
|
|
100
101
|
file_path = file.get('path')
|
|
@@ -104,8 +105,8 @@ class File(object):
|
|
|
104
105
|
if file_path[0] == '.':
|
|
105
106
|
file_path = file_path[1:]
|
|
106
107
|
|
|
107
|
-
if file_path[0] != '/':
|
|
108
|
-
file_path = f
|
|
108
|
+
if transfer_type != CK.FILE.WEBPAGE_TRANSFER and file_path[0] != '/':
|
|
109
|
+
file_path = f"/{file_path}"
|
|
109
110
|
|
|
110
111
|
file_path = file_path.replace('\\', '/')
|
|
111
112
|
|
|
@@ -118,7 +119,7 @@ class File(object):
|
|
|
118
119
|
file_content = bytes(file_content, 'utf-8')
|
|
119
120
|
|
|
120
121
|
if file_content is None or type(file_content) is not bytes:
|
|
121
|
-
logging.error(f
|
|
122
|
+
logging.error(f"File data is not bytes...")
|
|
122
123
|
return False
|
|
123
124
|
|
|
124
125
|
msg = b''
|
|
@@ -130,10 +131,10 @@ class File(object):
|
|
|
130
131
|
msg += Utils.get_tlv(CK.TYPE.BLOB, file_content)
|
|
131
132
|
|
|
132
133
|
# Send request and wait for response
|
|
133
|
-
resp = self._connection_handle.request(msg)
|
|
134
|
+
resp = self._connection_handle.request(msg, props)
|
|
134
135
|
|
|
135
136
|
if resp.get('error'):
|
|
136
|
-
logging.error(f
|
|
137
|
+
logging.error(f"File [{file_path}] write error: {resp.get('error')}")
|
|
137
138
|
return False
|
|
138
139
|
|
|
139
140
|
return True
|
|
@@ -142,13 +143,13 @@ class File(object):
|
|
|
142
143
|
|
|
143
144
|
return False
|
|
144
145
|
|
|
145
|
-
def delete_uapp(self):
|
|
146
|
+
def delete_uapp(self, props={}):
|
|
146
147
|
try:
|
|
147
148
|
# Send request and wait for response
|
|
148
|
-
resp = self._connection_handle.request(Utils.get_tlv(CK.SPECIAL.DELETE_UAPP))
|
|
149
|
+
resp = self._connection_handle.request(Utils.get_tlv(CK.SPECIAL.DELETE_UAPP), props)
|
|
149
150
|
|
|
150
151
|
if resp.get('error'):
|
|
151
|
-
logging.error(f
|
|
152
|
+
logging.error(f"Deleting User Application failed...")
|
|
152
153
|
return False
|
|
153
154
|
|
|
154
155
|
return True
|
|
@@ -157,36 +158,48 @@ class File(object):
|
|
|
157
158
|
|
|
158
159
|
return False
|
|
159
160
|
|
|
160
|
-
def upload_user_app(self, content=None):
|
|
161
|
+
def upload_user_app(self, content=None, props={}):
|
|
161
162
|
try:
|
|
162
|
-
|
|
163
|
+
if type(content) is str:
|
|
164
|
+
content = base64.b64decode(content)
|
|
165
|
+
|
|
166
|
+
return self.write([{'path': "/uapp/application.idsol", 'content': content}], CK.FILE.UAPP_TRANSFER, props)
|
|
163
167
|
except Exception as ex:
|
|
164
168
|
logging.exception(ex)
|
|
165
169
|
|
|
166
|
-
def upload_firmware(self, content=None):
|
|
170
|
+
def upload_firmware(self, content=None, props={}):
|
|
167
171
|
try:
|
|
168
|
-
|
|
172
|
+
if type(content) is str:
|
|
173
|
+
content = base64.b64decode(content)
|
|
174
|
+
|
|
175
|
+
return self.write([{'path': "/firmware/firmware.ckfw", 'content': content}], CK.FILE.FIRMWARE_TRANSFER, props)
|
|
169
176
|
except Exception as ex:
|
|
170
177
|
logging.exception(ex)
|
|
171
178
|
|
|
172
|
-
def
|
|
179
|
+
def upload_web_content(self, file_name=None, content=None, props={}):
|
|
173
180
|
try:
|
|
174
|
-
|
|
181
|
+
if type(content) is str:
|
|
182
|
+
content = base64.b64decode(content)
|
|
183
|
+
|
|
184
|
+
if type(file_name) is not str:
|
|
185
|
+
file_name = "web.bfb"
|
|
186
|
+
|
|
187
|
+
return self.write([{'path': file_name, 'content': content}], CK.FILE.WEBPAGE_TRANSFER, props)
|
|
175
188
|
except Exception as ex:
|
|
176
189
|
logging.exception(ex)
|
|
177
190
|
|
|
178
|
-
def read_module_config(self):
|
|
191
|
+
def read_module_config(self, props={}):
|
|
179
192
|
try:
|
|
180
|
-
return self.read({'path': '/config/module_cfg.json', 'content': 'json'})
|
|
193
|
+
return self.read({'path': '/config/module_cfg.json', 'content': 'json'}, props)
|
|
181
194
|
except Exception as ex:
|
|
182
195
|
logging.exception(ex)
|
|
183
196
|
|
|
184
|
-
def write_module_config(self, content=None):
|
|
197
|
+
def write_module_config(self, content=None, props={}):
|
|
185
198
|
try:
|
|
186
199
|
if type(content) is not dict:
|
|
187
200
|
logging.error('Content type is not dictionary')
|
|
188
201
|
return False
|
|
189
202
|
|
|
190
|
-
return self.write({'path': '/config/module_cfg.json', 'content': content})
|
|
203
|
+
return self.write({'path': '/config/module_cfg.json', 'content': content}, CK.FILE.TRANSFER, props)
|
|
191
204
|
except Exception as ex:
|
|
192
205
|
logging.exception(ex)
|