#ifndef POSIX_APP_HDLC_INTERFACE_HPP_
#define POSIX_APP_HDLC_INTERFACE_HPP_
#include "openthread-posix-config.h"
#include "platform-posix.h"
#include "lib/hdlc/hdlc.hpp"
#include "lib/spinel/spinel_interface.hpp"
#if OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_UART
namespace ot {
namespace Posix {
class HdlcInterface
{
public:
HdlcInterface(Spinel::SpinelInterface::ReceiveFrameCallback aCallback,
void * aCallbackContext,
Spinel::SpinelInterface::RxFrameBuffer & aFrameBuffer);
~HdlcInterface(void);
otError Init(Arguments &aArguments);
void Deinit(void);
otError SendFrame(const uint8_t *aFrame, uint16_t aLength);
otError WaitForFrame(uint64_t aTimeoutUs);
void UpdateFdSet(fd_set &aReadFdSet, fd_set &aWriteFdSet, int &aMaxFd, struct timeval &aTimeout);
void Process(const RadioProcessContext &aContext);
#if OPENTHREAD_POSIX_VIRTUAL_TIME
void Process(const Event &aEvent) { Decode(aEvent.mData, aEvent.mDataLength); }
#endif
private:
void Read(void);
otError WaitForWritable(void);
otError Write(const uint8_t *aFrame, uint16_t aLength);
void Decode(const uint8_t *aBuffer, uint16_t aLength);
static void HandleHdlcFrame(void *aContext, otError aError);
void HandleHdlcFrame(otError aError);
static int OpenFile(const char *aFile, Arguments &aArguments);
#if OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
static int ForkPty(const char *aCommand, const char *aArguments);
#endif
enum
{
kMaxFrameSize = Spinel::SpinelInterface::kMaxFrameSize,
kMaxWaitTime = 2000, };
Spinel::SpinelInterface::ReceiveFrameCallback mReceiveFrameCallback;
void * mReceiveFrameContext;
Spinel::SpinelInterface::RxFrameBuffer & mReceiveFrameBuffer;
int mSockFd;
Hdlc::Decoder mHdlcDecoder;
HdlcInterface(const HdlcInterface &);
HdlcInterface &operator=(const HdlcInterface &);
};
} }
#endif #endif