48 lines
941 B
C++
48 lines
941 B
C++
#ifndef CMD_H_
|
|
#define CMD_H_
|
|
|
|
#include <stdint.h>
|
|
#include <Ethernet.h>
|
|
#include <EthernetServer.h>
|
|
#include <EthernetClient.h>
|
|
#include <WString.h>
|
|
|
|
static const uint8_t NUM_OF_COMMANDS = 10;
|
|
|
|
class CmdServer;
|
|
|
|
class Cmd {
|
|
public:
|
|
virtual ~Cmd() {};
|
|
void setClient(EthernetClient *p_client) { m_client = p_client; };
|
|
void setServer(EthernetServer *p_server) { m_server = p_server; };
|
|
virtual String exec(String params) =0;
|
|
virtual String getCmdName() =0;
|
|
virtual String getHelp() =0;
|
|
virtual void registerYourself(CmdServer *cmdServer);
|
|
protected:
|
|
EthernetClient *m_client;
|
|
EthernetServer *m_server;
|
|
};
|
|
|
|
|
|
|
|
class CmdServer {
|
|
public:
|
|
CmdServer(uint16_t port);
|
|
void begin();
|
|
void exec();
|
|
void registerCmd(Cmd *cmdObj);
|
|
private:
|
|
void parseCommand();
|
|
EthernetServer m_server;
|
|
EthernetClient m_client;
|
|
String cmd;
|
|
String params;
|
|
uint8_t cmdListIdx;
|
|
Cmd *cmdList[NUM_OF_COMMANDS];
|
|
};
|
|
|
|
|
|
#endif /* CMD_H_ */
|