device-protocol-sdk 1.2.4__tar.gz → 1.2.5__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.
Files changed (18) hide show
  1. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/PKG-INFO +2 -1
  2. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/abstract_device.py +5 -0
  3. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/pusher.py +62 -5
  4. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk.egg-info/PKG-INFO +2 -1
  5. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk.egg-info/requires.txt +1 -0
  6. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/setup.py +2 -1
  7. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/README.md +0 -0
  8. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/__init__.py +0 -0
  9. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/device_pb2.py +0 -0
  10. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/device_pb2_grpc.py +0 -0
  11. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/model/__init__.py +0 -0
  12. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/model/action_item.py +0 -0
  13. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/model/device_key.py +0 -0
  14. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk/model/device_status.py +0 -0
  15. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk.egg-info/SOURCES.txt +0 -0
  16. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk.egg-info/dependency_links.txt +0 -0
  17. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/device_protocol_sdk.egg-info/top_level.txt +0 -0
  18. {device_protocol_sdk-1.2.4 → device_protocol_sdk-1.2.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: device_protocol_sdk
3
- Version: 1.2.4
3
+ Version: 1.2.5
4
4
  Summary: 无人设备协议开发SDK
5
5
  Author: fuhl
6
6
  Requires-Python: >=3.8
@@ -10,6 +10,7 @@ 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: shapely>=2.1.2
13
14
 
14
15
  # Device Protocol SDK
15
16
 
@@ -138,6 +138,11 @@ class AbstractDevice(ABC):
138
138
  is_connect,client = self._create_client(device_key.device_id,device_key.connection_str)
139
139
  if is_connect:
140
140
  self._connection_pool[device_key] = client
141
+ return is_connect,client
142
+ else:
143
+ client = self._connection_pool[device_key]
144
+ return True,client
145
+
141
146
 
142
147
  def disconnect(self, device_key: DeviceKey):
143
148
  with self._lock:
@@ -9,6 +9,7 @@ from . import device_pb2
9
9
  from . import device_pb2_grpc
10
10
  from .model.device_key import DeviceKey
11
11
  import math
12
+ from shapely.geometry import Point, Polygon
12
13
 
13
14
  logger = logging.getLogger(__name__)
14
15
 
@@ -222,6 +223,52 @@ class DevicePusher:
222
223
  logger.warning("MQTT连接断开,尝试重新连接...")
223
224
  return await self.setup_mqtt()
224
225
  return True
226
+
227
+ def is_in_china_shapely(self,lon, lat):
228
+ """
229
+ 使用更精确的中国边界判断经纬度是否在中国范围内
230
+ """
231
+ # 更精确的中国边界坐标(包含主要陆地和主要岛屿)
232
+ china_coords = [
233
+ # 中国大陆主要边界点(逆时针)
234
+ (121.612, 25.288), # 台湾东北
235
+ (123.508, 24.445), # 钓鱼岛附近
236
+ (125.341, 24.787), # 东海
237
+ (129.664, 32.792), # 日本海附近
238
+ (130.667, 42.266), # 吉林延边
239
+ (131.283, 44.893), # 吉林珲春
240
+ (134.773, 48.446), # 黑龙江抚远
241
+ (135.092, 47.733), # 黑龙江同江
242
+ (137.437, 53.571), # 外兴安岭附近
243
+ (119.931, 52.117), # 内蒙古满洲里
244
+ (97.234, 42.812), # 甘肃敦煌
245
+ (80.260, 42.215), # 新疆喀什
246
+ (75.996, 39.468), # 新疆塔什库尔干
247
+ (74.890, 37.235), # 新疆红其拉甫
248
+ (78.367, 35.427), # 新疆和田
249
+ (79.722, 34.468), # 西藏阿里
250
+ (81.111, 32.493), # 西藏狮泉河
251
+ (82.567, 31.779), # 西藏改则
252
+ (85.152, 28.547), # 西藏聂拉木
253
+ (86.827, 27.866), # 西藏定结
254
+ (88.916, 27.799), # 西藏亚东
255
+ (91.681, 27.498), # 西藏错那
256
+ (97.352, 28.262), # 云南贡山
257
+ (98.494, 24.846), # 云南瑞丽
258
+ (101.152, 21.485), # 云南西双版纳
259
+ (105.444, 21.531), # 广西那坡
260
+ (108.320, 21.573), # 广西北海
261
+ (110.355, 20.098), # 广东湛江
262
+ (113.823, 22.448), # 香港
263
+ (114.296, 22.808), # 深圳
264
+ (117.367, 23.752), # 台湾海峡
265
+ (121.612, 25.288), # 回到起点
266
+ ]
267
+
268
+ china_polygon = Polygon(china_coords)
269
+ point = Point(lon, lat)
270
+
271
+ return china_polygon.contains(point)
225
272
  async def _report_status_continuously(self,protocol_name, device: 'AbstractDevice', deviceKey: DeviceKey, report_interval=1):
226
273
  """通过MQTT持续上报设备状态"""
227
274
  """通过MQTT持续上报设备状态,状态为空时停止并清理"""
@@ -251,14 +298,24 @@ class DevicePusher:
251
298
  if not isinstance(status, (list, tuple)):
252
299
  logger.warning(f"设备 {deviceKey} 状态格式错误: {type(status)}")
253
300
  continue
301
+
254
302
  #将status中的gps坐标系转换 WGS84坐标转换为GCJ02坐标
255
303
  for st in status:
304
+ if device.is_connected:
305
+ st['is_connect'] = True
306
+ else:
307
+ st['is_connect'] = False
256
308
  if st and 'lat' in st and 'lon' in st:
257
- lat_wgs84 = st['lat']
258
- lon_wgs84 = st['lon']
259
- lon_gcj02, lat_gcj02 = self.wgs84_to_gcj02(lon_wgs84, lat_wgs84)
260
- st['lat'] = lat_gcj02
261
- st['lon'] = lon_gcj02
309
+ if st:
310
+ lat_wgs84 = st['lat']
311
+ lon_wgs84 = st['lon']
312
+ if self.is_in_china_shapely(lon_wgs84,lat_wgs84):
313
+ lon_gcj02, lat_gcj02 = self.wgs84_to_gcj02(lon_wgs84, lat_wgs84)
314
+ st['lat'] = lat_gcj02
315
+ st['lon'] = lon_gcj02
316
+ else:
317
+ st['lat'] = None
318
+ st['lon'] = None
262
319
 
263
320
 
264
321
  payload = json.dumps({
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: device_protocol_sdk
3
- Version: 1.2.4
3
+ Version: 1.2.5
4
4
  Summary: 无人设备协议开发SDK
5
5
  Author: fuhl
6
6
  Requires-Python: >=3.8
@@ -10,6 +10,7 @@ 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: shapely>=2.1.2
13
14
 
14
15
  # Device Protocol SDK
15
16
 
@@ -3,3 +3,4 @@ grpcio-tools>=1.48.2
3
3
  paho-mqtt>=1.6.1
4
4
  pydantic>=1.9.0
5
5
  websockets>=10.0
6
+ shapely>=2.1.2
@@ -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.4",
10
+ version="1.2.5",
11
11
  packages=find_packages(include=["sdk*", "device_protocol_sdk*"]),
12
12
  install_requires=[
13
13
  "grpcio>=1.48.2", # gRPC 运行时依赖
@@ -15,6 +15,7 @@ setup(
15
15
  "paho-mqtt>=1.6.1", # MQTT 客户端
16
16
  "pydantic>=1.9.0", # 数据验证和设置管理
17
17
  "websockets>=10.0", # Websocket 支持
18
+ "shapely>=2.1.2",
18
19
  ],
19
20
  python_requires=">=3.8",
20
21
  author="fuhl",