device-protocol-sdk 1.2.3__tar.gz → 1.2.4__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.
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/PKG-INFO +1 -2
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/pusher.py +138 -49
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk.egg-info/PKG-INFO +1 -2
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk.egg-info/requires.txt +0 -1
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/setup.py +1 -2
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/README.md +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/__init__.py +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/abstract_device.py +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/device_pb2.py +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/device_pb2_grpc.py +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/model/__init__.py +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/model/action_item.py +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/model/device_key.py +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/model/device_status.py +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk.egg-info/SOURCES.txt +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk.egg-info/dependency_links.txt +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk.egg-info/top_level.txt +0 -0
- {device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: device_protocol_sdk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.4
|
|
4
4
|
Summary: 无人设备协议开发SDK
|
|
5
5
|
Author: fuhl
|
|
6
6
|
Requires-Python: >=3.8
|
|
@@ -10,7 +10,6 @@ Requires-Dist: grpcio-tools>=1.48.2
|
|
|
10
10
|
Requires-Dist: paho-mqtt>=1.6.1
|
|
11
11
|
Requires-Dist: pydantic>=1.9.0
|
|
12
12
|
Requires-Dist: websockets>=10.0
|
|
13
|
-
Requires-Dist: coord-convert>=0.2.1
|
|
14
13
|
|
|
15
14
|
# Device Protocol SDK
|
|
16
15
|
|
|
@@ -8,7 +8,6 @@ import paho.mqtt.client as mqtt
|
|
|
8
8
|
from . import device_pb2
|
|
9
9
|
from . import device_pb2_grpc
|
|
10
10
|
from .model.device_key import DeviceKey
|
|
11
|
-
from coord_convert import transform
|
|
12
11
|
import math
|
|
13
12
|
|
|
14
13
|
logger = logging.getLogger(__name__)
|
|
@@ -244,10 +243,17 @@ class DevicePusher:
|
|
|
244
243
|
# if not status:
|
|
245
244
|
# logger.warning(f"设备 {deviceKey} 状态为空")
|
|
246
245
|
# break
|
|
246
|
+
if status is None:
|
|
247
|
+
logger.warning(f"设备 {deviceKey} 返回状态为 None")
|
|
248
|
+
continue # 跳过这个设备的处理
|
|
247
249
|
|
|
250
|
+
# 添加对 status 是否为可迭代对象的检查
|
|
251
|
+
if not isinstance(status, (list, tuple)):
|
|
252
|
+
logger.warning(f"设备 {deviceKey} 状态格式错误: {type(status)}")
|
|
253
|
+
continue
|
|
248
254
|
#将status中的gps坐标系转换 WGS84坐标转换为GCJ02坐标
|
|
249
255
|
for st in status:
|
|
250
|
-
if 'lat' in st and 'lon' in st:
|
|
256
|
+
if st and 'lat' in st and 'lon' in st:
|
|
251
257
|
lat_wgs84 = st['lat']
|
|
252
258
|
lon_wgs84 = st['lon']
|
|
253
259
|
lon_gcj02, lat_gcj02 = self.wgs84_to_gcj02(lon_wgs84, lat_wgs84)
|
|
@@ -404,40 +410,45 @@ class DevicePusher:
|
|
|
404
410
|
mission_id = command_request.mission_id
|
|
405
411
|
selected_devices = json.loads(command_request.params)
|
|
406
412
|
result = ""
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
413
|
+
|
|
414
|
+
# 添加执行模式控制,可以根据需要配置
|
|
415
|
+
execute_parallel = False # 可以改为从配置或命令参数中获取
|
|
416
|
+
|
|
417
|
+
if execute_parallel:
|
|
418
|
+
#并行
|
|
419
|
+
tasks = []
|
|
420
|
+
for selected_device in selected_devices:
|
|
421
|
+
task = self._process_single_device(selected_device, mission_id, command_request.command_id)
|
|
422
|
+
tasks.append(task)
|
|
423
|
+
|
|
424
|
+
# 等待所有设备处理完成
|
|
425
|
+
results = await asyncio.gather(*tasks, return_exceptions=True)
|
|
426
|
+
|
|
427
|
+
# 处理结果
|
|
428
|
+
success_results = []
|
|
429
|
+
for i, result in enumerate(results):
|
|
430
|
+
if isinstance(result, Exception):
|
|
431
|
+
logger.error(f"设备 {selected_devices[i]['device_id']} 处理失败: {result}")
|
|
432
|
+
# 可以根据需要决定是否继续处理其他设备
|
|
433
|
+
else:
|
|
434
|
+
success_results.append(result)
|
|
435
|
+
|
|
436
|
+
# 合并成功的结果
|
|
437
|
+
result = success_results[0] if success_results else ""
|
|
438
|
+
else:
|
|
439
|
+
#串行
|
|
440
|
+
for selected_device in selected_devices:
|
|
441
|
+
# 解析参数
|
|
442
|
+
device_id = selected_device['device_id']
|
|
443
|
+
connection_str = selected_device['connection_str']
|
|
444
|
+
deviceKey = DeviceKey(device_id=device_id, connection_str=connection_str)
|
|
445
|
+
if mission_id == 'connect':
|
|
435
446
|
# 获取或创建设备实例
|
|
436
447
|
if deviceKey not in self.devices:
|
|
437
448
|
logger.info(f"创建新设备实例: {deviceKey}")
|
|
438
449
|
device = self.device_factory()
|
|
439
|
-
device.set_grpc_stub(self.grpc_stub)
|
|
440
450
|
self.devices[deviceKey] = device
|
|
451
|
+
result = "创建连接成功"
|
|
441
452
|
# 连接设备
|
|
442
453
|
try:
|
|
443
454
|
device.connect(deviceKey)
|
|
@@ -446,25 +457,46 @@ class DevicePusher:
|
|
|
446
457
|
self._report_status_continuously(self.protocol_name,device, deviceKey))
|
|
447
458
|
logger.info(f"为设备 {deviceKey} 启动状态上报任务")
|
|
448
459
|
except Exception as e:
|
|
460
|
+
result = "创建连接失败"
|
|
449
461
|
raise ValueError(f"设备连接失败: {e}")
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
462
|
+
else:
|
|
463
|
+
actions = selected_device['actions']
|
|
464
|
+
for action in actions:
|
|
465
|
+
command_type = action['command_type']
|
|
466
|
+
params = action['parameters']
|
|
467
|
+
# 获取或创建设备实例
|
|
468
|
+
if deviceKey not in self.devices:
|
|
469
|
+
logger.info(f"创建新设备实例: {deviceKey}")
|
|
470
|
+
device = self.device_factory()
|
|
471
|
+
device.set_grpc_stub(self.grpc_stub)
|
|
472
|
+
self.devices[deviceKey] = device
|
|
473
|
+
# 连接设备
|
|
474
|
+
try:
|
|
475
|
+
device.connect(deviceKey)
|
|
476
|
+
if deviceKey not in self.status_tasks:
|
|
477
|
+
self.status_tasks[deviceKey] = asyncio.create_task(
|
|
478
|
+
self._report_status_continuously(self.protocol_name,device, deviceKey))
|
|
479
|
+
logger.info(f"为设备 {deviceKey} 启动状态上报任务")
|
|
480
|
+
except Exception as e:
|
|
481
|
+
raise ValueError(f"设备连接失败: {e}")
|
|
482
|
+
|
|
483
|
+
device = self.devices[deviceKey]
|
|
484
|
+
device.set_grpc_stub(self.grpc_stub)
|
|
485
|
+
# 执行命令
|
|
486
|
+
try:
|
|
487
|
+
result = device.excute_command(device_id, connection_str, command_type, params, mission_id)
|
|
488
|
+
except Exception as e:
|
|
489
|
+
raise ValueError(f"命令执行失败: {e}")
|
|
490
|
+
|
|
491
|
+
# 发送成功确认
|
|
492
|
+
ack = device_pb2.CommandAck(
|
|
493
|
+
command_id=command_request.command_id,
|
|
494
|
+
mission_id=mission_id,
|
|
495
|
+
success=True,
|
|
496
|
+
data=json.dumps(result) if result else ""
|
|
497
|
+
)
|
|
498
|
+
await command_stream.write(ack)
|
|
499
|
+
logger.info(f"命令执行成功: {command_request.command_id}")
|
|
468
500
|
|
|
469
501
|
except Exception as e:
|
|
470
502
|
logger.error(f"处理命令失败: {e}")
|
|
@@ -484,6 +516,63 @@ class DevicePusher:
|
|
|
484
516
|
logger.error(f"命令流处理异常: {e}")
|
|
485
517
|
raise
|
|
486
518
|
|
|
519
|
+
async def _process_single_device(self, selected_device, mission_id, command_id):
|
|
520
|
+
"""处理单个设备的通用逻辑"""
|
|
521
|
+
# 解析参数
|
|
522
|
+
device_id = selected_device['device_id']
|
|
523
|
+
connection_str = selected_device['connection_str']
|
|
524
|
+
deviceKey = DeviceKey(device_id=device_id, connection_str=connection_str)
|
|
525
|
+
|
|
526
|
+
if mission_id == 'connect':
|
|
527
|
+
# 获取或创建设备实例
|
|
528
|
+
if deviceKey not in self.devices:
|
|
529
|
+
logger.info(f"创建新设备实例: {deviceKey}")
|
|
530
|
+
device = self.device_factory()
|
|
531
|
+
self.devices[deviceKey] = device
|
|
532
|
+
result = "创建连接成功"
|
|
533
|
+
# 连接设备
|
|
534
|
+
try:
|
|
535
|
+
device.connect(deviceKey)
|
|
536
|
+
if deviceKey not in self.status_tasks:
|
|
537
|
+
self.status_tasks[deviceKey] = asyncio.create_task(
|
|
538
|
+
self._report_status_continuously(self.protocol_name, device, deviceKey))
|
|
539
|
+
logger.info(f"为设备 {deviceKey} 启动状态上报任务")
|
|
540
|
+
except Exception as e:
|
|
541
|
+
result = "创建连接失败"
|
|
542
|
+
raise ValueError(f"设备连接失败: {e}")
|
|
543
|
+
return result
|
|
544
|
+
else:
|
|
545
|
+
actions = selected_device['actions']
|
|
546
|
+
final_result = ""
|
|
547
|
+
for action in actions:
|
|
548
|
+
command_type = action['command_type']
|
|
549
|
+
params = action['parameters']
|
|
550
|
+
# 获取或创建设备实例
|
|
551
|
+
if deviceKey not in self.devices:
|
|
552
|
+
logger.info(f"创建新设备实例: {deviceKey}")
|
|
553
|
+
device = self.device_factory()
|
|
554
|
+
device.set_grpc_stub(self.grpc_stub)
|
|
555
|
+
self.devices[deviceKey] = device
|
|
556
|
+
# 连接设备
|
|
557
|
+
try:
|
|
558
|
+
device.connect(deviceKey)
|
|
559
|
+
if deviceKey not in self.status_tasks:
|
|
560
|
+
self.status_tasks[deviceKey] = asyncio.create_task(
|
|
561
|
+
self._report_status_continuously(self.protocol_name, device, deviceKey))
|
|
562
|
+
logger.info(f"为设备 {deviceKey} 启动状态上报任务")
|
|
563
|
+
except Exception as e:
|
|
564
|
+
raise ValueError(f"设备连接失败: {e}")
|
|
565
|
+
|
|
566
|
+
device = self.devices[deviceKey]
|
|
567
|
+
device.set_grpc_stub(self.grpc_stub)
|
|
568
|
+
# 执行命令
|
|
569
|
+
try:
|
|
570
|
+
result = device.excute_command(device_id, connection_str, command_type, params, mission_id)
|
|
571
|
+
final_result = result
|
|
572
|
+
except Exception as e:
|
|
573
|
+
raise ValueError(f"命令执行失败: {e}")
|
|
574
|
+
return final_result
|
|
575
|
+
|
|
487
576
|
def _update_all_devices_grpc_stub(self):
|
|
488
577
|
"""更新所有设备实例的grpc_stub"""
|
|
489
578
|
for device_key, device in self.devices.items():
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: device_protocol_sdk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.4
|
|
4
4
|
Summary: 无人设备协议开发SDK
|
|
5
5
|
Author: fuhl
|
|
6
6
|
Requires-Python: >=3.8
|
|
@@ -10,7 +10,6 @@ Requires-Dist: grpcio-tools>=1.48.2
|
|
|
10
10
|
Requires-Dist: paho-mqtt>=1.6.1
|
|
11
11
|
Requires-Dist: pydantic>=1.9.0
|
|
12
12
|
Requires-Dist: websockets>=10.0
|
|
13
|
-
Requires-Dist: coord-convert>=0.2.1
|
|
14
13
|
|
|
15
14
|
# Device Protocol SDK
|
|
16
15
|
|
|
@@ -7,7 +7,7 @@ long_description = readme_path.read_text(encoding="utf-8")
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name="device_protocol_sdk",
|
|
10
|
-
version="1.2.
|
|
10
|
+
version="1.2.4",
|
|
11
11
|
packages=find_packages(include=["sdk*", "device_protocol_sdk*"]),
|
|
12
12
|
install_requires=[
|
|
13
13
|
"grpcio>=1.48.2", # gRPC 运行时依赖
|
|
@@ -15,7 +15,6 @@ setup(
|
|
|
15
15
|
"paho-mqtt>=1.6.1", # MQTT 客户端
|
|
16
16
|
"pydantic>=1.9.0", # 数据验证和设置管理
|
|
17
17
|
"websockets>=10.0", # Websocket 支持
|
|
18
|
-
"coord-convert>=0.2.1",
|
|
19
18
|
],
|
|
20
19
|
python_requires=">=3.8",
|
|
21
20
|
author="fuhl",
|
|
File without changes
|
|
File without changes
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/abstract_device.py
RENAMED
|
File without changes
|
|
File without changes
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/device_pb2_grpc.py
RENAMED
|
File without changes
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/model/__init__.py
RENAMED
|
File without changes
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/model/action_item.py
RENAMED
|
File without changes
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/model/device_key.py
RENAMED
|
File without changes
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk/model/device_status.py
RENAMED
|
File without changes
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{device_protocol_sdk-1.2.3 → device_protocol_sdk-1.2.4}/device_protocol_sdk.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|