norberttak / XPanel

XPlane 11/12 plugin to handle home cockpit panels
GNU General Public License v3.0
8 stars 3 forks source link

[BUG] hid_send_feature_report error on Gentoo Linux #90

Closed CyberGuerro closed 5 months ago

CyberGuerro commented 5 months ago

Describe the bug With attached xpanel.ini and Saitek Radio Panel connected to USB, plugin crash and x-plane with it

To Reproduce Steps to reproduce the behavior like this:

  1. Attach saitek device
  2. Run X-Plane12 and select aircraft (ZIBO 4.01.9)
  3. Start flight
  4. X-Plane crash

Expected behavior Flight start

X-Plane log file Log.txt

xpanel.ini content:

; Aircraft specific handler for Zibo 737 XPlane aircraft
log_level="DEBUG"
aircraft_acf="b738_4k.acf"

;---------------------- Saitek Radio Panel -------------------------
[device:id="saitek_radio"]
vid="6a3"
pid="d05"

[multi_display:id="RADIO_DISPLAY_ACTIVE_UP"]
line="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_freq_hz"
line="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_freq_hz"
line="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_freq_hz"
line="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_freq_hz"
line="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_freq_hz"
line="on_select:SW_UP_IDT,dataref:sim/cockpit/radios/transponder_code"

[multi_display:id="RADIO_DISPLAY_STBY_UP"]
line="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz"
line="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz"
line="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz"
line="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz"
line="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz"

[button:id="KNOB_UP_BIG_PLUS"]
on_push="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:100:0:359"
on_push="on_select:SW_UP_IDT,dataref:sim/cockpit/radios/transponder_code:100:0:8888"

[button:id="KNOB_UP_BIG_MINUS"]
on_push="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:-100:0:359"
on_push="on_select:SW_UP_IDT,dataref:sim/cockpit2/radios/actuators/transponder_code:-100:0:8888"

[button:id="KNOB_UP_SMALL_PLUS"]
on_push="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:5:0:15000"
on_push="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:5:0:15000"
on_push="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:1:0:15000"
on_push="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:1:0:15000"
on_push="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:1:0:359"
on_push="on_select:SW_UP_IDT,dataref:sim/cockpit/radios/transponder_code:1:0:8888"

[button:id="KNOB_UP_SMALL_MINUS"]
on_push="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:-5:0:16000"
on_push="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:-5:0:16000"
on_push="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:-1:0:16000"
on_push="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:-1:0:16000"
on_push="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:-1:0:359"
on_push="on_select:SW_UP_IDT,dataref:sim/cockpit2/radios/actuators/transponder_code:-1:0:8888"

[button:id="ACT_STBY_UP"]
on_push="on_select:SW_UP_COM1,commandref:sim/radios/com1_standy_flip:once"
on_push="on_select:SW_UP_COM2,commandref:sim/radios/com2_standy_flip:once"
on_push="on_select:SW_UP_NAV1,commandref:sim/radios/nav1_standy_flip:once"
on_push="on_select:SW_UP_NAV2,commandref:sim/radios/nav2_standy_flip:once"
on_push="on_select:SW_UP_ADF,commandref:sim/radios/adf1_standy_flip:once"

[multi_display:id="RADIO_DISPLAY_ACTIVE_DOWN"]
line="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_freq_hz"
line="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_freq_hz"
line="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_freq_hz"
line="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_freq_hz"
line="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_freq_hz"
line="on_select:SW_DOWN_IDT,dataref:sim/cockpit/radios/transponder_code"

[multi_display:id="RADIO_DISPLAY_STBY_DOWN"]
line="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz"
line="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz"
line="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz"
line="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz"
line="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz"

[button:id="KNOB_DOWN_BIG_PLUS"]
on_push="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:100:0:359"
on_push="on_select:SW_DOWN_IDT,dataref:sim/cockpit/radios/transponder_code:100:0:8888"

[button:id="KNOB_DOWN_BIG_MINUS"]
on_push="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:-100:0:359"
on_push="on_select:SW_DOWN_IDT,dataref:sim/cockpit2/radios/actuators/transponder_code:-100:0:8888"

[button:id="KNOB_DOWN_SMALL_PLUS"]
on_push="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:5:0:15000"
on_push="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:5:0:15000"
on_push="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:1:0:15000"
on_push="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:1:0:15000"
on_push="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:1:0:359"
on_push="on_select:SW_DOWN_IDT,dataref:sim/cockpit/radios/transponder_code:1:0:8888"

[button:id="KNOB_DOWN_SMALL_MINUS"]
on_push="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:-5:0:16000"
on_push="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:-5:0:16000"
on_push="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:-1:0:16000"
on_push="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:-1:0:16000"
on_push="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:-1:0:359"
on_push="on_select:SW_DOWN_IDT,dataref:sim/cockpit2/radios/actuators/transponder_code:-1:0:8888"

[button:id="ACT_STBY_DOWN"]
on_push="on_select:SW_DOWN_COM1,commandref:sim/radios/com1_standy_flip:once"
on_push="on_select:SW_DOWN_COM2,commandref:sim/radios/com2_standy_flip:once"
on_push="on_select:SW_DOWN_NAV1,commandref:sim/radios/nav1_standy_flip:once"
on_push="on_select:SW_DOWN_NAV2,commandref:sim/radios/nav2_standy_flip:once"
on_push="on_select:SW_DOWN_ADF,commandref:sim/radios/adf1_standy_flip:once"

List of usb devices connected before run X-Plane12

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 1462:7d25 Micro Star International MYSTIC LIGHT 
Bus 001 Device 003: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 006: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 009: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 001 Device 010: ID 058f:6364 Alcor Micro Corp. AU6477 Card Reader Controller
Bus 001 Device 033: ID 043e:9a10 LG Electronics USA, Inc. ASM107x
Bus 001 Device 034: ID 131d:0159 Natural Point 
Bus 001 Device 041: ID 05e3:0610 Genesys Logic, Inc. Hub
Bus 001 Device 042: ID 06a3:0d05 Saitek PLC Pro Flight Radio Panel
Bus 001 Device 043: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 044: ID 03f0:e807 HP, Inc HP Webcam HD 4310
Bus 001 Device 045: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 05e3:0616 Genesys Logic, Inc. hub

Desktop (please complete the following information):

norberttak commented 5 months ago

It's strange that between the device connect and the first send_feature_report error your PC spend more than 5 seconds

XPanel [45982] [DEBUG]:device connect: vid=1699 pid=3333
XPanel [51488] [DEBUG]:error in UsbHidDevice::send_feature_report reason=ioctl (SFEATURE): Connessione scaduta
XPanel [51490] [DEBUG]:SaitekRadioPanel connect. successful

On my PC (which is a much less powerful compared to yours) it is only 5 ms (not seconds but milliseconds)

XPanel [12347] [DEBUG]:device connect: vid=1699 pid=3333
XPanel [12351] [DEBUG]:SaitekRadioPanel connect. successful

What I see is that you have a lot of custom scenaries what are loaded at almost the same time as XPanel plugin loads. Maybe it overloads your PC and the plugin can't get the time to communicate with the USB devices? I know it sounds very strange. I would like to do two tests:

  1. I created a plugin version that delays any USB message handling for 10 seconds after plugin loads. It means that in the first 10 seconds it seems not working so please wait the time before testing the devices. lin-delay-10sec.zip
  2. I don't know whether it is possible or not but for a test it would be nice to disable every custom scenaries.
CyberGuerro commented 5 months ago

Remove all custom sceneries, using your lin-delay-10sec version, tested with only 1 radio device: NOT WORKING, same error. Atteched Log.txt

norberttak commented 5 months ago

I did a USB communication capture on my Ubuntu box. I'd like to ask you to do the same tests on your system as well:

  1. install wireshark sudo apt install wireshark
  2. enable usbmon kernel modul: sudo modprobe usbmon
  3. list your USB devices:
    norbi@norbi-linux:~$ lsusb
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 001 Device 007: ID 413c:2110 Dell Computer Corp. Dell Wired Multimedia Keyboard
    Bus 001 Device 004: ID 413c:1010 Dell Computer Corp. USB 2.0 Hub [MTT]
    Bus 001 Device 003: ID 06a3:a2ae Saitek PLC Pro Flight Instrument Panel
    Bus 001 Device 014: ID 06a3:0d67 Saitek PLC Pro Flight Switch Panel
    Bus 001 Device 011: ID 044f:b679 ThrustMaster, Inc. T-Rudder
    Bus 001 Device 008: ID 06a3:0d06 Saitek PLC Flight Pro Multi Panel
    Bus 001 Device 005: ID 06a3:0d05 Saitek PLC Pro Flight Radio Panel
    Bus 001 Device 002: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub             
    Bus 001 Device 013: ID 0b05:1939 ASUSTek Computer, Inc. AURA LED Controller
    Bus 001 Device 009: ID 05e3:0610 Genesys Logic, Inc. Hub
    Bus 001 Device 012: ID 06a3:0bac Saitek PLC Pro Flight Yoke
    Bus 001 Device 010: ID 0461:4d81 Primax Electronics, Ltd Dell N889 Optical Mouse
    Bus 001 Device 015: ID 0b0e:0300 GN Netcom Jabra EVOLVE 20 SE MS
    Bus 001 Device 006: ID 06a3:712c Saitek PLC Pro Flight Yoke integrated hub
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  4. My radio panel is on the USB Bus 001, and it has device ID 005. Note these values.
  5. Start wireshark sudo wireshark and select the USB bus to capture (in my case it was 001 according to the previous point)
  6. Apply this filter in wireshark: usb.dst contains "1.5." || usb.src contains "1.5." here the 1.5 means bus 1 and device 5 (according to lsusb output). Modify the filter according to your bus/device id.
  7. Start packet capturing in wireshark
  8. Start XPlane and load the Cessna 172. Do not touch any button, knob on saitek devices. After about 1 minute stop capturing packets in wireshark.
  9. Stop XPlane simulator

This is the captured USB frames in my system: Screenshot from 2024-04-05 18-46-54 The SET_REPORT_REQUEST is when my plugin initialize the radio panel. That's the point where you get the timeout error messages.

I'm really curious what traffic is captured on your system. If you have time I'd like to see the same tests with XSaitek panel plugin as well.

Please use the lin-delay-10sec version for your tests.

CyberGuerro commented 5 months ago

Tests done. This is my usb lists:

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 1462:7d25 Micro Star International MYSTIC LIGHT 
Bus 001 Device 003: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 004: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 005: ID 05e3:0610 Genesys Logic, Inc. Hub
Bus 001 Device 006: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 007: ID 058f:6364 Alcor Micro Corp. AU6477 Card Reader Controller
Bus 001 Device 008: ID 043e:9a10 LG Electronics USA, Inc. ASM107x
Bus 001 Device 009: ID 03f0:e807 HP, Inc HP Webcam HD 4310
Bus 001 Device 010: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 001 Device 011: ID 131d:0159 Natural Point 
Bus 001 Device 012: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 013: ID 06a3:0d05 Saitek PLC Pro Flight Radio Panel
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 002: ID 05e3:0616 Genesys Logic, Inc. hub

This is my wireshark filter: usb.dst contains "1.13." || usb.src contains "1.13." (my device's id is 13 on bus 001)

Attached: XPanel.zip Xsaitekpanels.zip

I hope these help you

norberttak commented 5 months ago

Thanks for the tests. What I see:

  1. it seems Saitek changed something in the firmware because the HID descriptor in your Radio HW is different what I have. I'm not sure it is important or not.
  2. XSaitek Panel sends the first feature report with the very first byte set to 0. According to Linux kernel source if it is 0 then kernel truncates the report size. That's what I see in comparison with XSaitek panel and my plugin's feature report (my plugin try to send 23 bytes while Xsaitek panel only 22 bytes). The Radio panel response for my 23 byte long message with a
    URB status: No such file or directory (-ENOENT) (-2)

    It could be the root cause of the issue. I'm not sure but it seems a problem. On the other hand I don't understand how it works both on my Linux and Windows. Anyways, I created a new version where I set the first byte of the feature report strictly to 0. Could you please test this please?

CyberGuerro commented 5 months ago

GREAT NEWS!!!! Now it works: no more errors and display, buttons and knobs work..... .....BUT... ....if I connect only 1 radio it works as expected, but if I connect all my 3 radio devices, all 3 devices's display show same things (Top-Left display of first, second and third devices shows same thing, top-right same thing on all 3 devices and so on) and 3 devices are setted as below:

device 1 upper: COM1
device 1 lower: COM 2
device 2 upper: NAV 1
device 2 lower: NAV 2
device 3 upper: ADF
device 3 lower: XPDR

If I turn device 1 knobs, sometimes display of device 1 change, sometimes display of device 2, sometimes display of device 3. Same thing if I use knobs of device 2 or device 3.

I think that now the plugin have to distinguish the device when there are multiple devices of the same type.

norberttak commented 5 months ago

that's great news :-)

let me check what causes the mixing of more than one radio devices. If you don't mind I close this Issue and open a new one for the multi radio issue.

norberttak commented 5 months ago

Followup of the multi radio devices bug: #99