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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Implement connection manager. #1031

wants to merge 13 commits into from

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.

@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

# Conflicts:
#	device/prj.conf
#	device/src/bt_conn.c
#	device/src/bt_scan.c
#	device/src/dongle_leds.c
#	device/src/dongle_leds.h
#	device/src/keyboard/uart.c
#	device/src/messenger.c
#	device/src/usb/usb.cpp
#	device/src/usb/usb_compatibility.cpp
#	right/src/stubs.h
@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

This is a semi-stable state. Will look into it further. However, any testing is welcome.

@mondalaci
Copy link
Member

I've tried to pair my dongle which resulted in "device pairing timeout" in Agent master. Is this expected?

Before sending a bunch of logs, I need to know whether I should test with UltimateHackingKeyboard/agent#2450

@kareltucek
Copy link
Collaborator Author

Is this expected?

No.

Please test with UltimateHackingKeyboard/agent#2450

@mondalaci
Copy link
Member

I can't pair one of my dongles because the pairing notification is not displayed in Agent. I think I have paired this dongle previously, and the host connection has been removed in Agent in the meantime, possibly when the dongle wasn't connected. The dongle displays violet light, and the right half keeps outputting frequent log messages while it's connected:

Unknown NUS trying to connect. Refusing!
Handing report over to c2usb!
Bt disconnected from unknown (d0:d1:91:71:0e:79), reason 22
Handing report over to c2usb!
Starting advertising, try 0!
NUS and HID advertising continued
Handing report over to c2usb!
Handing report over to c2usb!
Bt connected to unknown. Starting discovery.
Starting advertising, try 0!
NUS and HID advertising continued
Handing report over to c2usb!
Handing report over to c2usb!
Handing report over to c2usb!
Handing report over to c2usb!
Handing report over to c2usb!
Handing report over to c2usb!
Handing report over to c2usb!
Unknown NUS trying to connect. Refusing!
Handing report over to c2usb!
Bt disconnected from unknown (d0:d1:91:71:0e:79), reason 22
Starting advertising, try 0!
NUS and HID advertising continued
Handing report over to c2usb!
Handing report over to c2usb!
Bt connected to unknown. Starting discovery.
Starting advertising, try 0!
NUS and HID advertising continued
Handing report over to c2usb!
Unknown NUS trying to connect. Refusing!
Bt disconnected from unknown (d0:d1:91:71:0e:79), reason 22
Starting advertising, try 0!
NUS and HID advertising continued
Handing report over to c2usb!
Bt connected to unknown. Starting discovery.
Starting advertising, try 0!
NUS and HID advertising continued
Unknown NUS trying to connect. Refusing!
Bt disconnected from unknown (d0:d1:91:71:0e:79), reason 22
Starting advertising, try 0!
NUS and HID advertising continued

Regardless of the dongle, upon every keypress and release, the following message is displayed in the right's half console, which is a bit annoying: Handing report over to c2usb!

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.

3 participants