14
14
from pymavlink import mavutil
15
15
16
16
# import pymavlink.dialects.v20.ardupilotmega
17
+ from MethodicConfigurator import _
18
+ from MethodicConfigurator .middleware_fc_ids import (
19
+ APJ_BOARD_ID_NAME_DICT ,
20
+ APJ_BOARD_ID_VENDOR_DICT ,
21
+ VID_PID_PRODUCT_DICT ,
22
+ VID_VENDOR_DICT ,
23
+ )
17
24
18
25
19
26
class BackendFlightcontrollerInfo : # pylint: disable=too-many-instance-attributes
@@ -29,10 +36,12 @@ def __init__(self) -> None:
29
36
self .component_id : str = ""
30
37
self .autopilot : str = ""
31
38
self .vehicle_type : str = ""
39
+ self .firmware_type : str = ""
32
40
self .mav_type : str = ""
33
41
self .flight_sw_version : str = ""
34
42
self .flight_sw_version_and_type : str = ""
35
43
self .board_version : str = ""
44
+ self .apj_board_id : str = ""
36
45
self .flight_custom_version : str = ""
37
46
self .os_custom_version : str = ""
38
47
self .vendor : str = ""
@@ -48,18 +57,20 @@ def __init__(self) -> None:
48
57
49
58
def get_info (self ) -> dict [str , Union [str , dict [str , str ]]]:
50
59
return {
51
- "Vendor" : self .vendor_and_vendor_id ,
52
- "Product" : self .product_and_product_id ,
53
- "Hardware Version" : self .board_version ,
54
- "Autopilot Type" : self .autopilot ,
55
- "ArduPilot FW Type" : self .vehicle_type ,
56
- "MAV Type" : self .mav_type ,
57
- "Firmware Version" : self .flight_sw_version_and_type ,
58
- "Git Hash" : self .flight_custom_version ,
59
- "OS Git Hash" : self .os_custom_version ,
60
- "Capabilities" : self .capabilities ,
61
- "System ID" : self .system_id ,
62
- "Component ID" : self .component_id ,
60
+ _ ("USB Vendor" ): self .vendor_and_vendor_id ,
61
+ _ ("USB Product" ): self .product_and_product_id ,
62
+ _ ("Board Type" ): self .apj_board_id ,
63
+ _ ("Hardware Version" ): self .board_version ,
64
+ _ ("Autopilot Type" ): self .autopilot ,
65
+ _ ("ArduPilot Vehicle Type" ): self .vehicle_type ,
66
+ _ ("ArduPilot FW Type" ): self .firmware_type ,
67
+ _ ("MAV Type" ): self .mav_type ,
68
+ _ ("Firmware Version" ): self .flight_sw_version_and_type ,
69
+ _ ("Git Hash" ): self .flight_custom_version ,
70
+ _ ("OS Git Hash" ): self .os_custom_version ,
71
+ _ ("Capabilities" ): self .capabilities ,
72
+ _ ("System ID" ): self .system_id ,
73
+ _ ("Component ID" ): self .component_id ,
63
74
}
64
75
65
76
def set_system_id_and_component_id (self , system_id : str , component_id : str ) -> None :
@@ -80,29 +91,28 @@ def set_flight_sw_version(self, version: int) -> None:
80
91
self .flight_sw_version_and_type = self .flight_sw_version + " " + v_fw_type
81
92
82
93
def set_board_version (self , board_version : int ) -> None :
83
- self .board_version = str (board_version )
94
+ self .board_version = str (board_version & 0x0FFFF )
95
+ apj_board_id = board_version >> 16
96
+ self .apj_board_id = str (apj_board_id )
97
+ self .firmware_type = str (APJ_BOARD_ID_NAME_DICT .get (apj_board_id , _ ("Unknown" )))
98
+
99
+ vendor_derived_from_apj_board_id = str (APJ_BOARD_ID_VENDOR_DICT .get (apj_board_id , "ArduPilot" ))
100
+ if vendor_derived_from_apj_board_id != "ArduPilot" and self .vendor in ["ArduPilot" , _ ("Unknown" )]:
101
+ self .vendor = vendor_derived_from_apj_board_id
84
102
85
103
def set_flight_custom_version (self , flight_custom_version : Sequence [int ]) -> None :
86
104
self .flight_custom_version = "" .join (chr (c ) for c in flight_custom_version )
87
105
88
106
def set_os_custom_version (self , os_custom_version : Sequence [int ]) -> None :
89
107
self .os_custom_version = "" .join (chr (c ) for c in os_custom_version )
90
108
91
- def set_vendor_id_and_product_id (self , vendor_id : int , product_id : int ) -> None :
92
- pid_vid_dict = self .__list_ardupilot_supported_usb_pid_vid ()
93
-
94
- self .vendor_id = f"0x{ vendor_id :04X} " if vendor_id else "Unknown"
95
- if vendor_id and vendor_id in pid_vid_dict :
96
- self .vendor = f"{ pid_vid_dict [vendor_id ]['vendor' ]} "
97
- elif vendor_id :
98
- self .vendor = "Unknown"
109
+ def set_usb_vendor_and_product_ids (self , vendor_id : int , product_id : int ) -> None :
110
+ self .vendor_id = f"0x{ vendor_id :04X} " if vendor_id else _ ("Unknown" )
111
+ self .vendor = str (VID_VENDOR_DICT .get (vendor_id , _ ("Unknown" )))
99
112
self .vendor_and_vendor_id = f"{ self .vendor } ({ self .vendor_id } )"
100
113
101
- self .product_id = f"0x{ product_id :04X} " if product_id else "Unknown"
102
- if vendor_id and product_id and product_id in pid_vid_dict [vendor_id ]["PID" ]:
103
- self .product = f"{ pid_vid_dict [vendor_id ]['PID' ][product_id ]} "
104
- elif product_id :
105
- self .product = "Unknown"
114
+ self .product_id = f"0x{ product_id :04X} " if product_id else _ ("Unknown" )
115
+ self .product = str (VID_PID_PRODUCT_DICT .get ((vendor_id , product_id ), _ ("Unknown" )))
106
116
self .product_and_product_id = f"{ self .product } ({ self .product_id } )"
107
117
108
118
def set_capabilities (self , capabilities : int ) -> None :
@@ -234,49 +244,3 @@ def __classify_vehicle_type(mav_type_int: int) -> str:
234
244
235
245
# Return the classified vehicle type based on the MAV_TYPE enum
236
246
return mav_type_to_vehicle_type .get (mav_type_int , "" )
237
-
238
- @staticmethod
239
- def __list_ardupilot_supported_usb_pid_vid () -> dict [int , dict [str , Union [str , dict [int , str ]]]]:
240
- """
241
- List all ArduPilot supported USB vendor ID (VID) and product ID (PID).
242
-
243
- source: https://ardupilot.org/dev/docs/USB-IDs.html
244
- """
245
- return {
246
- 0x0483 : {"vendor" : "ST Microelectronics" , "PID" : {0x5740 : "ChibiOS" }},
247
- 0x1209 : {
248
- "vendor" : "ArduPilot" ,
249
- "PID" : {
250
- 0x5740 : "MAVLink" ,
251
- 0x5741 : "Bootloader" ,
252
- },
253
- },
254
- 0x16D0 : {"vendor" : "ArduPilot" , "PID" : {0x0E65 : "MAVLink" }},
255
- 0x26AC : {"vendor" : "3D Robotics" , "PID" : {}},
256
- 0x2DAE : {
257
- "vendor" : "CubePilot" ,
258
- "PID" : {
259
- 0x1001 : "CubeBlack bootloader" ,
260
- 0x1011 : "CubeBlack" ,
261
- 0x1101 : "CubeBlack+" ,
262
- 0x1002 : "CubeYellow bootloader" ,
263
- 0x1012 : "CubeYellow" ,
264
- 0x1005 : "CubePurple bootloader" ,
265
- 0x1015 : "CubePurple" ,
266
- 0x1016 : "CubeOrange" ,
267
- 0x1058 : "CubeOrange+" ,
268
- 0x1059 : "CubeRed" ,
269
- },
270
- },
271
- 0x3162 : {"vendor" : "Holybro" , "PID" : {0x004B : "Durandal" }},
272
- 0x27AC : {
273
- "vendor" : "Laser Navigation" ,
274
- "PID" : {
275
- 0x1151 : "VRBrain-v51" ,
276
- 0x1152 : "VRBrain-v52" ,
277
- 0x1154 : "VRBrain-v54" ,
278
- 0x1910 : "VRCore-v10" ,
279
- 0x1351 : "VRUBrain-v51" ,
280
- },
281
- },
282
- }
0 commit comments