Skip to content

Commit

Permalink
Add firmware update functionality, fix packet parser bugs
Browse files Browse the repository at this point in the history
* Support for CRC32 packets
* Packet parser rewrite (packet was not parsed when extra 0xaa or 0x55 byte is met)
  • Loading branch information
MultiMote committed Jan 9, 2025
1 parent 5f1f984 commit b023425
Show file tree
Hide file tree
Showing 14 changed files with 955 additions and 89 deletions.
93 changes: 61 additions & 32 deletions docs/documents/niimbot_proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ WIP

## Packet structure

### Main packet

![](proto/packet.png)

* **Prefix** - prefix `0x03` is present in only one command - **Connect**.
Expand All @@ -18,41 +20,68 @@ WIP
* **Checksum** - calculated by XOR of all bytes from **Command** to the last byte of **Data** (inclusive).
* **Tail** - always 2 bytes (`0xAA` `0xAA`).

### CRC32 (firmware) packet

![](proto/crc32packet.png)

* **Head** - always 2 bytes (`0x55` `0x55`).
* **Command** - command (packet) identifier.
* **Index** - firmware chunk index, used only in `FirmwareChunk` and `In_RequestFirmwareChunk` packets, otherwise equals zero.
* **Data Length** - number of bytes of data.
* **Data** - data with **Data length** length.
* **Checksum** - crc32 checksum of all bytes from **Command** to the last byte of **Data** (inclusive).
* **Tail** - always 2 bytes (`0xAA` `0xAA`).

## List of packets

| Request ID | Name | Response ID(s) | [Simple](#simple-packet) |
| Request ID | Name | Response ID(s) | [Simple](#simple-packet) | CRC32 |
|------|------------|------|-|-|
| 0x01 | PrintStart | 0x02 || |
| 0x03 | PageStart | 0x04 || |
| 0x05 | PrinterLog | 0x06 || |
| 0x0b | AntiFake | 0x0c || |
| 0x13 | SetPageSize | 0x14 | | |
| 0x15 | PrintQuantity | 0x16 | | |
| 0x1a | RfidInfo | 0x1b || |
| 0x1c | RfidInfo2 | 0x1d || |
| 0x20 | PrintClear | 0x30 || |
| 0x21 | SetDensity | 0x31 | | |
| 0x23 | SetLabelType | 0x33 | | |
| 0x27 | SetAutoShutdownTime | 0x37 | | |
| 0x28 | PrinterReset | 0x38 || |
| 0x40 | PrinterInfo | 0x4f, 0x47, 0x4d, 0x4a, 0x41, 0x4c, 0x43, 0x46, 0x48, 0x4b, 0x49, 0x42 | | |
| 0x54 | RfidSuccessTimes | 0x64 || |
| 0x58 | SoundSettings | 0x68 | | |
| 0x59 | CalibrateHeight | 0x69 | | |
| 0x5a | PrintTestPage | 0x6a || |
| 0x70 | WriteRFID | 0x71 | | |
| 0x83 | [PrintBitmapRowIndexed](#printbitmaprowindexed) | ⚠ one way | | |
| 0x84 | [PrintEmptyRow](#printemptyrow) | ⚠ one way | | |
| 0x85 | [PrintBitmapRow](#printbitmaprow) | ⚠ one way | | |
| 0x8e | LabelPositioningCalibration | 0x8f || |
| 0x91 | FirmwareCrc | ⚠ one way | ||
| 0x92 | FirmwareCommit | ⚠ one way | ||
| 0x9b | FirmwareChunk | ⚠ one way | ||
| 0x9c | FirmwareNoMoreChunks | ⚠ one way | ||
| 0xa3 | PrintStatus | 0xb3 || |
| 0xa5 | PrinterStatusData | 0xb5 || |
| 0xaf | PrinterConfig | 0xbf | | |
| 0xc1 | Connect | 0xc2 || |
| 0xda | CancelPrint | 0xd0 || |
| 0xdc | Heartbeat | 0xde, 0xdf, 0xdd, 0xd9 | | |
| 0xe3 | PageEnd | 0xe4 || |
| 0xf3 | PrintEnd | 0xf4 || |
| 0xf5 | StartFirmwareUpgrade | 0xf6 | | |

Comes from printer only:

| Request ID | Name | Client response ID | CRC32 |
|------|------------|------|-|
| 0x01 | PrintStart | 0x02 ||
| 0x03 | PageStart | 0x04 ||
| 0x05 | PrinterLog | 0x06 ||
| 0x0b | AntiFake | 0x0c ||
| 0x13 | SetPageSize | 0x14 | |
| 0x15 | PrintQuantity | 0x16 | |
| 0x1a | RfidInfo | 0x1b ||
| 0x1c | RfidInfo2 | 0x1d ||
| 0x20 | PrintClear | 0x30 ||
| 0x21 | SetDensity | 0x31 | |
| 0x23 | SetLabelType | 0x33 | |
| 0x27 | SetAutoShutdownTime | 0x37 | |
| 0x28 | PrinterReset | 0x38 ||
| 0x40 | PrinterInfo | 0x4f, 0x47, 0x4d, 0x4a, 0x41, 0x4c, 0x43, 0x46, 0x48, 0x4b, 0x49, 0x42 | |
| 0x54 | RfidSuccessTimes | 0x64 ||
| 0x58 | SoundSettings | 0x68 | |
| 0x59 | CalibrateHeight | 0x69 | |
| 0x5a | PrintTestPage | 0x6a ||
| 0x70 | WriteRFID | 0x71 | |
| 0x83 | [PrintBitmapRowIndexed](#printbitmaprowindexed) | ⚠ one way | |
| 0x84 | [PrintEmptyRow](#printemptyrow) | ⚠ one way | |
| 0x85 | [PrintBitmapRow](#printbitmaprow) | ⚠ one way | |
| 0x8e | LabelPositioningCalibration | 0x8f ||
| 0xa3 | PrintStatus | 0xb3 ||
| 0xa5 | PrinterStatusData | 0xb5 ||
| 0xaf | PrinterConfig | 0xbf | |
| 0xc1 | Connect | 0xc2 ||
| 0xda | CancelPrint | 0xd0 ||
| 0xdc | Heartbeat | 0xde, 0xdf, 0xdd, 0xd9 | |
| 0xe3 | PageEnd | 0xe4 ||
| 0xf3 | PrintEnd | 0xf4 ||
| 0xe0 | In_PrinterPageIndex | |
| 0x90 | In_RequestFirmwareCrc | 0x91 ||
| 0x9a | In_RequestFirmwareChunk | 0x9b ||
| 0x9d | In_FirmwareCheckResult | ||
| 0x9e | In_FirmwareResult | ||

## Packet details

Expand Down
Binary file added docs/documents/proto/crc32packet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b023425

Please sign in to comment.