0x1814 · changeHost
查询多主机设备的槽位数量并切换当前连接,同时支持每槽 cookie 管理以实现增强型连接失败回退。
多主机设备通过此功能查询支持的主机槽位 / RF 频道数量并在它们之间切换。get_host_info 返回一个 ChangeHostInfo 结构体,包含主机数量、当前主机索引以及 ChangeHostCapabilities 标志位字段;set_current_host 发送一个"发送即忘"的切换请求——设备在主机切换时通常会重置连接,因此不等待响应。
另有两个函数管理每个主机槽位的cookie 字节——设备非易失性存储中的一个小数值。get_cookies 返回每个槽位对应的一字节 cookie;set_cookie 写入单个条目。固件在新主机配对到该槽位时会清除其 cookie。增强型主机切换(ENHANCED_HOST_SWITCH 能力标志)利用非零 cookie 在连接失败时选择备用主机,之后再返回原始槽位。
ChangeHostInfo——host_count、current_host、capabilities。ChangeHostCapabilities::ENHANCED_HOST_SWITCH—— 连接失败时先回退到 cookie 非零的主机,再返回原始主机。
规格: Logitech HID++ 2.0 —— changeHost。用于:
openlogi-hidpp中的类型化封装。
Function reference
The ChangeHostFeature wrapper (0x1814) exposes methods for querying and changing the active host slot on multi-host devices, plus per-slot cookie management.
Methods
| Function | HID++ fn | Signature | Returns |
|---|---|---|---|
get_host_info | 0 | () | ChangeHostInfo |
set_current_host | 1 | (host: u8) | () |
get_cookies | 2 | (host_count: u8) | Vec<u8> |
set_cookie | 3 | (host: u8, cookie: u8) | () |
All methods are async and return Result<…, Hidpp20Error>.
Types
ChangeHostInfo
Host configuration returned by get_host_info.
| Field | Type | Description |
|---|---|---|
host_count | u8 | Number of hosts / RF channels. |
current_host | u8 | Current host index, in 0..host_count. |
capabilities | ChangeHostCapabilities | Host-switching capabilities. |
ChangeHostCapabilities
Host-switching capabilities bitflags reported by get_host_info.
| Flag | Bit/Value | Description |
|---|---|---|
ENHANCED_HOST_SWITCH | 1 << 0 | Enhanced host switching is enabled: on a failed connection the device falls back to another host with a non-zero cookie before returning to the original host. |
Wire format
Short 3-byte request payloads are used for all functions; responses are read from the 16-byte long payload via extend_payload().
get_host_info (fn 0)
Request: [0x00, 0x00, 0x00] (no parameters)
Response (byte → field):
| Byte | Field | Notes |
|---|---|---|
| 0 | host_count | Total number of host slots / RF channels |
| 1 | current_host | Active host index, zero-based |
| 2 | capabilities | ChangeHostCapabilities bitflags; bit 0 = ENHANCED_HOST_SWITCH |
set_current_host (fn 1)
Sent as a notify (fire-and-forget); no response is read.
Request: [host, 0x00, 0x00]
| Byte | Field | Notes |
|---|---|---|
| 0 | host | Target host index to activate |
| 1–2 | — | Padding, always 0x00 |
get_cookies (fn 2)
Request: [0x00, 0x00, 0x00] (no parameters)
Response: bytes payload[0..host_count] — one cookie byte per host slot in order. The caller supplies host_count (from get_host_info) to slice the response; bytes beyond host_count are ignored.
| Byte | Field | Notes |
|---|---|---|
| 0 | cookie for host 0 | |
| 1 | cookie for host 1 | |
| … | cookie for host N-1 | Up to host_count bytes |
set_cookie (fn 3)
Request: [host, cookie, 0x00]
| Byte | Field | Notes |
|---|---|---|
| 0 | host | Host slot index whose cookie is being written |
| 1 | cookie | Arbitrary byte value to store in NVM |
| 2 | — | Padding, always 0x00 |
The device ACK response is awaited but its payload is discarded.
Usage (Rust)
use hidpp::feature::change_host::ChangeHostFeature;
// device: &mut Device, already created via Device::new(channel, index)
device.enumerate_features().await?;
if let Some(feat) = device.get_feature::<ChangeHostFeature>() {
// Query host count, current host, and capabilities
let info = feat.get_host_info().await?;
println!("hosts: {}, current: {}", info.host_count, info.current_host);
// Read the per-host cookies (one byte per slot)
let cookies = feat.get_cookies(info.host_count).await?;
println!("cookies: {:?}", cookies);
// Switch to host 1 (fire-and-forget; device will reset its connection)
feat.set_current_host(1).await?;
}