smartpi 0.1.17__py3-none-any.whl → 0.1.19__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.
- smartpi/__init__.py +1 -1
- smartpi/base_driver.py +58 -16
- smartpi/trace.py +0 -2
- {smartpi-0.1.17.dist-info → smartpi-0.1.19.dist-info}/METADATA +1 -1
- {smartpi-0.1.17.dist-info → smartpi-0.1.19.dist-info}/RECORD +7 -7
- {smartpi-0.1.17.dist-info → smartpi-0.1.19.dist-info}/WHEEL +0 -0
- {smartpi-0.1.17.dist-info → smartpi-0.1.19.dist-info}/top_level.txt +0 -0
smartpi/__init__.py
CHANGED
smartpi/base_driver.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
|
-
import serial,time,struct,threading
|
|
2
|
+
import serial,time,struct,threading,fcntl
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from collections import deque
|
|
5
5
|
from . import servo,motor,cw2015,gui
|
|
@@ -202,12 +202,14 @@ def process_received_data():
|
|
|
202
202
|
"""读取设备型号"""
|
|
203
203
|
def read_device_model() -> Optional[bytes]:
|
|
204
204
|
serial_lock.acquire() #获取线程锁
|
|
205
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
205
206
|
write_data(READ_MODEL_H, READ_MODEL_L)
|
|
206
207
|
start_time = time.time()
|
|
207
208
|
while True:
|
|
208
209
|
response =process_received_data()
|
|
209
210
|
if response:
|
|
210
211
|
serial_lock.release() #释放线程锁
|
|
212
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
211
213
|
display_data = response[6:-3].decode(errors="ignore")
|
|
212
214
|
# print(f"设备型号: {display_data}")
|
|
213
215
|
return display_data
|
|
@@ -216,17 +218,20 @@ def read_device_model() -> Optional[bytes]:
|
|
|
216
218
|
print("读取超时")
|
|
217
219
|
buffer.clear()
|
|
218
220
|
serial_lock.release() #释放线程锁
|
|
221
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
219
222
|
return None
|
|
220
223
|
|
|
221
224
|
"""读取版本号"""
|
|
222
225
|
def read_version() -> Optional[bytes]:
|
|
223
226
|
serial_lock.acquire() #获取线程锁
|
|
227
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
224
228
|
write_data(READ_VERSION_H, READ_VERSION_L)
|
|
225
229
|
start_time = time.time()
|
|
226
230
|
while True:
|
|
227
231
|
response =process_received_data()
|
|
228
232
|
if response:
|
|
229
233
|
serial_lock.release() #释放线程锁
|
|
234
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
230
235
|
display_data = response[6:-3].decode(errors="ignore")
|
|
231
236
|
# print(f"版本号: {display_data}")
|
|
232
237
|
return display_data
|
|
@@ -235,17 +240,20 @@ def read_version() -> Optional[bytes]:
|
|
|
235
240
|
print("读取超时")
|
|
236
241
|
buffer.clear()
|
|
237
242
|
serial_lock.release() #释放线程锁
|
|
243
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
238
244
|
return None
|
|
239
245
|
|
|
240
246
|
"""读取工厂信息"""
|
|
241
247
|
def read_factory_data() -> Optional[bytes]:
|
|
242
248
|
serial_lock.acquire() #获取线程锁
|
|
249
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
243
250
|
write_data(READ_FACTORY_H, READ_FACTORY_L)
|
|
244
251
|
start_time = time.time()
|
|
245
252
|
while True:
|
|
246
253
|
response =process_received_data()
|
|
247
254
|
if response:
|
|
248
255
|
serial_lock.release() #释放线程锁
|
|
256
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
249
257
|
display_data = response[6:-3].decode(errors="ignore")
|
|
250
258
|
# print(f"厂家信息: {display_data}")
|
|
251
259
|
return display_data
|
|
@@ -254,17 +262,20 @@ def read_factory_data() -> Optional[bytes]:
|
|
|
254
262
|
print("读取超时")
|
|
255
263
|
buffer.clear()
|
|
256
264
|
serial_lock.release() #释放线程锁
|
|
265
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
257
266
|
return None
|
|
258
267
|
|
|
259
268
|
"""读取硬件ID"""
|
|
260
269
|
def read_hardware_ID() -> Optional[bytes]:
|
|
261
270
|
serial_lock.acquire() #获取线程锁
|
|
271
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
262
272
|
write_data(READ_HW_ID_H, READ_HW_ID_L)
|
|
263
273
|
start_time = time.time()
|
|
264
274
|
while True:
|
|
265
275
|
response =process_received_data()
|
|
266
276
|
if response:
|
|
267
277
|
serial_lock.release() #释放线程锁
|
|
278
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
268
279
|
display_data = response[6:-3].decode(errors="ignore")
|
|
269
280
|
# print(f"硬件ID: {display_data}")
|
|
270
281
|
return display_data
|
|
@@ -273,17 +284,20 @@ def read_hardware_ID() -> Optional[bytes]:
|
|
|
273
284
|
print("读取超时")
|
|
274
285
|
buffer.clear()
|
|
275
286
|
serial_lock.release() #释放线程锁
|
|
287
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
276
288
|
return None
|
|
277
289
|
|
|
278
290
|
"""读取设备名称"""
|
|
279
291
|
def read_device_name() -> Optional[bytes]:
|
|
280
|
-
serial_lock.acquire() #获取线程锁
|
|
292
|
+
serial_lock.acquire() #获取线程锁
|
|
293
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
281
294
|
write_data(READ_NAME_H, READ_NAME_L)
|
|
282
295
|
start_time = time.time()
|
|
283
296
|
while True:
|
|
284
297
|
response =process_received_data()
|
|
285
298
|
if response:
|
|
286
299
|
serial_lock.release() #释放线程锁
|
|
300
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
287
301
|
display_data = response[6:-3].decode(errors="ignore")
|
|
288
302
|
# print(f"设备名称: {display_data}")
|
|
289
303
|
return display_data
|
|
@@ -292,11 +306,13 @@ def read_device_name() -> Optional[bytes]:
|
|
|
292
306
|
print("读取超时")
|
|
293
307
|
buffer.clear()
|
|
294
308
|
serial_lock.release() #释放线程锁
|
|
309
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
295
310
|
return None
|
|
296
311
|
|
|
297
312
|
"""设置设备名称"""
|
|
298
313
|
def write_device_name(send_data: str) -> Optional[bytes]:
|
|
299
314
|
serial_lock.acquire() #获取线程锁
|
|
315
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
300
316
|
data_bytes = send_data.encode('utf-8')
|
|
301
317
|
write_data(WRITE_NAME_H, WRITE_NAME_L, data_bytes)
|
|
302
318
|
start_time = time.time()
|
|
@@ -304,6 +320,7 @@ def write_device_name(send_data: str) -> Optional[bytes]:
|
|
|
304
320
|
response =process_received_data()
|
|
305
321
|
if response:
|
|
306
322
|
serial_lock.release() #释放线程锁
|
|
323
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
307
324
|
display_data = response[6:-3].decode(errors="ignore")
|
|
308
325
|
# print(f"设置状态: {display_data}")
|
|
309
326
|
return 0
|
|
@@ -312,17 +329,20 @@ def write_device_name(send_data: str) -> Optional[bytes]:
|
|
|
312
329
|
print("读取超时")
|
|
313
330
|
buffer.clear()
|
|
314
331
|
serial_lock.release() #释放线程锁
|
|
332
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
315
333
|
return None
|
|
316
334
|
|
|
317
335
|
"""读取连接方式"""
|
|
318
|
-
def read_connected() -> Optional[bytes]:
|
|
336
|
+
def read_connected() -> Optional[bytes]:
|
|
319
337
|
serial_lock.acquire() #获取线程锁
|
|
338
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
320
339
|
write_data(READ_CONNECT_H, READ_CONNECT_L)
|
|
321
340
|
start_time = time.time()
|
|
322
341
|
while True:
|
|
323
342
|
response =process_received_data()
|
|
324
343
|
if response:
|
|
325
344
|
serial_lock.release() #释放线程锁
|
|
345
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
326
346
|
display_data = response[6:-3].decode(errors="ignore")
|
|
327
347
|
# print(f"连接方式: {display_data}")
|
|
328
348
|
return display_data
|
|
@@ -330,7 +350,8 @@ def read_connected() -> Optional[bytes]:
|
|
|
330
350
|
if time.time() - start_time > 3:
|
|
331
351
|
print("读取超时")
|
|
332
352
|
buffer.clear()
|
|
333
|
-
serial_lock.release() #释放线程锁
|
|
353
|
+
serial_lock.release() #释放线程锁
|
|
354
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
334
355
|
return None
|
|
335
356
|
|
|
336
357
|
"""读取电池电量百分比"""
|
|
@@ -442,14 +463,16 @@ def read_battery() -> Optional[bytes]:
|
|
|
442
463
|
###############################################################################读取传感器信息
|
|
443
464
|
|
|
444
465
|
"""读取外设连接情况"""
|
|
445
|
-
def read_peripheral() -> Optional[bytes]:
|
|
446
|
-
|
|
466
|
+
def read_peripheral() -> Optional[bytes]:
|
|
467
|
+
serial_lock.acquire() #获取线程锁
|
|
468
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
447
469
|
write_data(READ_PERIPH_H, READ_PERIPH_L)
|
|
448
470
|
start_time = time.time()
|
|
449
471
|
while True:
|
|
450
472
|
response =process_received_data()
|
|
451
473
|
if response:
|
|
452
|
-
|
|
474
|
+
serial_lock.release() #释放线程锁
|
|
475
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
453
476
|
display_data = response[6:-3]
|
|
454
477
|
# for x in display_data:
|
|
455
478
|
# print(f"{x:02X}", end=' ')
|
|
@@ -459,18 +482,21 @@ def read_peripheral() -> Optional[bytes]:
|
|
|
459
482
|
if time.time() - start_time > 3:
|
|
460
483
|
print("读取超时")
|
|
461
484
|
buffer.clear()
|
|
462
|
-
|
|
485
|
+
serial_lock.release() #释放线程锁
|
|
486
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
463
487
|
return None
|
|
464
488
|
|
|
465
489
|
"""单次操作外设"""
|
|
466
490
|
def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
467
491
|
serial_lock.acquire() #获取线程锁
|
|
492
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
468
493
|
write_data(SINGLE_OP_H, SINGLE_OP_L, op_struct)
|
|
469
494
|
start_time = time.time()
|
|
470
495
|
while True:
|
|
471
496
|
response =process_received_data()
|
|
472
497
|
if response:
|
|
473
498
|
serial_lock.release() #释放线程锁
|
|
499
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
474
500
|
display_data = response[6:-3]
|
|
475
501
|
# for x in display_data:
|
|
476
502
|
# print(f"{x:02X}", end=' ')
|
|
@@ -481,6 +507,7 @@ def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
|
481
507
|
print("读取超时")
|
|
482
508
|
buffer.clear()
|
|
483
509
|
serial_lock.release() #释放线程锁
|
|
510
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
484
511
|
return None
|
|
485
512
|
|
|
486
513
|
#P端口初始化释放
|
|
@@ -494,14 +521,16 @@ def P_port_init(port:bytes) -> Optional[bytes]:
|
|
|
494
521
|
return None
|
|
495
522
|
|
|
496
523
|
"""从机模式转换"""
|
|
497
|
-
def mode_change(send_data: str) -> Optional[bytes]:
|
|
498
|
-
serial_lock.acquire() #获取线程锁
|
|
524
|
+
def mode_change(send_data: str) -> Optional[bytes]:
|
|
525
|
+
serial_lock.acquire() #获取线程锁
|
|
526
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
499
527
|
write_data(MODE_CHANGE_H, MODE_CHANGE_L, send_data)
|
|
500
528
|
start_time = time.time()
|
|
501
529
|
while True:
|
|
502
530
|
response =process_received_data()
|
|
503
531
|
if response:
|
|
504
532
|
serial_lock.release() #释放线程锁
|
|
533
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
505
534
|
display_data = response[6:-3]
|
|
506
535
|
# for x in display_data:
|
|
507
536
|
# print(f"{x:02X}", end=' ')
|
|
@@ -512,17 +541,20 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
512
541
|
print("读取超时")
|
|
513
542
|
buffer.clear()
|
|
514
543
|
serial_lock.release() #释放线程锁
|
|
544
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
515
545
|
return None
|
|
516
546
|
|
|
517
547
|
"""智能模式发送周期"""
|
|
518
|
-
def mode_change(send_data: str) -> Optional[bytes]:
|
|
519
|
-
serial_lock.acquire() #获取线程锁
|
|
548
|
+
def mode_change(send_data: str) -> Optional[bytes]:
|
|
549
|
+
serial_lock.acquire() #获取线程锁
|
|
550
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
520
551
|
write_data(SEND_CYCLE_H, SEND_CYCLE_L, send_data)
|
|
521
552
|
start_time = time.time()
|
|
522
553
|
while True:
|
|
523
554
|
response =process_received_data()
|
|
524
555
|
if response:
|
|
525
556
|
serial_lock.release() #释放线程锁
|
|
557
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
526
558
|
display_data = response[6:-3]
|
|
527
559
|
# for x in display_data:
|
|
528
560
|
# print(f"{x:02X}", end=' ')
|
|
@@ -532,38 +564,48 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
532
564
|
if time.time() - start_time > 3:
|
|
533
565
|
print("读取超时")
|
|
534
566
|
buffer.clear()
|
|
535
|
-
serial_lock.release() #释放线程锁
|
|
567
|
+
serial_lock.release() #释放线程锁
|
|
568
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
536
569
|
return None
|
|
537
570
|
|
|
538
571
|
def shut_down():
|
|
539
572
|
serial_lock.acquire() #获取线程锁
|
|
573
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
540
574
|
write_data(0XFF, 0XFE)
|
|
541
575
|
serial_lock.release() #释放线程锁
|
|
576
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
542
577
|
time.sleep(0.5)
|
|
543
578
|
|
|
544
579
|
def shut_down_state() -> bool:
|
|
545
580
|
serial_lock.acquire() #获取线程锁
|
|
581
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
546
582
|
response =process_received_data()
|
|
547
583
|
if response:
|
|
548
584
|
receive_data = response[4:-3]
|
|
549
585
|
if receive_data[0]==0XFF and receive_data[1]==0XFE:
|
|
550
586
|
serial_lock.release() #释放线程锁
|
|
587
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
551
588
|
return True
|
|
552
589
|
else:
|
|
553
590
|
serial_lock.release() #释放线程锁
|
|
591
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
554
592
|
return False
|
|
555
593
|
else:
|
|
556
594
|
serial_lock.release() #释放线程锁
|
|
595
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
557
596
|
return False
|
|
558
597
|
|
|
559
598
|
"""H2-RCU初始化"""
|
|
560
599
|
def smartpi_init():
|
|
561
600
|
|
|
562
601
|
if is_lock_locked(serial_lock):
|
|
563
|
-
serial_lock.release()
|
|
602
|
+
serial_lock.release() #释放线程锁
|
|
564
603
|
|
|
565
|
-
|
|
604
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
605
|
+
serial_lock.acquire() #获取线程锁
|
|
606
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
566
607
|
uart3_init()
|
|
608
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
567
609
|
P_port_init(1)
|
|
568
610
|
P_port_init(2)
|
|
569
611
|
P_port_init(3)
|
|
@@ -596,6 +638,6 @@ def smartpi_init():
|
|
|
596
638
|
motor.reset_motor_encoder(6)
|
|
597
639
|
time.sleep(0.1)
|
|
598
640
|
gui.init()
|
|
599
|
-
serial_lock.release()
|
|
641
|
+
serial_lock.release()
|
|
600
642
|
time.sleep(0.1)
|
|
601
643
|
|
smartpi/trace.py
CHANGED
|
@@ -12,8 +12,6 @@ def get_analog(port:bytes, chn:bytes) -> Optional[bytes]:
|
|
|
12
12
|
if response == None:
|
|
13
13
|
return None
|
|
14
14
|
else:
|
|
15
|
-
trace_data=response[4:-1]
|
|
16
|
-
trace_num=int.from_bytes(trace_data, byteorder='big', signed=True)
|
|
17
15
|
return response[4]
|
|
18
16
|
|
|
19
17
|
#循迹卡设置全部颜色 port:连接P端口;正常返回:通道光值数据; 读取错误:None
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
smartpi/__init__.py,sha256=
|
|
2
|
-
smartpi/base_driver.py,sha256=
|
|
1
|
+
smartpi/__init__.py,sha256=XC4FyX6UBONemsJEdIZzMvIkF4pscJ5XGVvK8jgVCdA,55
|
|
2
|
+
smartpi/base_driver.py,sha256=DV-jh7j4X7ak9zFSqgwjHrj1X18SDqUjCqewLovxDVU,24096
|
|
3
3
|
smartpi/color_sensor.py,sha256=sTqD3jApjmc6qHMrDyEy2UjaRt8vhJZNR88vzgUiLKs,496
|
|
4
4
|
smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
|
|
5
5
|
smartpi/flash.py,sha256=Luz0TjinQSkx31uVknqfSWkiAiVrqIE2Iba7lk3AOzM,4132
|
|
@@ -12,9 +12,9 @@ smartpi/move.py,sha256=3qzrJCGA-qbsLXBpklY2DErtw0jlzMELzozjhEvRzKs,6028
|
|
|
12
12
|
smartpi/servo.py,sha256=B6X3yCoEz82qqpUIE5MSO0Eg9YZJ5zDzJEcRpioZpUo,4625
|
|
13
13
|
smartpi/temperature.py,sha256=px2YeqgG63nPkyhJA1wDg3dwYx_oOCYuhMjtsVm_YO0,460
|
|
14
14
|
smartpi/touch_sensor.py,sha256=F6IIQGewNRhC9U1RbHpVzuGYqb8H41lpeQ1Ejwsc_T8,438
|
|
15
|
-
smartpi/trace.py,sha256=
|
|
15
|
+
smartpi/trace.py,sha256=dtZQAkUUIsq578hycwrfR9GJUsIUCbHCF4ZvJv9GLrs,984
|
|
16
16
|
smartpi/ultrasonic.py,sha256=0meczFKXFLUt92kLxipeEc37vb5duvJjPs4kgtlpO8M,622
|
|
17
|
-
smartpi-0.1.
|
|
18
|
-
smartpi-0.1.
|
|
19
|
-
smartpi-0.1.
|
|
20
|
-
smartpi-0.1.
|
|
17
|
+
smartpi-0.1.19.dist-info/METADATA,sha256=kViF6wYE4k68vEkBr0T8XPnoZGIN3gmP0d7sAulJItg,311
|
|
18
|
+
smartpi-0.1.19.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
19
|
+
smartpi-0.1.19.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
20
|
+
smartpi-0.1.19.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|