update python tools to new proto names

This commit is contained in:
2024-02-25 19:51:41 +01:00
parent b09924b9c8
commit 85e08d31be
4 changed files with 49 additions and 49 deletions

View File

@@ -3,21 +3,21 @@ import struct
from google.protobuf.message import DecodeError
from serial.tools import list_ports
from cls_device_pb2 import RequestDeviceList, Device, ResponseDeviceList
from usb_pb2 import UsbPackageType
from cls_device_pb2 import RequestList, Device, ResponseList
from usb_pb2 import PackageType
from vcp_driver import *
if __name__ == "__main__":
ser = setup_connection()
# Create a RequestDeviceList message
request = RequestDeviceList()
request = RequestList()
request.msg = 1 # or whatever value you want to set
# Serialize the request to a bytearray
request_data = request.SerializeToString()
# Send the request
send_package(UsbPackageType.REQUEST_DEVICE_LIST, request_data, ser)
send_package(PackageType.REQUEST_DEVICE_LIST, request_data, ser)
# Now wait for the response
while True:
@@ -28,13 +28,13 @@ if __name__ == "__main__":
length, typeid, check = struct.unpack('<HHB', response_header)
# Check if the type is RESPONSE_DEVICE_LIST
if typeid == UsbPackageType.RESPONSE_DEVICE_LIST:
if typeid == PackageType.RESPONSE_DEVICE_LIST:
# Read the response data from the serial port
response_data = ser.read(length)
# Try to parse the data as a ResponseDeviceList message
try:
response = ResponseDeviceList.FromString(response_data)
response = ResponseList.FromString(response_data)
# If we get here, we successfully parsed the response. Break the loop.
break
except DecodeError: