#ifndef WSCLIENT_H #define WSCLIENT_H #include "seasocks/Server.h" #include "seasocks/WebSocket.h" #include #include #include #include "structures.h" static constexpr int DATASIZE = 0x2000; enum ParserState { StateIdle = 0, StateHeader, StateData, StateReply, }; class WsClient { seasocks::WebSocket * ws; int & pollfd; TrigerSettings trigerSettings; bool running; int fd; const size_t reclen; char * recbuff; int recindex; ParserState state; int packet_cnt; char * packet_buf; SendHeader header; public: explicit WsClient(seasocks::WebSocket * p, int & fd) : ws (p), pollfd (fd), trigerSettings(), running(false), fd(0), reclen(0x4000ul), recindex(0), state(StateIdle), packet_cnt(0) { recbuff = new char [reclen]; packet_buf = new char [DATASIZE]; } virtual ~WsClient() { delete [] recbuff; delete [] packet_buf; }; bool start (); void stop (); void send (const char * data); void receive (); protected: void SendTrigerMode (int n); void SendTrigerEdge (int n); void SendTrigerChan (int n); void SendBaseRange (int n); void SettingChanged (int n); void SendVoltage (int ch, int n); void Start (); void send_trig_mode (); int write (const char * data, const int len); void received_pack (); void parse_input (const char * data, const long len); void parse_header (); void parse_packet (); void parse_reply (const char * data, const int len); }; #endif // WSCLIENT_H