#include <DAQSocket.hh>
Public Types | |
| typedef std::pair< int, int > | rate_bps_pair |
| pair representing data rate (in Hz) & byte per sample | |
|
typedef std::map< std::string, DAQDChannel > | channellist |
| list of channels: map between channel name and channel info | |
| typedef channellist::iterator | Channel_iter |
| channel list iterator | |
Public Member Functions | |
| DAQSocket () | |
| DAQSocket (const char *ipaddr, int ipport=DAQD_PORT, long RcvBufferLen=16384) | |
| ~DAQSocket () | |
| int | open (const char *ipaddr, int ipport=DAQD_PORT, long RcvBufferLen=16384) |
| Open a socket and connect it to a server. | |
| void | close () |
| void | flush () |
| bool | isOpen () const |
| bool | isOn () const |
| int | StopWriter () |
| int | RequestFrames () |
| Start reading frame data. | |
| int | RequestOnlineData (bool fast=false, long timeout=-1) |
| Start reading online CDS data. | |
| int | RequestData (unsigned long start, unsigned long duration, long timeout=-1) |
| Start reading CDS data. | |
| int | RequestTrend (unsigned long start, unsigned long duration, bool mintrend=false, long timeout=-1) |
| int | RequestNames (long timeout=-1) |
| int | WaitforData (bool poll=false) |
| int | AddChannel (const DAQDChannel &chns) |
| int | AddChannel (const char *chan, rate_bps_pair rb=rate_bps_pair(0, 0)) |
| void | RmChannel (const char *chan) |
| int | GetData (char *buf, long len, long timeout=-1) |
| Receive block of data in the CDS proprietary format. | |
| int | GetData (char **buf, long timeout=-1) |
| long | GetName (char *buf, long len) |
| long | GetFrame (char *buf, long len) |
| int | Available (DAQDChannel list[], long N) |
| List all known channels. | |
| int | Available (std::vector< DAQDChannel > &list) |
| List all known channels. | |
| int | Times (unsigned long &start, unsigned long &duration, long timeout=-1) |
| int | TimesTrend (unsigned long &start, unsigned long &duration, bool mintrend=false, long timeout=-1) |
| void | setDebug (bool debug=true) |
| void | setAbort (bool *abort) |
| bool | TestOpen (void) |
| float | Version (void) |
Public Attributes | |
| channellist | mChannel |
DAQSocket provides a client interface to the Network Data Server. The server provides data in the CDS proprietary format or as standard frames. The interface may also be used to list channel names, or to specify the channels to be read in.
| DAQSocket::DAQSocket | ( | ) |
Construct an unopened socket.
| DAQSocket::DAQSocket | ( | const char * | ipaddr, | |
| int | ipport = DAQD_PORT, |
|||
| long | RcvBufferLen = 16384 | |||
| ) | [explicit] |
Create a socket and connect it to a server. The network address argument has the same syntax as that passed to DAQSocket::open().
| DAQSocket::~DAQSocket | ( | ) |
Disconnect and close a socket.
| int DAQSocket::open | ( | const char * | ipaddr, | |
| int | ipport = DAQD_PORT, |
|||
| long | RcvBufferLen = 16384 | |||
| ) |
Open a socket and connect it to a server.
The argument, ipaddr, specifies the IP address of the node on which the network data server is running. It may be specified either as a symbolic name or as four numeric fields separated by dots. open()
| void DAQSocket::close | ( | ) |
Disconnect and close a socket.
| void DAQSocket::flush | ( | ) |
flushes the input data from the socket.
| bool DAQSocket::isOpen | ( | void | ) | const [inline] |
true if socket is open and connected
| bool DAQSocket::isOn | ( | void | ) | const [inline] |
true if request was alreday sent
| int DAQSocket::StopWriter | ( | ) |
Stop a data writer. This function effectively countermands the RequestXXX() functions. StopWriter returns either the server response code or -1 if no writer has been requested.
| int DAQSocket::RequestFrames | ( | ) |
Start reading frame data.
The network data server is requested to start a frame writer task. Only channels explicitly specified by AddChannel() will be written.
| int DAQSocket::RequestOnlineData | ( | bool | fast = false, |
|
| long | timeout = -1 | |||
| ) |
Start reading online CDS data.
The network data server is requested to start a net-writer task. Only channels explicitly specified by AddChannel() will be written.
| int DAQSocket::RequestData | ( | unsigned long | start, | |
| unsigned long | duration, | |||
| long | timeout = -1 | |||
| ) |
Start reading CDS data.
The network data server is requested to start a net-writer task for past data. Start time and duration are given in GPS seconds. Only channels explicitly specified by AddChannel() will be written.
| int DAQSocket::RequestTrend | ( | unsigned long | start, | |
| unsigned long | duration, | |||
| bool | mintrend = false, |
|||
| long | timeout = -1 | |||
| ) |
Start reading CDS trend data. The network data server is requested to start a trend net-writer task. Start time and duration are given in GPS seconds. Only channels explicitly specified by AddChannel() will be written.
| int DAQSocket::RequestNames | ( | long | timeout = -1 |
) |
Start reading file names. The network data server is requested to start a name writer task.
| int DAQSocket::WaitforData | ( | bool | poll = false |
) |
Wait for data to arrive. Execution is blocked until data are available to the socket. This can be used to wait for data after a request has been made. The calling function can then e.g. allocate a buffer before calling GetData(), GetName() or GetFrame(). If poll is true the function returns immediately with 1 if data is ready, or 0 if not.
| int DAQSocket::AddChannel | ( | const DAQDChannel & | chns | ) |
Add a channel to the request list. All channels may be added by specifying "all" instead of a channel name.
| int DAQSocket::AddChannel | ( | const char * | chan, | |
| rate_bps_pair | rb = rate_bps_pair(0, 0) | |||
| ) |
Add a channel to the request list. All channels may be added by specifying "all" instead of a channel name.
| void DAQSocket::RmChannel | ( | const char * | chan | ) |
Remove a channel from the request list.
| int DAQSocket::GetData | ( | char * | buf, | |
| long | len, | |||
| long | timeout = -1 | |||
| ) |
Receive block of data in the CDS proprietary format.
A single block of data (including the header) is received and copied into the specified buffer.
| int DAQSocket::GetData | ( | char ** | buf, | |
| long | timeout = -1 | |||
| ) |
Receive block of data in the CDS proprietary format. A single block of data (including the header) is received and copied into the specified buffer. The data length (excluding the header) is returned. GetData() returns -1 if an error is detected, or 0 if an end-of file record is found. A buffer of the correct length will be allocated and returned automatically. The caller is reponsible for deallocation using delete[].
| long DAQSocket::GetName | ( | char * | buf, | |
| long | len | |||
| ) |
Receive a file name. The next frame file name written by the NDS is copied to buf and the data length is returned. The GetName returns -1 if a name-writer hasn't been started, if the data buffer is too short, or if an error occurs in reading the data. GetData waits for a new message if one is not available from the socket.
| long DAQSocket::GetFrame | ( | char * | buf, | |
| long | len | |||
| ) |
Receive a data frame. A single data frame is received and copied to the specified buffer. The length of the Frame data is returned. GetFrame() returns -1 in case of an error or 0 if a trailer (end of file) block is received.
| int DAQSocket::Available | ( | DAQDChannel | list[], | |
| long | N | |||
| ) |
List all known channels.
The names, sample rates, etc. of all channels known by the server are copied into the channel list. The list is preallocated by the caller with N entries. Available() returns the number of entries found or -1 if an error occurred. If the number of entries is greater than N, only the first N are copied to list;
| int DAQSocket::Available | ( | std::vector< DAQDChannel > & | list | ) |
List all known channels.
The names, sample rates, etc. of all channels known by the server are copied into the channel vector. Available() returns the number of entries found or -1 if an error occurred.
| int DAQSocket::Times | ( | unsigned long & | start, | |
| unsigned long & | duration, | |||
| long | timeout = -1 | |||
| ) |
Known time intervals. The network data server is requested to return start time and duration of the data stored on disk.
| int DAQSocket::TimesTrend | ( | unsigned long & | start, | |
| unsigned long & | duration, | |||
| bool | mintrend = false, |
|||
| long | timeout = -1 | |||
| ) |
Known time intervals of trend data. The network data server is requested to return start time and duration of the trend data stored on disk.
| void DAQSocket::setDebug | ( | bool | debug = true |
) | [inline] |
Set debug mode. Setting debug mode to true causes the following to be printed to cout: all request text, the status code and reply text for each request, the header of each data block received and the length of each data/text block received and its buffer size.
| void DAQSocket::setAbort | ( | bool * | abort | ) | [inline] |
Set abort button. If the abort "button" is used, recv/send will periodically check if it has become true and if yes, abort the transaction. Make sure to set abort to false before calling a method that receives data or sends a request.
| bool DAQSocket::TestOpen | ( | void | ) | [inline] |
Test that connection is open. This is the only means of testing whether the creator was able to connect to a socket.
| float DAQSocket::Version | ( | void | ) | [inline] |
Get the server version ID. The version and revision numbers of the server software are returned in a single float as (Version + 0.01*Revision).
List of channel names to be read.
1.5.4