## 1. Protocol Management Module

Version 2.0 adds a protocol management module to manage **hardware device protocols**, as shown below:

fastbee-protocol-base: the protocol parsing base module. This module is the core module that implements decoding and encoding through annotations; users do not need to care about how it is implemented.

fastbee-protocol-collect: the protocol collection module, which currently bundles decoding and encoding for JSON, modbus-rtu, and the encapsulated modbus-rtu.

<img src="../../../../business/v2/dev/images/protocol/protocol01.png" style="border:1px solid #ccc;border-radius:6px;" alt="Protocol management module page screenshot" loading="lazy" />

## 2. Protocol Definition

Displayed on the frontend as shown below:<br> <img src="../../../../business/v2/dev/images/protocol/protocol02.png" style="border:1px solid #ccc;border-radius:6px;" alt="Protocol definition page screenshot" loading="lazy" />

If you need to add a protocol in the protocol management module, the system implements it through annotations. The annotation is defined as follows:<br> <img src="../../../../business/v2/dev/images/protocol/protocol03.png" style="border:1px solid #ccc;border-radius:6px;" alt="Protocol definition page screenshot" loading="lazy" />

Below is an example of **adding code for the modbus-rtu protocol**:

The fields are explained as follows:

1. name: the protocol name
2. protocolCode: the protocol code, used by the system to identify the protocol and associate it with products; one product corresponds to one protocol code.
3. description: the protocol description (optional)

<img src="../../../../business/v2/dev/images/protocol/protocol04.png" style="border:1px solid #ccc;border-radius:6px;" alt="Protocol definition page screenshot" loading="lazy" />

When a device has data to decode or encode, the device matches a protocol in the system based on the protocol code in the product, and uses that protocol for decoding and encoding.

A defined decoding example is as follows:<br>
The class that actually performs decoding is: **<span dir="">ModbusMessageDecoder</span>**<br> <img src="../../../../business/v2/dev/images/protocol/protocol05.png" style="border:1px solid #ccc;border-radius:6px;" alt="Protocol definition page screenshot" loading="lazy" />

A defined encoding example is as follows:<br>
The class that actually performs encoding is: **<span dir="">ModbusMessageEncoder</span>**<br> <img src="../../../../business/v2/dev/images/protocol/protocol06.png" style="border:1px solid #ccc;border-radius:6px;" alt="Protocol definition page screenshot" loading="lazy" />

## 3. Annotation-Based Protocol Decoding and Encoding

<span dir="">The platform encapsulates a base package for decoding and encoding hardware device messages through annotations, namely the </span>fastbee-protocol-base module<span dir="">. For all kinds of hardware device messages, this annotation-based approach can be used to implement decoding and encoding,</span>

<span dir="">reducing the tedious work of backend developers in message data decoding and encoding.</span>

<span dir="">Field definitions of the **@Column** annotation:</span><br> <img src="../../../../business/v2/dev/images/protocol/protocol07.png" style="border:1px solid #ccc;border-radius:6px;" alt="Annotation-based protocol decoding and encoding screenshot" loading="lazy" />
