58 lines
1.1 KiB
C++

/*
* DTE.h
*
* Author: Neta Yahav, Pavel Brychta
*/
#pragma once
#include <Arduino.h>
class DTE {
public:
enum CommandResult {
EXPECT_BUSY,
EXPECT_TIMEOUT,
EXPECT_DELAY,
EXPECT_RESULT
};
protected:
String mBuffer;
Stream & mStream;
unsigned int mBufferSize;
String mResponse[3];
unsigned long mTimeout;
unsigned long mTick;
unsigned int mMatch;
CommandResult mResult;
public:
DTE(Stream & stream, unsigned int size);
~DTE() = default;
void SendCommand(const char * command, unsigned long timeout, const char * response1, const char * response2 = nullptr, const char * response3 = nullptr);
void SendCommand(const __FlashStringHelper * command, unsigned long timeout, const char * response1, const char * response2 = nullptr, const char * response3 = nullptr);
void Delay(unsigned long delay);
bool getIsBusy();
CommandResult getResult();
[[nodiscard]] unsigned int getMatch() const;
String & getBuffer();
bool buffer();
void clearBuffer();
protected:
void flush();
void process();
}; // DTE