smartpi 0.1.42__py3-none-any.whl → 0.1.43__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 CHANGED
@@ -4,5 +4,5 @@ from .base_driver import P1, P2, P3, P4, P5, P6, M1, M2, M3, M4, M5, M6
4
4
  __all__ = ["base_driver","gui","ultrasonic","touch_sensor","temperature","humidity","light_sensor","color_sensor","motor","servo","led","flash",
5
5
  "P1", "P2", "P3", "P4", "P5", "P6", "M1", "M2", "M3", "M4", "M5", "M6"]
6
6
 
7
- __version__ = "0.1.42"
7
+ __version__ = "0.1.43"
8
8
 
smartpi/base_driver.py CHANGED
@@ -109,7 +109,7 @@ def uart3_init() -> Optional[serial.Serial]:
109
109
  def calculate_pro_check(command_h: int, command_l: int, data: List[bytes] = None) -> int:
110
110
  if data:
111
111
  len_data = len(data)
112
- base_sum = 0x86 + 0xAB + 0x00 + 0x09 + len_data + command_h + command_l + 0x01 + 0xCF
112
+ base_sum = 0x86 + 0xAB + (len_data+9)//256 + 0x09 + len_data + command_h + command_l + 0x01 + 0xCF
113
113
  base_sum += sum(data)
114
114
  else:
115
115
  base_sum = 0x86 + 0xAB + 0x00 + 0x09 + command_h + command_l + 0x01 + 0xCF
@@ -130,10 +130,10 @@ def write_data(command_h: int, command_l: int, send_data: bytes= None, lock: byt
130
130
  send_packet = [0x86, 0xAB, 0x00, 0x09, command_h, command_l, 0x01, pro_check, 0xCF]
131
131
  send_bytes = bytes(send_packet)
132
132
 
133
- print("send:")
134
- for x in send_bytes:
135
- print(f"{x:02X}", end=' ')
136
- print("\n")
133
+ # print("send:")
134
+ # for x in send_bytes:
135
+ # print(f"{x:02X}", end=' ')
136
+ # print("\n")
137
137
  buf_clear()
138
138
  serial_lock.acquire() #获取线程锁
139
139
  fcntl.flock(ser.fileno(), fcntl.LOCK_EX) #进程锁,阻塞其他进程
@@ -153,10 +153,10 @@ def write_data(command_h: int, command_l: int, send_data: bytes= None, lock: byt
153
153
  send_packet = [0x86, 0xAB, 0x00, 0x09, command_h, command_l, 0x01, pro_check, 0xCF]
154
154
  send_bytes = bytes(send_packet)
155
155
 
156
- print("send:")
157
- for x in send_bytes:
158
- print(f"{x:02X}", end=' ')
159
- print("\n")
156
+ # print("send:")
157
+ # for x in send_bytes:
158
+ # print(f"{x:02X}", end=' ')
159
+ # print("\n")
160
160
  buf_clear()
161
161
  ser.write(send_bytes)
162
162
 
@@ -197,6 +197,7 @@ def process_received_data():
197
197
  # for x in buffer:
198
198
  # print(f"{x:02X}", end=' ')
199
199
  # print("\n")
200
+
200
201
  # 1. 查找帧头
201
202
  start_idx = buffer.find(HEADER)
202
203
  if start_idx == -1:
@@ -230,6 +231,10 @@ def process_received_data():
230
231
  # 处理所有完整帧
231
232
  if len(frames_queue) > 0:
232
233
  frame = frames_queue.popleft()
234
+ # for x in frame:
235
+ # print(f"{x:02X}", end=' ')
236
+ # print("\n")
237
+
233
238
  if check_frame(frame):
234
239
  return frame
235
240
  else:
@@ -549,262 +554,7 @@ def buf_clear():
549
554
  fcntl.ioctl(ser.fileno(), termios.TCIOFLUSH)
550
555
  except:
551
556
  pass
552
-
553
-
554
- def enter_bootloader_mode():
555
- """进入Bootloader模式"""
556
- serial_lock.acquire() #获取线程锁
557
- fcntl.flock(ser.fileno(), fcntl.LOCK_EX) #进程锁,阻塞其他进程
558
- write_data(BOOT_UPDATE_H, BOOT_UPDATE_L, None, False)
559
- start_time = time.time()
560
- while True:
561
- response =process_received_data()
562
- if response:
563
- serial_lock.release() #释放线程锁
564
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
565
- buf_clear()
566
- print("get:")
567
- for x in response:
568
- print(f"{x:02X}", end=' ')
569
- print("\n")
570
- return True
571
- else:
572
- if time.time() - start_time > 2:
573
- print("读取超时")
574
- buf_clear()
575
- serial_lock.release() #释放线程锁
576
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
577
- return None
578
-
579
- def send_update_request():
580
- """发送更新请求"""
581
- serial_lock.acquire() #获取线程锁
582
- fcntl.flock(ser.fileno(), fcntl.LOCK_EX) #进程锁,阻塞其他进程
583
- write_data(UPDATE_REQUEST_H, UPDATE_REQUEST_L, None, False)
584
- start_time = time.time()
585
- while True:
586
- response = process_received_data()
587
- if response:
588
- serial_lock.release() #释放线程锁
589
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
590
- buf_clear()
591
- print("get:")
592
- for x in response:
593
- print(f"{x:02X}", end=' ')
594
- print("\n")
595
- return True
596
- else:
597
- if time.time() - start_time > 2:
598
- print("更新请求超时")
599
- buf_clear()
600
- serial_lock.release() #释放线程锁
601
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
602
- return None
603
-
604
- def send_file_size(file_size):
605
- """发送文件大小"""
606
- serial_lock.acquire() #获取线程锁
607
- fcntl.flock(ser.fileno(), fcntl.LOCK_EX) #进程锁,阻塞其他进程
608
-
609
- try:
610
- # 将文件大小转换为4字节小端序
611
- size_data = struct.pack('<I', file_size)
612
- write_data(MAX_COM_LEN_H, MAX_COM_LEN_L, size_data, False)
613
-
614
- start_time = time.time()
615
- while True:
616
- response = process_received_data()
617
- if response:
618
- serial_lock.release() #释放线程锁
619
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
620
- buf_clear()
621
- for x in response:
622
- print(f"{x:02X}", end=' ')
623
- print("\n")
624
- return True
625
- else:
626
- if time.time() - start_time > 2:
627
- print("发送文件大小超时")
628
- buf_clear()
629
- serial_lock.release() #释放线程锁
630
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
631
- return None
632
- except Exception as e:
633
- print(f"发送文件大小出错: {e}")
634
- serial_lock.release() #释放线程锁
635
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
636
- return None
637
-
638
- def send_file_data_chunk(chunk_data, chunk_num, total_chunks):
639
- """发送文件数据块"""
640
- serial_lock.acquire() #获取线程锁
641
- fcntl.flock(ser.fileno(), fcntl.LOCK_EX) #进程锁,阻塞其他进程
642
-
643
- try:
644
- write_data(PAGE_SEND_H, PAGE_SEND_L, chunk_data, False)
645
-
646
- start_time = time.time()
647
- while True:
648
- response = process_received_data()
649
- if response:
650
- serial_lock.release() #释放线程锁
651
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
652
- buf_clear()
653
- # 显示进度
654
- progress = (chunk_num + 1) * 100 // total_chunks
655
- if progress % 10 == 0 or chunk_num == total_chunks - 1:
656
- print(f"传输进度: {progress}% ({chunk_num+1}/{total_chunks})")
657
- return True
658
- else:
659
- if time.time() - start_time > 2:
660
- print(f"第{chunk_num+1}块数据发送超时")
661
- buf_clear()
662
- serial_lock.release() #释放线程锁
663
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
664
- return None
665
- except Exception as e:
666
- print(f"发送数据块出错: {e}")
667
- serial_lock.release() #释放线程锁
668
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
669
- return None
670
-
671
- def send_restart_command():
672
- """发送重启命令"""
673
- print("发送重启指令...")
674
- serial_lock.acquire()
675
- fcntl.flock(ser.fileno(), fcntl.LOCK_EX)
676
-
677
- try:
678
- # 发送重启命令 (0xFF 0xFF)
679
- write_data(0xFF, 0xFF, None, False)
680
-
681
- # 重启不需要等待响应,因为设备会立即重启
682
- time.sleep(0.5)
683
- print("重启指令已发送")
684
- return True
685
- except Exception as e:
686
- print(f"发送重启指令出错: {e}")
687
- return False
688
- finally:
689
- serial_lock.release()
690
- fcntl.flock(ser.fileno(), fcntl.LOCK_UN)
691
-
692
- def transmit_file_to_usb(file_path, chunk_size=512):
693
- """
694
- 传输文件到虚拟U盘的主函数
695
-
696
- Args:
697
- file_path: 要传输的文件路径
698
- chunk_size: 每个数据块的大小(默认512字节)
699
-
700
- Returns:
701
- bool: 传输是否成功
702
- """
703
- print("=" * 50)
704
- print("开始文件传输到虚拟U盘")
705
- print("=" * 50)
706
-
707
- # 检查文件是否存在
708
- if not os.path.exists(file_path):
709
- print(f"错误: 文件不存在 - {file_path}")
710
- return False
711
-
712
- # 获取文件大小
713
- try:
714
- file_size = os.path.getsize(file_path)
715
- print(f"文件: {os.path.basename(file_path)}")
716
- print(f"大小: {file_size} 字节")
717
- except Exception as e:
718
- print(f"获取文件大小出错: {e}")
719
- return False
720
-
721
- # 确保串口已初始化
722
- if not ser.is_open:
723
- print("初始化串口...")
724
- uart3_init()
725
- if not ser.is_open:
726
- print("串口初始化失败")
727
- return False
728
-
729
- # 1. 进入Bootloader模式
730
- enter_bootloader_mode()
731
-
732
- time.sleep(5)
733
-
734
- # 2. 发送更新请求
735
- if not send_update_request():
736
- print("更新请求失败,传输中止")
737
- return False
738
-
739
- # # 3. 发送文件大小
740
- # if not send_file_size(file_size):
741
- # print("文件大小发送失败,传输中止")
742
- # return False
743
- #
744
- # # 4. 读取并发送文件数据
745
- # print("开始传输文件数据...")
746
- # try:
747
- # with open(file_path, 'rb') as f:
748
- # total_chunks = (file_size + chunk_size - 1) // chunk_size
749
- #
750
- # for chunk_num in range(total_chunks):
751
- # # 读取数据块
752
- # chunk_data = f.read(chunk_size)
753
- # if not chunk_data:
754
- # print(f"错误: 第{chunk_num+1}块数据读取失败")
755
- # return False
756
- #
757
- # # 如果数据块不足chunk_size,填充0(可选)
758
- # if len(chunk_data) < chunk_size:
759
- # chunk_data += b'\x00' * (chunk_size - len(chunk_data))
760
- #
761
- # # 发送数据块
762
- # if not send_file_data_chunk(chunk_data, chunk_num, total_chunks):
763
- # print(f"第{chunk_num+1}块数据发送失败,传输中止")
764
- # return False
765
- #
766
- # print("文件数据传输完成!")
767
- #
768
- # except Exception as e:
769
- # print(f"读取或发送文件数据出错: {e}")
770
- # return False
771
- #
772
- # # 5. 发送重启命令
773
- # if not send_restart_command():
774
- # print("重启指令发送失败")
775
- # return False
776
- #
777
- # print("=" * 50)
778
- # print("文件传输成功完成!")
779
- # print("文件已保存到虚拟U盘")
780
- # print("设备将自动重启...")
781
- # print("=" * 50)
782
-
783
- # 等待设备重启
784
- time.sleep(3)
785
- return True
786
-
787
- def example_file_transfer():
788
- """文件传输使用示例"""
789
- print("文件传输示例")
790
- print("-" * 30)
791
-
792
- # 初始化串口
793
- uart3_init()
794
-
795
- # 指定要传输的文件路径
796
- # 请根据实际情况修改
797
- file_path = "/home/zmrobo/UPDATE.DAT"
798
-
799
- # 执行文件传输
800
- success = transmit_file_to_usb(file_path)
801
-
802
- if success:
803
- print("文件传输成功!")
804
- return 0
805
- else:
806
- print("文件传输失败!")
807
- return 1
557
+
808
558
 
809
559
  """H2-RCU初始化"""
810
560
  def smartpi_init():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smartpi
3
- Version: 0.1.42
3
+ Version: 0.1.43
4
4
  Summary: A library use for H2-RCU
5
5
  Author: ZMROBO
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,10 +1,10 @@
1
- smartpi/__init__.py,sha256=7AdxZqsEjhv8Ht_bLXOoF3T3jGZ0TEnG-SVYdjs4NR0,356
1
+ smartpi/__init__.py,sha256=YzlPmAHE6lnrGS7ChCmQYrfk9QZRPCNMlw46chQnWSY,356
2
2
  smartpi/_gui.py,sha256=ij-6HZAEIwdy_hvU7f0NkyQjx_-eephijlKbGUhf8Uo,2177
3
3
  smartpi/ai_asr.py,sha256=wxh_1Klh8vJottAt19jq3qpOmM_Cw4DHQEPKpsHGhmE,40063
4
4
  smartpi/ai_llm.py,sha256=-khBK2PMwbYUDvbaCTRCktE4dFloqfai4mHI-V8GEXM,36751
5
5
  smartpi/ai_tts.py,sha256=OjAJs3XOykiufXuEDiaD0coKsWjknPdhwRpRzGLDZKU,36061
6
6
  smartpi/ai_vad.py,sha256=9J1xxuKF8GvojkL_JuXv7_xE8bQAo5D49Xasi8piKK8,3630
7
- smartpi/base_driver.py,sha256=nGkGp7cAgeNo7BijHMJKHfdVZKIKuZNTx9GqLFPP5TI,31486
7
+ smartpi/base_driver.py,sha256=BwqgcYbQ9Rg8KiBJV2xy--NMNsMIg_zL-nnsAilCHJk,22687
8
8
  smartpi/camera.py,sha256=AVpZsMpW-24CP3BOfarjmRawMJdTOZY7Crq7FeLOqb4,3292
9
9
  smartpi/color_sensor.py,sha256=ckIXD81YnqPo6nENAnipNp3gY12FJ235QKj0e8Cul9E,521
10
10
  smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
@@ -70,7 +70,7 @@ smartpi/text_gte_model/config/tokenizer_config.json,sha256=w5RiDifbeIYy6vyGX5v94
70
70
  smartpi/text_gte_model/config/vocab.txt,sha256=oi9hP3uz_8h8XoHNh6rgLnVdJbIEm75zKoSKM8HzsC8,84758
71
71
  smartpi/text_gte_model/gte/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
72
72
  smartpi/text_gte_model/gte/gte_model.onnx,sha256=XXYg6TUhzOx1SqAhp6ePDU0QgeK6DQEqHATMuQQJCNE,30468366
73
- smartpi-0.1.42.dist-info/METADATA,sha256=FxIXEB2WMTsKc8Fs8ukVfdnD3--vqy7fOEXFT5AQLq8,614
74
- smartpi-0.1.42.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
75
- smartpi-0.1.42.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
76
- smartpi-0.1.42.dist-info/RECORD,,
73
+ smartpi-0.1.43.dist-info/METADATA,sha256=Itx-zHFW2xLOdYkd5UgHu7EKImJObZdgVXD-yduwt7c,614
74
+ smartpi-0.1.43.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
75
+ smartpi-0.1.43.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
76
+ smartpi-0.1.43.dist-info/RECORD,,