update python toolings

This commit is contained in:
2024-02-25 00:01:52 +01:00
parent 69a01f167e
commit 6508e6a07c
5 changed files with 84 additions and 31 deletions

View File

@@ -3,37 +3,12 @@ import struct
from google.protobuf.message import DecodeError
from serial.tools import list_ports
from firmware_pb2 import RequestDeviceList, Device, ResponseDeviceList, UsbPackageType
def make_header(typeid: UsbPackageType, length: int) -> bytearray:
struct_format = '<HHB' # '<' for little-endian, 'H' for uint16_t, 'B' for uint8_t
# Calculate the check byte as the sum of length and type
typeidint = int(typeid)
check = (length & 0xFF) + ((length >> 8) & 0xFF) + (typeidint & 0xFF) + ((typeidint >> 8) & 0xFF)
packed_data = struct.pack(struct_format, length, typeid, check)
return packed_data
def send_package(typeid : UsbPackageType, data: bytearray, serial: serial.Serial):
head = make_header(typeid, len(data))
package = head + data
serial.write(package)
from cls_device_pb2 import RequestDeviceList, Device, ResponseDeviceList
from usb_pb2 import UsbPackageType
from vcp_driver import *
if __name__ == "__main__":
stm_port = None
for port in list_ports.comports():
print(port)
if "STM32 Virtual ComPort" in port.description:
stm_port = port.device
break
if stm_port is None:
print("STM32 Virtual ComPort not found")
exit(-1)
else:
# Open the serial port
ser = serial.Serial(stm_port,baudrate=5000000)
ser = setup_connection()
# Create a RequestDeviceList message
request = RequestDeviceList()
request.msg = 1 # or whatever value you want to set