1 // Copyright 2021 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
16 #include "pw_assert/light.h"
17 #include "pw_router/packet_parser.h"
21 // HDLC frame parser for routers that operates on wire-encoded frames.
23 // Currently, this assumes 1-byte HDLC address fields. An optional address_bits
24 // value can be provided to the constructor to use a smaller address size.
25 class WirePacketParser final : public router::PacketParser {
27 constexpr WirePacketParser(uint8_t address_bits = 8)
28 : address_(0), address_shift_(8 - address_bits) {
29 PW_ASSERT(address_bits <= 8);
32 // Verifies and parses an HDLC frame. Packet passed in is expected to be a
33 // single, complete, wire-encoded frame, starting and ending with a flag.
34 bool Parse(ConstByteSpan packet) final;
36 std::optional<uint32_t> GetDestinationAddress() const final {
42 uint8_t address_shift_;
45 } // namespace pw::hdlc