2020-02-23 01:35:11 +00:00
|
|
|
// Copyright 2015-2020 Mobilinkd LLC <rob@mobilinkd.com>
|
2018-08-27 03:28:24 +00:00
|
|
|
// All rights reserved.
|
|
|
|
|
2020-02-23 01:35:11 +00:00
|
|
|
#pragma once
|
2018-08-27 03:28:24 +00:00
|
|
|
|
|
|
|
#include "HdlcFrame.hpp"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace mobilinkd { namespace tnc { namespace hdlc {
|
|
|
|
|
2019-06-09 03:49:16 +00:00
|
|
|
struct NewDecoder
|
|
|
|
{
|
|
|
|
enum class State {IDLE, SYNC, RECEIVE};
|
|
|
|
using frame_type = IoFrame;
|
|
|
|
using result_type = std::tuple<frame_type*, uint8_t>;
|
|
|
|
using optional_result_type = frame_type*;
|
|
|
|
|
|
|
|
static constexpr uint8_t STATUS_OK{0x01};
|
|
|
|
static constexpr uint8_t STATUS_USER_CANCEL{0x02};
|
|
|
|
static constexpr uint8_t STATUS_FRAME_ABORT{0x04};
|
|
|
|
static constexpr uint8_t STATUS_FRAME_ERROR{0x08};
|
|
|
|
static constexpr uint8_t STATUS_NO_CARRIER{0x10};
|
|
|
|
static constexpr uint8_t STATUS_CRC_ERROR{0x20};
|
|
|
|
|
2020-02-23 01:35:11 +00:00
|
|
|
static constexpr uint16_t VALID_CRC = 0xf0b8;
|
2019-06-09 03:49:16 +00:00
|
|
|
|
|
|
|
State state{State::IDLE};
|
|
|
|
|
|
|
|
uint8_t buffer{0};
|
|
|
|
|
|
|
|
uint8_t bits{0};
|
2020-02-23 01:35:11 +00:00
|
|
|
uint8_t report_bits{0};
|
2019-06-09 03:49:16 +00:00
|
|
|
uint8_t ones{0};
|
|
|
|
bool flag{0};
|
2020-03-06 02:30:13 +00:00
|
|
|
bool had_dcd{false};
|
2020-02-23 01:35:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell the demodulator to return all "passable" HDLC frames. These
|
|
|
|
* are frames which consist of an even multiple of eight bits and are
|
|
|
|
* up to 330 bytes, but which do not have a valid checksum.
|
|
|
|
*/
|
2019-06-09 03:49:16 +00:00
|
|
|
bool passall{false};
|
|
|
|
|
2020-03-06 02:30:13 +00:00
|
|
|
enum class DCD { ON, PARTIAL, OFF };
|
|
|
|
|
|
|
|
DCD dcd{DCD::PARTIAL};
|
|
|
|
|
2019-06-09 03:49:16 +00:00
|
|
|
frame_type* packet{nullptr};
|
|
|
|
|
|
|
|
NewDecoder(bool pass_all=false)
|
|
|
|
: passall(pass_all)
|
|
|
|
{}
|
|
|
|
|
2020-02-23 01:35:11 +00:00
|
|
|
bool can_pass(uint8_t status) const
|
|
|
|
{
|
|
|
|
return status == STATUS_OK or (passall and status == STATUS_CRC_ERROR);
|
|
|
|
}
|
|
|
|
|
2019-06-09 03:49:16 +00:00
|
|
|
optional_result_type operator()(bool input, bool pll_lock);
|
|
|
|
uint8_t process(bool input, bool pll_lock);
|
2020-02-23 21:58:08 +00:00
|
|
|
void setPassall(bool enabled)
|
|
|
|
{
|
|
|
|
passall = enabled;
|
|
|
|
}
|
2020-03-06 02:30:13 +00:00
|
|
|
|
|
|
|
void setDCD(DCD config)
|
|
|
|
{
|
|
|
|
dcd = config;
|
|
|
|
}
|
2020-04-15 02:02:15 +00:00
|
|
|
|
|
|
|
bool active() const
|
|
|
|
{
|
|
|
|
return state != State::IDLE;
|
|
|
|
}
|
2019-06-09 03:49:16 +00:00
|
|
|
};
|
|
|
|
|
2018-08-27 03:28:24 +00:00
|
|
|
}}} // mobilinkd::tnc::hdlc
|