M5Unit-RF433 0.1.0 git rev:5415b86
Loading...
Searching...
No Matches
protocol_codec.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_RF433_CODEC_PROTOCOL_CODEC_HPP
11#define M5_UNIT_RF433_CODEC_PROTOCOL_CODEC_HPP
12
13#include "../rmt_item_types.hpp"
14
15namespace m5 {
16namespace unit {
17namespace rf433 {
18
29
36enum class CodecType : uint8_t {
37 M5RF433 = 0,
38 // Future protocol support (not yet implemented):
39 // EV1527, //!< EV1527 / HS1527 / RT1527 (24-bit code + sync)
40 // PT2262, //!< PT2262 / PT2272 (tri-state encoding)
41 // RadioHead, //!< RadioHead / VirtualWire ASK compatible
42 Custom = 255,
43};
44
50public:
51 explicit ProtocolCodec(CodecType t) : _type(t)
52 {
53 }
54 virtual ~ProtocolCodec() = default;
55
58 {
59 return _type;
60 }
61
64
70 virtual item_container_type encode(const uint8_t* payload, uint32_t payload_len) = 0;
72
75
84 virtual bool decode(const gpio::m5_rmt_item_t* items, uint32_t num, uint8_t* work_buf, uint16_t work_buf_size,
85 DecodeResult& result) = 0;
87
90
94 virtual uint8_t overhead() const = 0;
96
97private:
98 CodecType _type;
99};
100
101} // namespace rf433
102} // namespace unit
103} // namespace m5
104#endif
Abstract base class for RF433 protocol encoding/decoding.
Definition protocol_codec.hpp:49
virtual item_container_type encode(const uint8_t *payload, uint32_t payload_len)=0
Encode payload into a complete RMT frame (preamble + SOF + header + data + EOF)
virtual bool decode(const gpio::m5_rmt_item_t *items, uint32_t num, uint8_t *work_buf, uint16_t work_buf_size, DecodeResult &result)=0
Try to decode a valid frame from RMT items.
virtual uint8_t overhead() const =0
Maximum protocol overhead in bytes (excluding payload)
CodecType type() const
Get codec type for safe downcasting.
Definition protocol_codec.hpp:57
Top level namespace of M5Stack.
Unit-related namespace.
CodecType
Identifies the protocol codec implementation.
Definition protocol_codec.hpp:36
@ Custom
User-defined custom protocol.
@ M5RF433
M5Unit-RF433 original protocol (.
RMT related definition and function for RF433.
uint8_t communication_identifier_t
Communication identifier (0-255)
Definition rmt_item_types.hpp:29
std::vector< gpio::m5_rmt_item_t > item_container_type
Item container.
Definition rmt_item_types.hpp:28
Result of decoding a received frame.
Definition protocol_codec.hpp:23
uint8_t send_count
Send count (for duplicate detection)
Definition protocol_codec.hpp:25
uint16_t payload_offset
Offset to payload in decode buffer.
Definition protocol_codec.hpp:27
uint8_t payload_length
Payload length in bytes.
Definition protocol_codec.hpp:26