Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement connection manager. #1031

Merged
merged 35 commits into from
Jan 10, 2025
Merged

Implement connection manager. #1031

merged 35 commits into from
Jan 10, 2025

Conversation

kareltucek
Copy link
Collaborator

@kareltucek kareltucek commented Dec 15, 2024

This contains a refactor of connection handling - both host connections and other connections (like bridge) are now managed by one central module.

Changes:

  • Implemented switchover. (If host connection's checkbox is checked, then the UHK automatically switches over to this host when connection is established, irrespectively of its place in hist connection list.)
  • When a connection is disconnected, UHK switches over to the connection that is currently connected and highest in the host connection list.
  • Oled now shows host connection's name.
  • Multiple dongles can be connected at the same time.
  • switchHost { next | previous | last } macro can be used to iterate over connected hosts (blue dongles)
  • switchHost "name" can be used to select a specific host connection (i.e., blue and violet dongles) to connect to even when the host is not connected (e.g., because there are more active dongles than the available peripheral connection slots) . In such case, the least recently used host is disconnected, and advertisement is started with a whitelist for the one selected host.
  • Ble HID connections now break UHK.
  • New color scheme for dongle leds:
    • Red "Disconnected": the dongle is not paired to any UHK.
    • Violet "Trying to connect": the dongle trying to connect to the paired UHK.
    • Blue "Standby": the dongle is connected to its UHK, but is not selected as the active host on UHK side.
    • Green "Active": this dongle is the current target host connection.

Please note the CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT prj.conf value and experiment with it. Reasonable values are 1, 2, and 3. In practice, it means the number of dongles that can be in blue and green modes at the same time.

With 1 the switchover takes around 1 second and switching over is done by disconnecting current dongle, applying an allow list filter, and starting advertising with that list, which however doesn't work very well in practice, as the dongles try to connect anyways. (The upside is that keeping a list of active dongles wouldn't be hard.)
With 2 or more, the user experience is a bit better, but I fear decreased responsivity. In this case, either all dongles can be connected in standby (blue) (if their number is smaller than the connection count), or some blue, some violet, and the whitelist approach is in practice used on one free slot obtained by disconnecting one of the blue dongles.

Known issues / missing features:

  • We are not trying to keep a list of connectable devices (e.g., violet dongles) based on their scanning inquiries or connection attempts (yet). As a result, only blue dongles can be reached via switchHost next. Violet dongles can still be reached by (e.g.) switchHost "MyDevDongle".
  • When there is a Bt Hid connection, Usb is not available.

Closes #1021
Closes #980

@mondalaci
Copy link
Member

@kareltucek I delay reviewing this until Benedek's PR is merged unless you say otherwise.

@kareltucek
Copy link
Collaborator Author

Yes, this will need reworking.

@kareltucek kareltucek force-pushed the host-routing branch 4 times, most recently from 6b17356 to 3343c07 Compare December 22, 2024 17:49
@mondalaci
Copy link
Member

When renaming the current connection and saving the configuration, the new name doesn't get reflected on the OLED display.

When connecting my production dongle to USB, the OLED display switches to disconnected, HID events don't have any effect, and the following is shown in the Zephyr log upon every HID event:

Failed to send message from right to dongle
Can't send report - selected connection is not ready!

Simultaneously, Agent displays the following, which shouldn't be displayed:

Screenshot from 2024-12-23 21-54-42

@kareltucek
Copy link
Collaborator Author

What do you mean by "production dongle"? You mean that you haven't updated it to the corresponding branch firmware? If so, which commit are they running?

@kareltucek
Copy link
Collaborator Author

kareltucek commented Dec 23, 2024

Also, have you tried to delete the connection and pair it again?

@mondalaci
Copy link
Member

I'm on the tip of the host-routing branch. Previously, I forgot to flash my dongle, but now I did, and I re-paired my dongle.

Experience various issues regarding connection switching. I haven't used the mentioned macro commands yet. Please try to connect/disconnect your UHK 80 / dongle via USB, which should trigger the following when pressing keys:

Failed to send data over BLE connection (err: -22)

or

Failed to send message from right to dongle
Can't send report - selected connection is not ready!

When seeing the above errors, my UHK usually doesn't send events to the host, and sometimes the mouse interface froze. Can you reproduce these issues?

@kareltucek
Copy link
Collaborator Author

Can you reproduce these issues?

No. Please try to give more detailed reproduction steps. And maybe more log context.

@mondalaci
Copy link
Member

Please merge master into this branch because Agent shows:

image

@mondalaci
Copy link
Member

mondalaci commented Dec 28, 2024

When the user configuration is empty, the UHK 80 is disconnected, even after reboot or after reconnecting USB. No wireless devices have ever been paired until this point.

*** Using Zephyr OS v3.7.99-37939f03cb6f ***
----------
UHK 80 right half started
Enabling UART

uhk8I: 3 Sectors of 4096 bytes
I: alloc wra: 0, fe8
I: data wra: 0, 0
I: SoftDevice Controller build revision: 
I: fe 2c f9 6a 7f 36 22 2e |.,.j.6".
I: a0 79 c0 40 be 2c 03 20 |.y.@.,. 
I: 40 c2 f3 32             |@..2    
I: HW Platform: Nordic Semiconductor (0x0002)
I: HW Variant: nRF52x (0x0002)
I: Firmware: Standard Bluetooth controller (0x00) Version 254.63788 Build 573996906
I: No ID address. App must call settings_load()
I: Identity: EA:5C:DD:BC:10:F4 (random)
I: HCI: version 6.0 (0x0e) revision 0x104e, manufacturer 0x0059
I: LMP: version 6.0 (0x0e) subver 0x104e
Reading hardware config
Reading user config
Applying user config
Resetting left right link! Unidirectional
Resetting left right link! Bidirectional
User config applied
 === Usb Enable Hid
NUS Server module initialized.
Scan module initialized
NUS Client module initialized
Starting bluetooth services.
Setting no advertising filter
NUS and HID advertising successfully started
Scanning successfully started
USB config changing to Hid_Full
Resetting left right link! Unidirectional
Supplied connection (0) doesn't correspond to a host connection!
0:right$  === set transport usb
Connection state: UsbHidRight(Ready)
Connection state: UartLeft(Ready)
Resetting left right link! Bidirectional
Can't send report - selected connection is not ready!
Failed to send message from right to dongle
Can't send report - selected connection is not ready!
Failed to send message from right to dongle
USB: requesting remote wakeup
USB: remote wakeup disabled
Can't send report - selected connection is not ready!
Failed to send message from right to dongle
Can't send report - selected connection is not ready!
Failed to send message from right to dongle
Can't send report - selected connection is not ready!
Failed to send message from right to dongle
Can't send report - selected connection is not ready!
Failed to send message from right to dongle

@mondalaci
Copy link
Member

Upon trying to pair my dongle, Agent errors out with "Cannot write to hid device".

Agent log:

19:15:26.383 › [DeviceService] start Dongle pairing
19:15:26.383 › [DeviceService] stop poll UHK Device
19:15:26.483 › [DeviceService] stopped poll UHK Device
19:15:26.507 › [UhkHidDevice] protocol versions: {"firmwareVersion":"12.1.0","deviceProtocolVersion":"4.12.0","moduleProtocolVersion":"4.3.0","userConfigVersion":"8.3.0","hardwareConfigVersion":"1.0.0","smartMacrosVersion":"3.0.0"}
19:15:26.514 › [DeviceOperation] Device BLE address:  f4:10:bc:dd:5c:ea
19:15:26.526 › [UhkHidDevice] Available devices changed.
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x5","path":"/dev/hidraw25","serialNumber":"4294967295","manufacturer":"Ultimate Gadget Laboratories","product":"UHK dongle","release":1,"interface":0,"usagePage":1,"usage":6}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x5","path":"/dev/hidraw27","serialNumber":"4294967295","manufacturer":"Ultimate Gadget Laboratories","product":"UHK dongle","release":1,"interface":2,"usagePage":65280,"usage":1}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x5","path":"/dev/hidraw28","serialNumber":"4294967295","manufacturer":"Ultimate Gadget Laboratories","product":"UHK dongle","release":1,"interface":3,"usagePage":12,"usage":1}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x5","path":"/dev/hidraw29","serialNumber":"4294967295","manufacturer":"Ultimate Gadget Laboratories","product":"UHK dongle","release":1,"interface":4,"usagePage":1,"usage":5}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x7","path":"/dev/hidraw8","serialNumber":"1502518868","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 left half","release":1,"interface":0,"usagePage":1,"usage":6}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x7","path":"/dev/hidraw10","serialNumber":"1502518868","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 left half","release":1,"interface":2,"usagePage":65280,"usage":1}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x7","path":"/dev/hidraw11","serialNumber":"1502518868","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 left half","release":1,"interface":3,"usagePage":12,"usage":1}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x7","path":"/dev/hidraw17","serialNumber":"1502518868","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 left half","release":1,"interface":4,"usagePage":1,"usage":128}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x7","path":"/dev/hidraw18","serialNumber":"1502518868","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 left half","release":1,"interface":5,"usagePage":1,"usage":5}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw19","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":0,"usagePage":1,"usage":6}
19:15:26.526 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw21","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":2,"usagePage":65280,"usage":1}
19:15:26.527 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw22","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":3,"usagePage":12,"usage":1}
19:15:26.527 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw23","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":4,"usagePage":1,"usage":128}
19:15:26.527 › [UhkHidDevice] Added: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw24","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":5,"usagePage":1,"usage":5}
19:15:26.579 › [UhkHidDevice] Used device: {"vendorId":"0x37A8","productId":"0x5","path":"/dev/hidraw27","serialNumber":"4294967295","manufacturer":"Ultimate Gadget Laboratories","product":"UHK dongle","release":1,"interface":2,"usagePage":65280,"usage":1}
19:15:26.586 › [UhkHidDevice] protocol versions: {"firmwareVersion":"12.1.0","deviceProtocolVersion":"4.12.0","moduleProtocolVersion":"4.3.0","userConfigVersion":"8.3.0","hardwareConfigVersion":"1.0.0","smartMacrosVersion":"3.0.0"}
19:15:26.594 › [DeviceOperation] Dongle BLE address:  25:ee:11:38:e0:dc
19:15:26.594 › [DeviceOperation] Device switching to pairing mode
19:15:26.618 › [DeviceOperation] Dongle switching to pairing mode
19:15:26.634 › [DeviceOperation] Device delete dongle bond
19:15:26.650 › [DeviceOperation] Dongle delete all bonds
19:15:26.658 › [DeviceOperation] Device read pairing info
19:15:26.666 › [DeviceOperation] Dongle read pairing info
19:15:26.674 › [DeviceOperation] Device set pairing info
19:15:26.682 › [DeviceOperation] Dongle set pairing info
19:15:26.690 › [DeviceOperation] Device pair peripheral
19:15:26.714 › [DeviceOperation] Dongle pair central
19:15:26.730 › [DeviceOperation] Device waiting for pairing finished
19:15:27.065 › [UhkHidDevice] Transfer error:  TypeError: Cannot write to hid device
    at /home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:474200
19:15:27.066 › [UhkHidDevice] Device communication closing.
19:15:27.067 › [UhkHidDevice] Device communication closed.
19:15:27.069 › [UhkHidDevice] Device communication closing.
19:15:27.071 › [UhkHidDevice] Device communication closed.
19:15:27.072 › [DeviceService] Dongle pairing failed TypeError: Cannot write to hid device
    at /home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:474200
19:15:27.072 › [DeviceService] Dongle force reenumerate
19:15:28.079 › [DeviceService] Dongle not found, skip reenumeration
19:15:29.080 › [DeviceService] Device force reenumerate
19:15:29.081 › [UhkHidDevice] Device communication closing.
19:15:30.101 › [UhkHidDevice] Device communication closing.
19:15:30.102 › [UhkHidDevice] Start reenumeration, mode: NormalKeyboard, timeout: 5000ms
19:15:30.290 › [UhkHidDevice] Reenumeration error. We hope it would not break the process TypeError: Cannot write to hid device
    at Fr.reenumerate (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:476381)
    at async Os.forceReenumerateDevice (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:577035)
    at async Os.startDonglePairing (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:569839)
    at async xs.process (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:554570)
19:15:30.291 › [UhkHidDevice] closing normal keyboard after reenumeration
19:15:30.314 › [UhkHidDevice] Reenumerating devices
19:15:30.315 › [DeviceService] Device force reenumerate done
19:15:30.315 › [UhkHidDevice] Device communication closing.
19:15:31.315 › [DeviceService] start poll UHK Device
19:15:31.548 › [DeviceService] Device connection state changed to: {
  "bootloaderActive": true,
  "bleDeviceConnected": false,
  "communicationInterfaceAvailable": false,
  "dongle": {
    "bootloaderActive": false,
    "multiDevice": false,
    "serialNumber": "4294967295"
  },
  "leftHalfBootloaderActive": false,
  "hasPermission": true,
  "halvesInfo": {
    "areHalvesMerged": true,
    "leftModuleSlot": 0,
    "isLeftHalfConnected": true,
    "rightModuleSlot": 0
  },
  "hardwareModules": {
    "moduleInfos": [],
    "rightModuleInfo": {
      "modules": {}
    }
  },
  "isMacroStatusDirty": false,
  "leftHalfDetected": true,
  "multiDevice": false,
  "udevRulesInfo": "Ok",
  "connectedDevice": {
    "id": 4,
    "asCliArg": "uhk80-right",
    "firmwareUpgradeMethod": "mcuboot",
    "logName": "UHK 80 right",
    "name": "UHK 80",
    "keyboard": [
      {
        "vid": 14248,
        "pid": 9
      }
    ],
    "bootloader": [
      {
        "vid": 14248,
        "pid": 8
      }
    ],
    "buspal": [],
    "reportId": 4
  }
}
19:15:31.548 › [DeviceRendererService] dispatch action [device] connection state changed
19:15:31.552 › [SmartMacroDocRendererService] downloadDocumentation
19:15:31.553 › [SmartMacroService] skip download firmware documentation because git repo or tag missing { firmwareGitRepo: '', firmwareGitTag: '' }
19:15:37.354 › [DeviceService] Device connection state changed to: {
  "bootloaderActive": false,
  "bleDeviceConnected": false,
  "communicationInterfaceAvailable": false,
  "dongle": {
    "bootloaderActive": false,
    "multiDevice": false,
    "serialNumber": "4294967295"
  },
  "leftHalfBootloaderActive": false,
  "hasPermission": true,
  "halvesInfo": {
    "areHalvesMerged": true,
    "leftModuleSlot": 0,
    "isLeftHalfConnected": true,
    "rightModuleSlot": 0
  },
  "hardwareModules": {
    "moduleInfos": [],
    "rightModuleInfo": {
      "modules": {}
    }
  },
  "isMacroStatusDirty": false,
  "leftHalfDetected": true,
  "multiDevice": false,
  "udevRulesInfo": "Ok"
}
19:15:37.355 › [DeviceRendererService] dispatch action [device] connection state changed
19:15:37.360 › [SmartMacroDocRendererService] downloadDocumentation
19:15:37.360 › [SmartMacroService] skip download firmware documentation because git repo or tag missing { firmwareGitRepo: '', firmwareGitTag: '' }
19:15:39.047 › [UhkHidDevice] Available devices changed.
19:15:39.048 › [UhkHidDevice] Removed: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw21","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":2,"usagePage":65280,"usage":1}
19:15:39.048 › [UhkHidDevice] Removed: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw22","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":3,"usagePage":12,"usage":1}
19:15:39.048 › [UhkHidDevice] Removed: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw23","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":4,"usagePage":1,"usage":128}
19:15:39.048 › [UhkHidDevice] Removed: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw24","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":5,"usagePage":1,"usage":5}
19:15:39.105 › [UhkHidDevice] Used device: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw19","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":0,"usagePage":65280,"usage":1}
19:15:39.130 › [UhkHidDevice] protocol versions: {"firmwareVersion":"12.1.0","deviceProtocolVersion":"4.12.0","moduleProtocolVersion":"4.3.0","userConfigVersion":"8.3.0","hardwareConfigVersion":"1.0.0","smartMacrosVersion":"3.0.0"}
19:15:39.162 › [DeviceOperation] Read "leftHalf" version information
19:15:39.170 › [DeviceOperation] Read "leftHalf" repo information
19:15:39.186 › [DeviceOperation] Read "leftHalf" firmware checksum
19:15:39.194 › [DeviceOperation] Read "leftModule" version information
19:15:39.202 › [DeviceOperation] Read "leftModule" repo information
19:15:39.218 › [DeviceOperation] Read "leftModule" firmware checksum
19:15:39.226 › [DeviceOperation] Read "rightModule" version information
19:15:39.234 › [DeviceOperation] Read "rightModule" repo information
19:15:39.250 › [DeviceOperation] Read "rightModule" firmware checksum
19:15:39.290 › [DeviceService] Device connection state changed to: {
  "bootloaderActive": false,
  "bleDeviceConnected": false,
  "communicationInterfaceAvailable": true,
  "dongle": {
    "bootloaderActive": false,
    "multiDevice": false,
    "serialNumber": "4294967295"
  },
  "leftHalfBootloaderActive": false,
  "hasPermission": true,
  "halvesInfo": {
    "areHalvesMerged": false,
    "isLeftHalfConnected": true,
    "leftModuleSlot": 2,
    "rightModuleSlot": 4
  },
  "hardwareModules": {
    "moduleInfos": [
      {
        "module": {
          "id": 1,
          "name": "Left keyboard half",
          "slotId": 1,
          "i2cAddress": 16,
          "firmwareUpgradeSupported": true
        },
        "info": {
          "moduleProtocolVersion": "4.3.0",
          "firmwareVersion": "12.1.0",
          "firmwareGitRepo": "Ul",
          "firmwareGitTag": "35",
          "firmwareChecksum": "00000000000000000000000000000000"
        }
      },
      {
        "module": {
          "id": 2,
          "name": "Key cluster",
          "configPath": "/add-on/key-cluster",
          "slotId": 2,
          "i2cAddress": 32,
          "firmwareUpgradeSupported": true
        },
        "info": {
          "moduleProtocolVersion": "4.3.0",
          "firmwareVersion": "12.0.0",
          "firmwareGitRepo": "Ul",
          "firmwareGitTag": "v1",
          "firmwareChecksum": "b9cd4660ab39398e130c14a4077135f7"
        }
      },
      {
        "module": {
          "id": 4,
          "name": "Trackpoint",
          "configPath": "/add-on/trackpoint",
          "slotId": 3,
          "i2cAddress": 48,
          "firmwareUpgradeSupported": true
        },
        "info": {
          "moduleProtocolVersion": "4.3.0",
          "firmwareVersion": "12.0.0",
          "firmwareGitRepo": "Ul",
          "firmwareGitTag": "v1",
          "firmwareChecksum": "25fd611cebe29234e848ffd01a1c1431"
        }
      }
    ],
    "rightModuleInfo": {
      "firmwareVersion": "12.1.0",
      "deviceProtocolVersion": "4.12.0",
      "moduleProtocolVersion": "4.3.0",
      "userConfigVersion": "8.3.0",
      "hardwareConfigVersion": "1.0.0",
      "smartMacrosVersion": "3.0.0",
      "firmwareGitRepo": "Ul",
      "firmwareGitTag": "35",
      "firmwareChecksum": "00000000000000000000000000000000",
      "modules": {
        "1": {
          "md5": "00000000000000000000000000000000"
        },
        "2": {
          "md5": "00000000000000000000000000000000"
        },
        "4": {
          "md5": "00000000000000000000000000000000"
        }
      }
    }
  },
  "isMacroStatusDirty": false,
  "leftHalfDetected": true,
  "multiDevice": false,
  "udevRulesInfo": "Ok",
  "connectedDevice": {
    "id": 4,
    "asCliArg": "uhk80-right",
    "firmwareUpgradeMethod": "mcuboot",
    "logName": "UHK 80 right",
    "name": "UHK 80",
    "keyboard": [
      {
        "vid": 14248,
        "pid": 9
      }
    ],
    "bootloader": [
      {
        "vid": 14248,
        "pid": 8
      }
    ],
    "buspal": [],
    "reportId": 4
  },
  "bleAddress": "f4:10:bc:dd:5c:ea"
}
19:15:39.291 › [DeviceRendererService] dispatch action [device] connection state changed
19:15:39.298 › [DeviceOperation] status buffer segment: 
19:15:39.301 › [SmartMacroDocRendererService] downloadDocumentation
19:15:39.302 › [SmartMacroService] start download firmware documentation { firmwareGitRepo: 'Ul', firmwareGitTag: '35' }
19:15:39.302 › [SmartMacroService] download documentation failed TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at join (node:path:1244:7)
    at Object.handleDownloadDocumentation (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:758047)
    at xs.process (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:554585)
    at xs.add (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:554423)
    at IpcMainImpl.<anonymous> (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:755397)
    at IpcMainImpl.emit (node:events:519:28)
    at WebContents.<anonymous> (node:electron/js2c/browser_init:2:86186)
    at WebContents.emit (node:events:519:28)
19:15:39.302 › [DeviceService] stop poll UHK Device
19:15:39.303 › [DeviceService] stopped poll UHK Device
19:15:39.306 › [UhkHidDevice] Device communication closing.
19:15:39.308 › [UhkHidDevice] Device communication closed.
19:15:39.308 › [DeviceService] start poll UHK Device
19:15:39.309 › [DeviceService] load user configuration
19:15:39.309 › [DeviceService] stop poll UHK Device
19:15:39.309 › [DeviceService] stopped poll UHK Device
19:15:39.306 › [DeviceRendererService] dispatch action [device] Status buffer changed
19:15:39.309 › [DeviceRendererService] dispatch action [device] Read config sizes reply
19:15:39.315 › [UhkHidDevice] Available devices unchanged
19:15:39.372 › [UhkHidDevice] Used device: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw19","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":0,"usagePage":65280,"usage":1}
19:15:39.394 › [UhkHidDevice] Device communication closing.
19:15:39.396 › [UhkHidDevice] Device communication closed.
19:15:39.397 › [DeviceOperation] User config size: 32768
19:15:39.403 › [UhkHidDevice] Available devices unchanged
19:15:39.462 › [UhkHidDevice] Used device: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw19","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":0,"usagePage":65280,"usage":1}
19:15:39.466 › [DeviceOperation] userConfigSize: 6246
19:15:40.274 › [UhkHidDevice] Device communication closing.
19:15:40.277 › [UhkHidDevice] Device communication closed.
19:15:40.277 › [DeviceOperation] Hardware config size: 64
19:15:40.301 › [UhkHidDevice] Available devices unchanged
19:15:40.366 › [UhkHidDevice] Used device: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw19","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":0,"usagePage":65280,"usage":1}
19:15:40.387 › [UhkHidDevice] Device communication closing.
19:15:40.390 › [UhkHidDevice] Device communication closed.
19:15:40.412 › [UhkHidDevice] Available devices unchanged
19:15:40.472 › [UhkHidDevice] Used device: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw19","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":0,"usagePage":65280,"usage":1}
19:15:40.483 › [UhkHidDevice] protocol versions: {"firmwareVersion":"12.1.0","deviceProtocolVersion":"4.12.0","moduleProtocolVersion":"4.3.0","userConfigVersion":"8.3.0","hardwareConfigVersion":"1.0.0","smartMacrosVersion":"3.0.0"}
19:15:40.514 › [DeviceOperation] Read "leftHalf" version information
19:15:40.523 › [DeviceOperation] Read "leftHalf" repo information
19:15:40.539 › [DeviceOperation] Read "leftHalf" firmware checksum
19:15:40.547 › [DeviceOperation] Read "leftModule" version information
19:15:40.555 › [DeviceOperation] Read "leftModule" repo information
19:15:40.571 › [DeviceOperation] Read "leftModule" firmware checksum
19:15:40.579 › [DeviceOperation] Read "rightModule" version information
19:15:40.587 › [DeviceOperation] Read "rightModule" repo information
19:15:40.603 › [DeviceOperation] Read "rightModule" firmware checksum
19:15:40.642 › [UhkHidDevice] Device communication closing.
19:15:40.645 › [UhkHidDevice] Device communication closed.
19:15:40.645 › [DeviceService] start poll UHK Device
19:15:40.647 › [DeviceRendererService] dispatch action [user-config] Load User Config from Device reply
19:15:40.667 › [SmartMacroDocRendererService] downloadDocumentation
19:15:40.667 › [SmartMacroService] start download firmware documentation { firmwareGitRepo: 'Ul', firmwareGitTag: '35' }
19:15:40.668 › [SmartMacroService] download documentation failed TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at join (node:path:1244:7)
    at Object.handleDownloadDocumentation (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:758047)
    at xs.process (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:554585)
    at xs.add (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:554423)
    at IpcMainImpl.<anonymous> (/home/laci/projects/agent/packages/uhk-agent/dist/electron-main.js:2:755397)
    at IpcMainImpl.emit (node:events:519:28)
    at WebContents.<anonymous> (node:electron/js2c/browser_init:2:86186)
    at WebContents.emit (node:events:519:28)
19:15:40.677 › [AppEffects] navigate to { commands: [ '/' ] }
19:15:40.939 › [UhkHidDevice] Available devices unchanged
19:15:40.999 › [UhkHidDevice] Used device: {"vendorId":"0x37A8","productId":"0x9","path":"/dev/hidraw19","serialNumber":"2396298791","manufacturer":"Ultimate Gadget Laboratories","product":"UHK 80 right half","release":1,"interface":0,"usagePage":65280,"usage":1}

Right half log:

uhk80:right$ --- Entering pairing mode. Going to stop BT and disconnect all connections. ---
Advertising successfully stopped
Scanning successfully stopped.
Not deleting bond for F4:7D:97:8A:EF:22 (random)
Settings: Found peer 'left' with address 22ef8a977df4
Settings: Found peer 'left' with address 22ef8a977df4
Setting no advertising filter
NUS advertising successfully started
Waiting for central to pair to me.
Bt disconnected from left (f4:7d:97:8a:ef:22), reason 22
Connection state: NusServerLeft(Disconnected)
 === Usb Disable Hid
Allocating connectionId 23 to peer 2
Connection state: HostConnection22(New Bluetooth Device, Connected)
Bt connected to host1 (dc:e0:38:11:ee:25)
 === set transport null
Connection state: HostConnection22(New Bluetooth Device, Disconnected)
Connection state: HostConnection0(My PC, Disconnected)
Supplied connection (0) doesn't correspond to a host connection!
Setting no advertising filter
NUS advertising continued
USB config changing to Hid_Empty
Pairing OOB data requested!
Pairing completed: host1 (dc:e0:38:11:ee:25), bonded 1
--- Pairing ended, success = 1: Successfuly bonded! ---
Advertising successfully stopped
Starting bluetooth services.
Setting no advertising filter
NUS advertising successfully started
Scanning successfully started
- is known: 0, isUhkPeer: 0
setting NewPairedDevice
Current connections:
  - peer 2(host1 (dc:e0:38:11:ee:25)), connection 23
  - unknown (ff:ff:ff:ff:ff:ff)
All bonds:
 - F4:7D:97:8A:EF:22 (random)
 - DC:E0:38:11:EE:25 (random)
Known host connection ble addresses:
 - 22 'New Bluetooth Device': address: 00:00:00:00:00:00 (public)
Bt connection secured: host1 (dc:e0:38:11:ee:25), level 4, peerId 2
Filters matched: left (f4:7d:97:8a:ef:22), connectable:1
Scan connecting: left (f4:7d:97:8a:ef:22)
Allocating connectionId 28 to peer 0
Connection state: NusServerLeft(Connected)
Bt connected to left (f4:7d:97:8a:ef:22)
Setting no advertising filter
NUS advertising continued
W: Unexpected SMP code 0x0b
BLE HID conn params: interval=11 ms, latency=0, timeout=1000 ms
NUS peripheral connection is ready.
Connection state: HostConnection22(New Bluetooth Device, Ready)
Switching to host: HostConnection22(New Bluetooth Device, Ready)
Resetting dongle right link! Unidirectional
Bt connection secured: left (f4:7d:97:8a:ef:22), level 4, peerId 0
Initiating NUS connection with left (f4:7d:97:8a:ef:22)
MTU exchange done with left (f4:7d:97:8a:ef:22)
NUS connection with left (f4:7d:97:8a:ef:22) successfully established
Connection state: NusServerLeft(Ready)
*** Booting nRF Connect SDK v2.8.0-474b69ace561 ***
*** Using Zephyr OS v3.7.99-37939f03cb6f ***
----------
UHK 80 right half started
Enabling UART

uhk8I: 3 Sectors of 4096 bytes
I: alloc wra: 0, e30
I: data wra: 0, 3cc
I: SoftDevice Controller build revision: 
I: fe 2c f9 6a 7f 36 22 2e |.,.j.6".
I: a0 79 c0 40 be 2c 03 20 |.y.@.,. 
I: 40 c2 f3 32             |@..2    
I: HW Platform: Nordic Semiconductor (0x0002)
I: HW Variant: nRF52x (0x0002)
I: Firmware: Standard Bluetooth controller (0x00) Version 254.63788 Build 573996906
I: No ID address. App must call settings_load()
Settings: Found peer 'left' with address 22ef8a977df4
I: Identity: EA:5C:DD:BC:10:F4 (random)
I: HCI: version 6.0 (0x0e) revision 0x104e, manufacturer 0x0059
I: LMP: version 6.0 (0x0e) subver 0x104e
Reading hardware config
Reading user config
Applying user config
Flashed User Config version: 8.3.0
Clearing bonds
 - Deleting an unknown bond!
Unpaired device DC:E0:38:11:EE:25 (random)
 - Keeping a known bond.
Resetting left right link! Unidirectional
User config applied
 === Usb Enable Hid
NUS Server module initialized.
Scan module initialized
NUS Client module initialized
Starting bluetooth services.
Setting no advertising filter
NUS and HID advertising successfully started
Scanning successfully started
USB config changing to Hid_Full
Supplied connection (0) doesn't correspond to a host connection!
0:right$  === Usb Disable Hid
Allocating connectionId 23 to peer 2
Connection state: HostConnection22(New Bluetooth Device, Connected)
Bt connected to host1 (dc:e0:38:11:ee:25)
Setting no advertising filter
NUS advertising continued
USB config changing to Hid_Empty
Resetting left right link! Unidirectional
Connection state: UartLeft(Ready)
Resetting left right link! Bidirectional
Filters matched: left (f4:7d:97:8a:ef:22), connectable:1
Scan connecting: left (f4:7d:97:8a:ef:22)
Allocating connectionId 28 to peer 0
Connection state: NusServerLeft(Connected)
Bt connected to left (f4:7d:97:8a:ef:22)
Setting no advertising filter
NUS advertising continued
W: Unexpected SMP code 0x0b
Bt connection secured: left (f4:7d:97:8a:ef:22), level 4, peerId 0
Initiating NUS connection with left (f4:7d:97:8a:ef:22)
MTU exchange done with left (f4:7d:97:8a:ef:22)
NUS connection with left (f4:7d:97:8a:ef:22) successfully established
Connection state: NusServerLeft(Ready)
BLE HID conn params: interval=11 ms, latency=10, timeout=1000 ms
USB: requesting remote wakeup
USB: remote wakeup disabled
Can't send report - selected connection is not ready!
Failed to send message from right to dongle
Can't send report - selected connection is not ready!
Failed to send message from right to dongle

Dongle log:

uhk-dongle$ --- Entering pairing mode. Going to stop BT and disconnect all connections. ---
Scanning successfully stopped.
Deleting all bonds!
Settings: Found peer 'right' with address f410bcdd5cea
Scanning successfully started
Scanning for pairable device
Filters matched: right (ea:5c:dd:bc:10:f4), connectable:1
Scan connecting: right (ea:5c:dd:bc:10:f4)
Allocating connectionId 29 to peer 1
Connection state: NusServerRight(Connected)
Bt connected to right (ea:5c:dd:bc:10:f4)
Pairing OOB data requested!
Pairing completed: right (ea:5c:dd:bc:10:f4), bonded 1
--- Pairing ended, success = 1: Successfuly bonded! ---
Scanning successfully stopped.
Starting bluetooth services.
Scanning successfully started
- is known: 1, isUhkPeer: 1
Current connections:
  - peer 1(right (ea:5c:dd:bc:10:f4)), connection 29
All bonds:
 - EA:5C:DD:BC:10:F4 (random)
Known host connection ble addresses:
 - 22 'New Bluetooth Device': address: 00:00:00:00:00:00 (public)
Bt connection secured: right (ea:5c:dd:bc:10:f4), level 4, peerId 1
Initiating NUS connection with right (ea:5c:dd:bc:10:f4)
MTU exchange done with right (ea:5c:dd:bc:10:f4)
NUS connection with right (ea:5c:dd:bc:10:f4) successfully established
Connection state: NusServerRight(Ready)
Resetting dongle right link! Bidirectional
Bt disconnected from right (ea:5c:dd:bc:10:f4), reason 8
Connection state: NusServerRight(Disconnected)
Scanning successfully started
Filters matched: right (ea:5c:dd:bc:10:f4), connectable:1
Scan connecting: right (ea:5c:dd:bc:10:f4)
Allocating connectionId 29 to peer 1
Connection state: NusServerRight(Connected)
Bt connected to right (ea:5c:dd:bc:10:f4)
Bt security failed: right (ea:5c:dd:bc:10:f4), level 1, err 2, disconnecting

@kareltucek
Copy link
Collaborator Author

(For the moment, it is only rebased. No point testing now.)

@ert78gb
Copy link
Member

ert78gb commented Dec 30, 2024

(For the moment, it is only rebased. No point testing now.)

FYI: The UltimateHackingKeyboard/agent#2450 PR works well for me with this PR

@kareltucek
Copy link
Collaborator Author

kareltucek commented Jan 1, 2025

(No changes to code, just rebased onto master to resolve conflicts.)

@mondalaci
Copy link
Member

For some reason, Agent now succeeded pairing both dongles. My connections:

image

My macros on the Fn2 layer which contain the macro actions of the same content as the macro names:

image

With switchHost next I can switch between "Production dongle" and "My Phone", but not the others. Should I be able to cycle between all the 4 host connections this way?

When switching to "Production Dongle", is it expected that I get the following?

Connection state: HostConnection2(Production Dongle, Ready), Peer host2, Active
Resetting dongle right link! Bidirectional
Failed to send data over BLE connection (err: -22)
Failed to send data over BLE connection (err: -22)

When trying to switch to "My PC", I can't, and I get:

uhk80:right$ Disconnecting oldest host 3
Bt disconnected from host1 (dc:e0:38:11:ee:25), reason 22
Connection state: HostConnection1(Dev Dongle, Disconnected), Peer host1
Starting advertising, try 0!
NUS advertising successfully started
Refusing connenction 2 (this is not a selected connection)
Starting advertising, try 0!
NUS advertising successfully started
Bt disconnected from unknown (dc:e0:38:11:ee:25), reason 22
Starting advertising, try 0!
NUS advertising continued
Refusing connenction 2 (this is not a selected connection)
Starting advertising, try 0!
NUS advertising successfully started
Bt disconnected from unknown (dc:e0:38:11:ee:25), reason 22
Starting advertising, try 0!
NUS advertising continued
Refusing connenction 2 (this is not a selected connection)
Starting advertising, try 0!
NUS advertising successfully started
Bt disconnected from unknown (dc:e0:38:11:ee:25), reason 22
Starting advertising, try 0!
NUS advertising continued
[repeating forever]

In the meantime, even though "Dev Dongle" shouldn't be involved at this point, outputs:

Bt disconnected from left (ea:5c:dd:bc:10:f4), reason 19       
Connection state: NusServerLeft(Disconnected), Peer left                   
Starting scanning, try 0!                                                  
Filters matched: left (ea:5c:dd:bc:10:f4), connectable:1                   
Scan connecting: left (ea:5c:dd:bc:10:f4)                                  
Connection state: NusServerLeft(Connected), Peer left                      
Bt connected to left (ea:5c:dd:bc:10:f4)                                   
Bt security failed: left (ea:5c:dd:bc:10:f4), level 1, err 9, disconnecting
Bt disconnected from left (ea:5c:dd:bc:10:f4), reason 19                   
Connection state: NusServerLeft(Disconnected), Peer left                   
Starting scanning, try 0!                                                  
Filters matched: left (ea:5c:dd:bc:10:f4), connectable:1                   
Scan connecting: left (ea:5c:dd:bc:10:f4)                                  
Connection state: NusServerLeft(Connected), Peer left                      
Bt connected to left (ea:5c:dd:bc:10:f4)                                   
Bt security failed: left (ea:5c:dd:bc:10:f4), level 1, err 9, disconnecting
Bt disconnected from left (ea:5c:dd:bc:10:f4), reason 19                   
Connection state: NusServerLeft(Disconnected), Peer left                   
Starting scanning, try 0!                                                  
Filters matched: left (ea:5c:dd:bc:10:f4), connectable:1                   
Scan connecting: left (ea:5c:dd:bc:10:f4)                                  
Connection state: NusServerLeft(Connected), Peer left                      
Bt connected to left (ea:5c:dd:bc:10:f4)                                   
Bt security failed: left (ea:5c:dd:bc:10:f4), level 1, err 9, disconnecting
Bt disconnected from left (ea:5c:dd:bc:10:f4), reason 19                   
Connection state: NusServerLeft(Disconnected), Peer left                   
Starting scanning, try 0!                                                  
Filters matched: left (ea:5c:dd:bc:10:f4), connectable:1                   
Scan connecting: left (ea:5c:dd:bc:10:f4)                                  
Connection state: NusServerLeft(Connected), Peer left                      
Bt connected to left (ea:5c:dd:bc:10:f4)                                   
[repeating forever]

I can't switch to "Dev Dongle", either. Right half log:

uhk80:right$ Disconnecting oldest host 3
Bt disconnected from host1 (dc:e0:38:11:ee:25), reason 22
Connection state: HostConnection1(Dev Dongle, Disconnected), Peer host1, Selecte
d
Starting advertising, try 0!
NUS advertising successfully started
Connection state: HostConnection1(Dev Dongle, Connected), Peer host1, Selected
Bt connected to host1 (dc:e0:38:11:ee:25)
Starting advertising, try 0!
Current slot count 0, not advertising
Current connections:
  - peer 3(host1 (dc:e0:38:11:ee:25)), connection 2
  - peer 4(host2 (d0:d1:91:71:0e:79)), connection 3
  - peer 5(host3 (ac:d6:18:1b:3d:b5)), connection 4
  - peer 1(left (f4:7d:97:8a:ef:22)), connection 29
Attempted to start advertising without any type! Ignoring.
Bt connection secured: host1 (dc:e0:38:11:ee:25), level 4, peerId 3

"Dev Dongle" log:

Bt disconnected from left (ea:5c:dd:bc:10:f4), reason 19
Connection state: NusServerLeft(Disconnected), Peer left            
Starting scanning, try 0!                                           
Filters matched: left (ea:5c:dd:bc:10:f4), connectable:1            
Scan connecting: left (ea:5c:dd:bc:10:f4)                           
Connection state: NusServerLeft(Connected), Peer left               
Bt connected to left (ea:5c:dd:bc:10:f4)                            
Bt connection secured: left (ea:5c:dd:bc:10:f4), level 4, peerId 1  

@kareltucek
Copy link
Collaborator Author

kareltucek commented Jan 1, 2025

With switchHost next I can switch between "Production dongle" and "My Phone", but not the others. Should I be able to cycle between all the 4 host connections this way

No. Only those whose connections are active - i.e., dongles that are blue, and maybe usb or ble hid.

As for usb vs ble hid, they are mutually exclusive for the moment, and they act quirky anyways. I am waiting for @benedekkupper's response about that at #1021


Whenever posting dongle-related issues please include following when possible:

  • colour of the dongle
  • the log line that reports current commit (e.g., Flashed User Config version: 8.3.0 (native version: 8.3.0., at ce3a3ce1))

(This is for next time, don't waste time by re-testing the above ;-).)

@kareltucek
Copy link
Collaborator Author

However you should be able to reach any dongle when asking for it specifically by name. Will investigate.

@kareltucek
Copy link
Collaborator Author

@benedekkupper I have restructured current bt connection initiation sequence - the old one suffered by a number of problems, often stemming from the ble hid central changing its address after pairing or during authentication... ...and this change broke c2usb's switching between usb and ble.

Can you please respond to #1021 ? In case I am doing something idiotic (which is by no means unlikely), then telling me that (you suspect that) I am being idiotic and pointing me in the right direction would be very appreciated. (Which source file should I read? Which c2usb documentation have I missed?)

@mondalaci
Copy link
Member

When renaming the current connection and saving the configuration, the new name isn't reflected on the OLED display.

@mondalaci
Copy link
Member

Many customers purchased multiple dongles, which is currently not handled by Agent and must be: When I connect a dongle via USB, it gets paired. If I connect another dongle via USB, Agent doesn't offer to pair it, only if I disconnect the old dongle and reconnect the new dongle. Is this purely an Agent limitation?

@kareltucek
Copy link
Collaborator Author

I believe so.

@mondalaci
Copy link
Member

When trying to switch to a specific host connection that is unavailable, it'd be nice to display it on the OLED display for a second, such as My PC unavailable, then revert to the current host connection. It's not a critical feature, and I can create a dedicated issue.

@mondalaci
Copy link
Member

It'd be nice to make switchConnection last work the way Alt-Tab works when switching not to the previous connection but the ones before it. Namely, when not releasing the layer switcher key (assuming one is involved) while pressing the action key multiple times. I understand if it's difficult to implement, and I don't insist on it now, but I think behavior would be useful. I can make a separate issue. There will be a dedicated action for this, at which point it'll be easy to differentiate this action and matching it, assuming it makes the implementation easier.

@mondalaci
Copy link
Member

I can't switch back to my phone now, even though it worked a couple minutes earlier. To be precise, the host connection changes, but no reports seem to be sent.

Connection state: HostConnection2(My Phone, Ready), Peer host1, Active
Connection state: HostConnection2(My Phone, Ready), Peer host1, Active
Giving report to c2usb ble hid!
Giving report to c2usb ble hid!
Giving report to c2usb ble hid!
Giving report to c2usb ble hid!

May this be a c2usb issue? On a related note, mousing on Android still doesn't work.

@kareltucek
Copy link
Collaborator Author

Giving report to c2usb ble hid! indicates that indeed I have handed the report over to c2usb.

@mondalaci mondalaci merged commit 3a114b7 into master Jan 10, 2025
2 checks passed
@mondalaci mondalaci deleted the host-routing branch January 10, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report routing revisited BLE HID pairing
4 participants