///////////////////////////////////////////////////////////////////////////////// // // nwthread.h is part of TestModbus-Client. // ///////////////////////////////////////////////////////////////////////////////// #ifndef _NWTHREAD_H_ #define _NWTHREAD_H_ #include #include #include #include #include #include "modbus.h" #include "tcp.h" enum { NWT_nothing, NWT_connect, NWT_running, NWT_error, NWT_close }; struct { int fc; int reg; int cnt; uint16_t data[0x100]; } typedef NWTReqResult; struct { int issend; int rawdatalen; char *rawdata; } typedef NWTRawData; struct { int type; char txt[]; } typedef NWTMessage; class NetworkThread { private: GMutex mutex; GThread *thread; int state; int req_new; // new request modbustcp_rq_header req_mbh; // .fc == 0 no request int req_timeout; // timeout[ms] struct timeval req_time; TCP tcp; std::string host, port; void SetState(int s); void GuiSendStatustext(int type, char* txt); void GuiSendResult(char *buffer, int len, modbustcp_rq_header *mbh_in); void BuildAndSendReadReq(char *buffer, int size); public: NetworkThread(); ~NetworkThread(); void Lock(); void UnLock(); int Connect(std::string dest_host, std::string dest_port); int Disconnect(); int GetState(); int SendRequestRead(int unitid, int fc, int reg, int num); void Thread(); }; #endif