nazo6 notememo

RRP Protocol

作成:2024/11/12

更新:2024/11/12

RRP protocol

RRP protocol is 'high level' protocol like HTTP.

Indicators

ValueNameMeaning
01010101(0x55)STARTRequest/Response starts
00000000(0x00)ENDThis request/response flow is finished
11111111(0xFF)CONTINUEThis request/response continues

Request

Normal

StepOperationData size
1Send START indicator1byte
2Send request id1byte
3Send endpoint id1byte
4Send CONTINUE indicator1byte
5Send data size4byte
6Send dataSize specified in step 5
7Send END indicator1byte

Stream

StepOperationData size
1Send START indicator1byte
2Send request id1byte
3Send endpoint id1byte
4If stream continues: Send CONTINUE
If stream finished: Send END
1byte
5Send data size4byte
6Send dataSize specified in step 5
7Goto step 4

Response

Normal

StepOperationData size
1Send START indicator1byte
2Send request id tied to this response1byte
3Send status code1byte
4Send CONTINUE indicator1byte
5Send data size4byte
6Send dataSize specified in step 5
7Send END indicator1byte

Stream

StepOperationData size
1Send START indicator1byte
2Send request id tied to this response1byte
3Send status code1byte
4If stream continues: Send CONTINUE
If stream finished: Send END
1byte
5Send data size4byte
6Send dataSize specified in step 5
7Goto step 4
If status code is other than 0, event stream endpoints respond with normal response.

About streaming

Although it is called streaming, this is not primarily intended for streaming, but rather to save memory when passing large vec.
If a request/response is streaming, its size should be greater than 0 so it can be distinguished from an End indicator.

RRP-hid protocol

RRP-hid protocol is low level protocol like udp to transfer RRP through hid.
  • Use Output Report for request
    • Output report is [u8; 32]
  • Use Input Report for response
    • Input report is [u8; u32]
      (This report descriptor's structure is same as via's one.)
  • Usage page id: 0xFF70, Usage id: 0x71
One report is considered as a packet. A packet contains the RRP data and the size of the data included in the packet. So the data structure looks like this.
1: Data size (1byte, 0-31)
2: Data (arbitrary size specified in Data Size)
Report size is always 32 bytes, and remained bytes are undefined (usually filled with 0).
This protocol doesn't have flow control. While one rrp request or response is ongoing, other requests or responses muse be blocked.

Descriptor

Changed usage id of rmk's via code
#[gen_hid_descriptor(
(collection = APPLICATION, usage_page = 0xFF70, usage = 0x71) = {
(usage = 0x72, logical_min = 0x0) = {
#[item_settings data,variable,absolute] input_data=input;
};
(usage = 0x73, logical_min = 0x0) = {
#[item_settings data,variable,absolute] output_data=output;
};
}
)]
pub(crate) struct ViaReport {
pub(crate) input_data: [u8; 32],
pub(crate) output_data: [u8; 32],
}