From d4bb25c112cae6a214c6bfb0a8f07194baa13ff0 Mon Sep 17 00:00:00 2001 From: Raine Date: Sun, 15 Oct 2023 18:06:18 +0200 Subject: [PATCH] feat: packet error checking --- doc/proto.md | 65 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/doc/proto.md b/doc/proto.md index ee37761..4d06b7d 100644 --- a/doc/proto.md +++ b/doc/proto.md @@ -16,13 +16,14 @@ Packets are sent in big endian. | `0x00` | 1 byte | `version` | This describes the version of the packet | `0x01` | | `0x01` | 4 bytes | `src` | This describes who sent the packet a.k.a. source device id | `0xAABBCCDD` | | `0x05` | 4 bytes | `dest` | This describes who the packet is for a.k.a. destination device id | `0xAABBCCDD` | -| `0x09` | 4 bytes | `packet_id` | This is the unique identifier of the packet | `0xFAB1B39D` | -| `0x0D` | 4 bytes | `reply_to` | This describes what this packet is replying to, if initial message, value is `0x0` | `0x00000000` | -| `0x09` | 1 byte | `command` | This describes what kind of command is sent | `0x00` | -| `0x11` | 2 bytes | `data_length` | This describes the length of the data in bytes | `0x0001` | -| `0x13` | `<0x11-0x12:data_length>` | `data` | This is the data of the command | `0x00` | +| `0x09` | 4 bytes | `checksum` | This is the CRC32 checksum of the *whole packet*. | `0x00000000` | +| `0x0D` | 4 bytes | `packet_id` | This is the unique identifier of the packet | `0xFAB1B39D` | +| `0x11` | 4 bytes | `reply_to` | This describes what this packet is replying to, if initial message, value is `0x0` | `0x00000000` | +| `0x12` | 1 byte | `command` | This describes what kind of command is sent | `0x00` | +| `0x13` | 2 bytes | `data_length` | This describes the length of the data in bytes | `0x0001` | +| `0x15` | `<0x11-0x12:data_length>` | `data` | This is the data of the command | `0x00` | -# Request / Response +# Packets in practice ## Statuses @@ -39,6 +40,13 @@ The "reserved" column (if present) will state what should be filled in by each s - "request": this should only be filled in the request. - "response": this should only be filled in the response. +# Error checking + +If the CRC32 doesn't match up the receiver will send a `0x0E` (error) packet to the probable source. +The error code `0x01`/`net_broken_packet` should be used. The metadata may contain some textual info on what went wrong. +The master will not track the broken packet's `packet_id`, so the slave can send it again. + + # Data types Domo has a data framework reliant on data types. @@ -84,7 +92,7 @@ This command will register a node. | offset | size | name | description | example | |--------|---------|-------------|------------------------------------------------|--------------| -| `0x13` | 4 bytes | `device_id` | the device identifier. (reserved for response) | `0x00000000` | +| `0x15` | 4 bytes | `device_id` | the device identifier. (reserved for response) | `0x00000000` | #### Example request @@ -114,9 +122,9 @@ there is no extra data required. | offset | size | name | description | reserved | example | |--------|-----------|-----------------|---------------------------------------------|----------|---------| -| `0x13` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | -| `0x33` | 1 byte | `data_type` | The type of data; see "Data types". | no | `0x01` | -| `0x34` | **1 bit** | `read_only` | Whether the property is readonly. | no | `0b0` | +| `0x15` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | +| `0x35` | 1 byte | `data_type` | The type of data; see "Data types". | no | `0x01` | +| `0x36` | **1 bit** | `read_only` | Whether the property is readonly. | no | `0b0` | ### `0x04` - Remove property @@ -124,7 +132,7 @@ there is no extra data required. | offset | size | name | description | reserved | example | |--------|----------|-----------------|---------------------------------------------|----------|---------| -| `0x13` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | +| `0x15` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | ### `0x0E` - Error @@ -134,19 +142,20 @@ Send a packet to state an error occurred. | offset | size | name | description | example | |--------|-------------------------------|-------------------|---------------------------------|----------| -| `0x13` | 1 byte | `error_code` | error code; check 'Error codes' | `0x00` | -| `0x14` | 2 bytes | `metadata_length` | metadata length | `0x0000` | -| `0x16` | `<0x14-0x15:metadata_length>` | `metadata` | metadata | | +| `0x15` | 1 byte | `error_code` | error code; check 'Error codes' | `0x00` | +| `0x16` | 2 bytes | `metadata_length` | metadata length | `0x0000` | +| `0x18` | `<0x14-0x15:metadata_length>` | `metadata` | metadata | | #### Error codes -| `status_code` | name | description | -|---------------|------------------------|----------------------------------------------------------------------------------------------| -| `0x00` | `net_duplicate_packet` | `reply_to` packet is invalid because another packet was sent recently with same `packet_id`. | -| `0x01` | `net_broken_packet` | recent packet was broken. | -| `0x1*` | `errc_*` | **Client errors** | -| `0x10` | `errc_not_registered` | client is not registered | -| `0x2*` | `errs_*` | **Server errors** | +| `status_code` | name | description | recoverable | +|---------------|------------------------|----------------------------------------------------------------------------------------------|-----------------------------------| +| `0x00` | `net_duplicate_packet` | `reply_to` packet is invalid because another packet was sent recently with same `packet_id`. | resend with different `packet_id` | +| `0x01` | `net_broken_packet` | recent packet was broken. | resend packet | +| `0x02` | `net_invalid_packet` | the packet sent is not valid | send packet with proper values | +| `0x1*` | `errc_*` | **Client errors** | | +| `0x10` | `errc_not_registered` | client is not registered | register client | +| `0x2*` | `errs_*` | **Server errors** | | ## `0x1*` - Properties control @@ -158,9 +167,9 @@ Get a properties value | offset | size | name | description | reserved | example | |--------|-------------------------|-----------------|---------------------------------------------|----------|---------| -| `0x13` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | -| `0x33` | 1 byte | `data_type` | The type of the data. | response | `0x00` | -| `0x34` | determined by data type | `data` | The actual data. | response | | +| `0x15` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | +| `0x35` | 1 byte | `data_type` | The type of the data. | response | `0x00` | +| `0x36` | determined by data type | `data` | The actual data. | response | | ### `0x11` - Set property @@ -168,9 +177,9 @@ Get a properties value | offset | size | name | description | reserved | example | |--------|-------------------------|-----------------|---------------------------------------------|----------|---------| -| `0x13` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | -| `0x33` | 1 byte | `data_type` | The type of the data. | no | `0x00` | -| `0x34` | determined by data type | `data` | The actual data. | no | | +| `0x15` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | +| `0x35` | 1 byte | `data_type` | The type of the data. | no | `0x00` | +| `0x36` | determined by data type | `data` | The actual data. | no | | ### `0x12` - Reset property @@ -178,4 +187,4 @@ Get a properties value | offset | size | name | description | reserved | example | |--------|----------|-----------------|---------------------------------------------|----------|---------| -| `0x13` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | \ No newline at end of file +| `0x15` | 32 bytes | `property_name` | The name of the property as a UTF-8 string. | no | "Power" | \ No newline at end of file