solax-py-library 1.0.0.15__py3-none-any.whl → 1.0.0.16__py3-none-any.whl
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.
- solax_py_library/__init__.py +1 -1
- solax_py_library/snap_shot/__init__.py +4 -4
- solax_py_library/snap_shot/address.py +299 -67
- solax_py_library/snap_shot/base_modbus.py +14 -14
- solax_py_library/snap_shot/core.py +249 -219
- solax_py_library/snap_shot/exceptions.py +6 -4
- solax_py_library/snap_shot/parser.py +226 -224
- solax_py_library/snap_shot/untils.py +20 -17
- solax_py_library/upload/__init__.py +3 -3
- solax_py_library/upload/api/__init__.py +3 -3
- solax_py_library/upload/api/service.py +24 -24
- solax_py_library/upload/core/__init__.py +3 -3
- solax_py_library/upload/core/data_adapter/__init__.py +5 -5
- solax_py_library/upload/core/data_adapter/base.py +9 -9
- solax_py_library/upload/core/data_adapter/csv.py +26 -26
- solax_py_library/upload/core/upload_service/__init__.py +15 -15
- solax_py_library/upload/core/upload_service/base.py +43 -43
- solax_py_library/upload/core/upload_service/ftp.py +97 -86
- solax_py_library/upload/errors/__init__.py +10 -10
- solax_py_library/upload/errors/base.py +10 -10
- solax_py_library/upload/errors/upload_error.py +21 -21
- solax_py_library/upload/test/test_ftp.py +81 -40
- solax_py_library/upload/types/__init__.py +11 -11
- solax_py_library/upload/types/client.py +19 -19
- solax_py_library/upload/types/ftp.py +37 -37
- {solax_py_library-1.0.0.15.dist-info → solax_py_library-1.0.0.16.dist-info}/METADATA +4 -4
- solax_py_library-1.0.0.16.dist-info/RECORD +29 -0
- {solax_py_library-1.0.0.15.dist-info → solax_py_library-1.0.0.16.dist-info}/WHEEL +1 -1
- solax_py_library-1.0.0.15.dist-info/RECORD +0 -29
@@ -1,219 +1,249 @@
|
|
1
|
-
from typing import Dict, Optional, List
|
2
|
-
import asyncio
|
3
|
-
|
4
|
-
from .base_modbus import ModbusClientBase
|
5
|
-
from .address import *
|
6
|
-
from .untils import retry
|
7
|
-
|
8
|
-
|
9
|
-
class SnapshotCore:
|
10
|
-
def __init__(self, modbus_client: ModbusClientBase, snap_except=None):
|
11
|
-
self.modbus = modbus_client
|
12
|
-
self.all_snap_shot_data: Dict[int, List[int]] = {}
|
13
|
-
self.snap_except = snap_except
|
14
|
-
|
15
|
-
def __getitem__(self, index: int) -> Optional[List[int]]:
|
16
|
-
return self.all_snap_shot_data.get(index)
|
17
|
-
|
18
|
-
async def __aiter__(self):
|
19
|
-
for key in self.all_snap_shot_data:
|
20
|
-
yield key, self.all_snap_shot_data[key]
|
21
|
-
|
22
|
-
@property
|
23
|
-
def all_snap_data(self):
|
24
|
-
return self.all_snap_shot_data.copy()
|
25
|
-
|
26
|
-
@retry(max_attempts=3, delay=0.5)
|
27
|
-
async def _set_MCU_source(self):
|
28
|
-
print("step 1 设置芯片源")
|
29
|
-
result = await self.modbus.write_registers(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
print("
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
result
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_START.value,
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
return result
|
88
|
-
|
89
|
-
@retry(max_attempts=3, delay=0.5)
|
90
|
-
async def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
await self.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
@retry(max_attempts=
|
140
|
-
async def
|
141
|
-
# print(f'
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
# print(f'
|
167
|
-
return
|
168
|
-
|
169
|
-
@retry(max_attempts=3, delay=0.5)
|
170
|
-
async def
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
1
|
+
from typing import Dict, Optional, List
|
2
|
+
import asyncio
|
3
|
+
|
4
|
+
from .base_modbus import ModbusClientBase
|
5
|
+
from .address import *
|
6
|
+
from .untils import retry
|
7
|
+
|
8
|
+
|
9
|
+
class SnapshotCore:
|
10
|
+
def __init__(self, modbus_client: ModbusClientBase, snap_except=None):
|
11
|
+
self.modbus = modbus_client
|
12
|
+
self.all_snap_shot_data: Dict[int, List[int]] = {}
|
13
|
+
self.snap_except = snap_except
|
14
|
+
|
15
|
+
def __getitem__(self, index: int) -> Optional[List[int]]:
|
16
|
+
return self.all_snap_shot_data.get(index)
|
17
|
+
|
18
|
+
async def __aiter__(self):
|
19
|
+
for key in self.all_snap_shot_data:
|
20
|
+
yield key, self.all_snap_shot_data[key]
|
21
|
+
|
22
|
+
@property
|
23
|
+
def all_snap_data(self):
|
24
|
+
return self.all_snap_shot_data.copy()
|
25
|
+
|
26
|
+
@retry(max_attempts=3, delay=0.5)
|
27
|
+
async def _set_MCU_source(self):
|
28
|
+
print("step 1 设置芯片源")
|
29
|
+
result = await self.modbus.write_registers(
|
30
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_MCUSOURCE.value,
|
31
|
+
[SnapshotMCUSource.MCU_SOURCE_MDSP.value],
|
32
|
+
)
|
33
|
+
print(f"step 1 设置芯片源回复:0x{result[0]:04x}")
|
34
|
+
|
35
|
+
@retry(max_attempts=3, delay=0.5)
|
36
|
+
async def _set_export_device(self): # 设置输出设备
|
37
|
+
print("setp 2 设置导出设备")
|
38
|
+
|
39
|
+
result = await self.modbus.write_registers(
|
40
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_EXPORTDEVICE.value,
|
41
|
+
[SnapshotExportDevice.EXPORT_DEVICE_UART.value],
|
42
|
+
)
|
43
|
+
print(f"setp 2 设置导出设备:0x{result[0]:04x}")
|
44
|
+
|
45
|
+
@retry(max_attempts=3, delay=0.5)
|
46
|
+
async def _get_snapshot_total_number(self) -> int: # 取得快照总数
|
47
|
+
print("step 3 获取快照总数")
|
48
|
+
try_number = 3
|
49
|
+
number = 0
|
50
|
+
result = [0]
|
51
|
+
while number < try_number:
|
52
|
+
result = await self.modbus.read_registers(
|
53
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_TOTALNUMBER.value, 1
|
54
|
+
)
|
55
|
+
print(f"step 3 获取快照总数 :{result}")
|
56
|
+
if result[0] > 0:
|
57
|
+
break
|
58
|
+
number += 1
|
59
|
+
return result[0]
|
60
|
+
|
61
|
+
@retry(max_attempts=3, delay=0.5)
|
62
|
+
async def _start_snap_shot(self): # 获取快照开始结果
|
63
|
+
print("第4步 录播开始")
|
64
|
+
result = False
|
65
|
+
readresultcnt = 0
|
66
|
+
while readresultcnt < 3:
|
67
|
+
result = await self.modbus.write_registers(
|
68
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_START.value,
|
69
|
+
[SnapshotStartResult.SNAPSHOT_START_START.value],
|
70
|
+
)
|
71
|
+
print(f" 设置录播开始{result}")
|
72
|
+
await asyncio.sleep(1)
|
73
|
+
response = await self.modbus.read_registers(
|
74
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_START.value, 1
|
75
|
+
)
|
76
|
+
print(f"录波读取设置变量:{response}")
|
77
|
+
|
78
|
+
if response[0] == SnapshotStartResult.SNAPSHOT_START_SUCCESS.value:
|
79
|
+
print("设置录播开始成功")
|
80
|
+
result = True
|
81
|
+
break
|
82
|
+
else:
|
83
|
+
print("设置录播开始失败")
|
84
|
+
result = False
|
85
|
+
readresultcnt += 1
|
86
|
+
|
87
|
+
return result
|
88
|
+
|
89
|
+
@retry(max_attempts=3, delay=0.5)
|
90
|
+
async def _get_snapshot_dataPara(
|
91
|
+
self
|
92
|
+
): # 取得快照数据参数 数据总数 通道数 通道数据深度
|
93
|
+
print("step 5 获取快照数据参数")
|
94
|
+
result = await self.modbus.read_registers(
|
95
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_DATASIZE.value, 3
|
96
|
+
)
|
97
|
+
print(f"step 5 获取快照数据参数:{result}")
|
98
|
+
return result[0]
|
99
|
+
|
100
|
+
@retry(max_attempts=3, delay=0.5)
|
101
|
+
async def _get_Single_snap_shot_data(
|
102
|
+
self, index: int, DataNumber: int
|
103
|
+
): # 获取单个快照数据
|
104
|
+
readdatanum = 0
|
105
|
+
packindex = 0
|
106
|
+
|
107
|
+
await self._set_snap_shot_data_index(index) # 设置快照索引
|
108
|
+
while readdatanum < DataNumber:
|
109
|
+
if await self._get_data_pack_read_state() is False: # 获取数据包读取状态
|
110
|
+
raise self.snap_except("读取数据包错误")
|
111
|
+
|
112
|
+
siglepackdatanum = DataNumber - readdatanum
|
113
|
+
if siglepackdatanum > 256:
|
114
|
+
siglepackdatanum = 256
|
115
|
+
print(f"第{index}次快照,第{packindex}包,读取数据个数:{siglepackdatanum}")
|
116
|
+
|
117
|
+
await self._get_data_pack_index() # 取得数据包索引
|
118
|
+
once_data = await self._get_data_pack(
|
119
|
+
siglepackdatanum
|
120
|
+
) # 获取快照数据的单个pack
|
121
|
+
self.all_snap_shot_data.setdefault(index, []).extend(once_data)
|
122
|
+
|
123
|
+
await (
|
124
|
+
self._clear_data_pack_read_state()
|
125
|
+
) # 清除数据包读取状态 让下位机切pack
|
126
|
+
readdatanum += siglepackdatanum
|
127
|
+
packindex += 1
|
128
|
+
# print(f'self.all_snap_shot_data:{self.all_snap_shot_data}')
|
129
|
+
|
130
|
+
@retry(max_attempts=3, delay=0.5) #
|
131
|
+
async def _set_snap_shot_data_index(self, index: int): # 设置快照数据索引
|
132
|
+
print("step 6 设置快照索引")
|
133
|
+
result = await self.modbus.write_registers(
|
134
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_SNAPSHOTINDEX.value,
|
135
|
+
[index],
|
136
|
+
)
|
137
|
+
print(f"step 6 设置快照索引返回值:0x{result[0]:04x}")
|
138
|
+
|
139
|
+
@retry(max_attempts=3, delay=0.5)
|
140
|
+
async def _get_data_pack_read_state(self): # 取得数据包就绪状态
|
141
|
+
# print(f'取得数据包就绪状态')
|
142
|
+
readcnt = 0
|
143
|
+
result = False
|
144
|
+
while readcnt < 100:
|
145
|
+
result = await self.modbus.read_registers(
|
146
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATASTATUS.value, 1
|
147
|
+
)
|
148
|
+
status = result[0]
|
149
|
+
if status == 1:
|
150
|
+
# print(f'数据包就绪状态为:{status},数据包就绪')
|
151
|
+
result = True
|
152
|
+
break
|
153
|
+
else:
|
154
|
+
# print(f'数据包就绪状态为:{status},数据包未就绪')
|
155
|
+
readcnt += 1
|
156
|
+
await asyncio.sleep(0.5)
|
157
|
+
return result
|
158
|
+
|
159
|
+
@retry(max_attempts=5, delay=0.2)
|
160
|
+
async def _get_data_pack_index(self): # 取得数据包索引
|
161
|
+
# print(f'获取数据包索引')
|
162
|
+
result = await self.modbus.read_registers(
|
163
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKINDEX.value, 1
|
164
|
+
)
|
165
|
+
packnum = result[0]
|
166
|
+
# print(f'当前数据包的索引:{packnum}')
|
167
|
+
return packnum
|
168
|
+
|
169
|
+
@retry(max_attempts=3, delay=0.5)
|
170
|
+
async def _get_data_pack(self, register_num: int) -> List: # 取得快照数据包
|
171
|
+
# print(f'取得快照数据包')
|
172
|
+
DataPack = []
|
173
|
+
if register_num >= 256:
|
174
|
+
response = await self.get_data_pack_h_address(64)
|
175
|
+
DataPack.extend(response)
|
176
|
+
response = await self._get_data_pack_l_address(64)
|
177
|
+
DataPack.extend(response)
|
178
|
+
elif register_num >= 64 and register_num < 256:
|
179
|
+
response = await self.get_data_pack_h_address(64)
|
180
|
+
DataPack.extend(response)
|
181
|
+
response = await self._get_data_pack_l_address((register_num - 128) // 2)
|
182
|
+
DataPack.extend(response)
|
183
|
+
else:
|
184
|
+
response = await self.get_data_pack_h_address(register_num // 2)
|
185
|
+
DataPack.extend(response)
|
186
|
+
|
187
|
+
# print(f'获取快照数据包返回值:{DataPack}')
|
188
|
+
return DataPack
|
189
|
+
|
190
|
+
@retry(max_attempts=3, delay=0.5)
|
191
|
+
async def get_data_pack_h_address(
|
192
|
+
self, register_num: int
|
193
|
+
) -> List: # 取得数据包大小
|
194
|
+
data = await self.modbus.read_registers(
|
195
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATA.value,
|
196
|
+
register_num,
|
197
|
+
)
|
198
|
+
return data
|
199
|
+
|
200
|
+
@retry(max_attempts=3, delay=0.5)
|
201
|
+
async def _get_data_pack_l_address(
|
202
|
+
self, register_num: int
|
203
|
+
) -> List: # 取得数据包大小
|
204
|
+
data = await self.modbus.read_registers(
|
205
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATA.value + 64,
|
206
|
+
register_num,
|
207
|
+
)
|
208
|
+
return data
|
209
|
+
|
210
|
+
@retry(max_attempts=5, delay=0.2)
|
211
|
+
async def _clear_data_pack_read_state(self): # 清除数据包读取状态
|
212
|
+
# print(f'清除数据包读取状态')
|
213
|
+
await self.modbus.write_registers(
|
214
|
+
SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATASTATUS.value, [0]
|
215
|
+
)
|
216
|
+
# print(f'清除数据包就绪状态返回值:{response}')
|
217
|
+
|
218
|
+
@classmethod
|
219
|
+
async def start(cls, modbus_client, snap_shot_index: int = 0, snap_exception=None):
|
220
|
+
"""启动故障录波
|
221
|
+
snap_shot_index : 代表第几个故障 如果传0 就默认读取所有故障
|
222
|
+
"""
|
223
|
+
# print'start.................................')
|
224
|
+
instance = cls(modbus_client, snap_exception)
|
225
|
+
try:
|
226
|
+
# 第一步 设置快照芯片源
|
227
|
+
await instance._set_MCU_source()
|
228
|
+
# 第二步 设置导出设备
|
229
|
+
await instance._set_export_device()
|
230
|
+
# 第三步 获取设备总数
|
231
|
+
total_number = await instance._get_snapshot_total_number()
|
232
|
+
if total_number < 1:
|
233
|
+
return instance.snap_except("无效的故障录波总数")
|
234
|
+
# 第四步 开始录波
|
235
|
+
await instance._start_snap_shot()
|
236
|
+
# 第5步 获取快照数据参数
|
237
|
+
total_data_length = await instance._get_snapshot_dataPara()
|
238
|
+
# 第六步 读数据
|
239
|
+
# for index in range(1, total_number + 1):
|
240
|
+
# await instance._get_Single_snap_shot_data(index, total_data_length)
|
241
|
+
await instance._get_Single_snap_shot_data(1, total_data_length)
|
242
|
+
|
243
|
+
return instance.all_snap_data
|
244
|
+
|
245
|
+
except Exception as e:
|
246
|
+
return instance.snap_except(f"故障录波失败:{e}")
|
247
|
+
|
248
|
+
async def __aenter__(self):
|
249
|
+
return self
|