00001 #ifndef DAQSOCKET_HH
00002 #define DAQSOCKET_HH
00003
00004
00005
00006 #include <vector>
00007 #include <string>
00008 #include <map>
00009 #include "gmutex.hh"
00010 #include "sockutil.h"
00011
00012 #define DAQD_PORT 8088
00013
00014
00109
00117 struct DAQDChannel {
00119 char mName[50];
00121 int mGroup;
00123 int mRate;
00125 int mNum;
00127 int mBPS;
00129 int mDatatype;
00131 float mGain;
00133 float mSlope;
00135 float mOffset;
00137 char mUnit[40];
00138 };
00139
00144 struct DAQDRecHdr {
00146 int Blen;
00148 int Secs;
00150 int GPS;
00152 int NSec;
00154 int SeqNum;
00155 };
00156
00166 class DAQSocket {
00167 public:
00169 typedef std::pair<int, int> rate_bps_pair;
00171 typedef std::map<std::string, DAQDChannel> channellist;
00173 typedef channellist::iterator Channel_iter;
00174
00177 channellist mChannel;
00178
00181 DAQSocket();
00182
00187 explicit DAQSocket(const char* ipaddr, int ipport = DAQD_PORT,
00188 long RcvBufferLen = 16384);
00189
00192 ~DAQSocket();
00193
00201 int open (const char* ipaddr, int ipport = DAQD_PORT,
00202 long RcvBufferLen = 16384);
00203
00206 void close();
00207
00210 void flush();
00211
00214 bool isOpen() const {
00215 return mOpened;
00216 }
00217
00220 bool isOn() const {
00221 return mWriterType != NoWriter;
00222 }
00223
00230 int StopWriter();
00231
00237 int RequestFrames();
00238
00244 int RequestOnlineData (bool fast = false, long timeout = -1);
00245
00252 int RequestData (unsigned long start, unsigned long duration,
00253 long timeout = -1);
00254
00261 int RequestTrend (unsigned long start, unsigned long duration,
00262 bool mintrend = false, long timeout = -1);
00263
00268 int RequestNames(long timeout = -1);
00269
00277 int WaitforData (bool poll = false);
00278
00283 int AddChannel (const DAQDChannel& chns);
00284
00289 int AddChannel(const char* chan,
00290 rate_bps_pair rb = rate_bps_pair (0, 0));
00291
00294 void RmChannel(const char* chan);
00295
00302 int GetData(char* buf, long len, long timeout = -1);
00303
00312 int GetData (char** buf, long timeout = -1);
00313
00321 long GetName(char *buf, long len);
00322
00328 long GetFrame(char *buf, long len);
00329
00338 int Available (DAQDChannel list[], long N);
00339
00346 int Available (std::vector<DAQDChannel>& list);
00347
00352 int Times (unsigned long& start, unsigned long& duration,
00353 long timeout = -1);
00358 int TimesTrend (unsigned long& start, unsigned long& duration,
00359 bool mintrend = false, long timeout = -1);
00360
00367 void setDebug(bool debug=true) {
00368 mDebug = debug;}
00369
00376 void setAbort (bool* abort) {
00377 mAbort = abort;}
00378
00383 bool TestOpen(void) {
00384 return mOpened;}
00385
00390 float Version(void) {
00391 return mVersion + 0.01*mRevision;}
00392
00393 private:
00405 int SendRequest(const char* text, char *reply=0, long length=0,
00406 long *Size=0, wait_time maxwait=-1);
00407
00413 int RecvRec(char *buf, long len, bool readall=false,
00414 wait_time maxwait=-1);
00415
00419 int SendRec(const char *buffer, long length, wait_time maxwait = -1);
00420
00426 int RecvData(char *buf, long len, DAQDRecHdr* hdr=0, long timeout = -1);
00427
00433 int RecvData(char **buf, long timeout = -1);
00434
00435 private:
00438 mutable thread::recursivemutex mux;
00439
00442 bool mOpened;
00443
00446 bool mDebug;
00447
00450 int mSocket;
00451
00454 long mRcvBuffer;
00455
00459 bool mGetAll;
00460
00463 bool mReorder;
00464
00467 char mWriter[8];
00468
00474 enum {NoWriter, NameWriter, DataWriter, FrameWriter, FastWriter}
00475 mWriterType;
00476
00479 int mOffline;
00480
00483 int mVersion;
00484
00487 int mRevision;
00488
00491 bool* mAbort;
00492
00493 };
00494
00497 #endif // DAQSOCKET_HH
00498