NDS2 access functions.


Classes

struct  signal_conv_t
 Data unit conversion structure. More...
struct  chan_req_t
 Channel request/status entry. More...
struct  daq_t
 NDS1/2 client status structure. More...
struct  daq_channel_t
 Channel description structure. More...
#define HEADER_LEN   16
typedef daq_block_header daq_block_t
enum  nds_version { nds_try = 0, nds_v1 = 1, nds_v2 = 2 }
int daq_clear_channel_list (daq_t *daq)
 Clear the channel list.
int daq_connect (daq_t *daq, const char *host, int port, enum nds_version version)
 Make a connection to the NDS1 server.
int daq_disconnect (daq_t *daq)
 Disconnect from the server.
const char * daq_get_channel_addr (daq_t *daq, const char *channel)
 Get a pointer to the data for the specified channel.
char * daq_get_channel_data (daq_t *daq, const char *channel, char *data)
 Copy channel data.
int daq_get_data_length (daq_t *daq, const char *channel)
 Get the channel data length.
chan_req_tdaq_get_channel_status (daq_t *daq, const char *channel)
 Get a pointer to channel data.
int daq_get_scaled_data (daq_t *daq, const char *channel, float *data)
 Calibrate and copy channel data.
void daq_init_channel (daq_channel_t *chan, const char *name, enum chantype ctype, double rate, daq_data_t dtype)
 Initialize a daq_channel_t structure.
int daq_recv_block_num (daq_t *daq)
 Receive block number.
int daq_recv_block (daq_t *daq)
 Receive a data block.
int daq_recv_next (daq_t *daq)
 Receive a data block.
int daq_recv_shutdown (daq_t *daq)
 Close the client connection.
int daq_recv_channels (daq_t *daq, daq_channel_t *channel, int num_channels, int *num_channels_received)
 Get a list of online channels.
int daq_recv_channel_list (daq_t *daq, daq_channel_t *channel, int num_channels, int *num_channels_received, time_t gps, enum chantype type)
 Get a list of channels.
long daq_recv_id (daq_t *daq)
 Receive an ID.
int daq_recv_source_list (daq_t *daq, char *sources, size_t max_len, time_t gps, long *str_len)
 Get a list of source frames.
int daq_request_channel (daq_t *daq, const char *name, enum chantype type, double rate)
 Add a channel to the request list.
int daq_request_channel_from_chanlist (daq_t *daq, daq_channel_t *channel)
 Add a channel to the request list.
int daq_request_data (daq_t *daq, time_t start, time_t end, time_t dt)
 Get requested data.
int daq_send (daq_t *daq, const char *command)
 send a command string.
int daq_startup (void)
 Initialize nds1/nds2 client subsystems.
const char * daq_strerror (int errornum)
 determine English equivalent of return code.
typedef enum chantype chantype_t
 Channel type code enumerator.
enum  chantype {
  cUnknown, cOnline, cRaw, cRDS,
  cSTrend, cMTrend, cTestPoint
}
 Channel type code enumerator. More...

Detailed Description

This module defines the NDS2 API. The C-functions provide a backward- compatible low level interface that may be used with either version of the NDS. These may used to implement the client server protocol defined elsewhere, e.g. classic NDS protocol or NDS protocol. A second high level interface is new to the API. This allows the user to make the server requests to either version of the NDS and without knowledge of the server protocol.

Define Documentation

#define HEADER_LEN   16

Block header structure length.


Typedef Documentation

typedef enum chantype chantype_t

Channel type code enumerator.

Define channel types. The channel types are used to distinguish the requested source of the data.

Remarks:
This expands on and replaces the channel group code in the NDS1 API which seems to have a very few values (0=normal fast channel, 1000=dmt trend channel, 1001=obsolete dmt channel).

typedef struct daq_block_header daq_block_t

Block header data type


Enumeration Type Documentation

enum chantype

Channel type code enumerator.

Define channel types. The channel types are used to distinguish the requested source of the data.

Remarks:
This expands on and replaces the channel group code in the NDS1 API which seems to have a very few values (0=normal fast channel, 1000=dmt trend channel, 1001=obsolete dmt channel).
Enumerator:
cUnknown  Unknown or unspecified default type.
cOnline  Online channel
cRaw  Archived raw data channel
cRDS  Processed/RDS data channel
cSTrend  Second trend data
cMTrend  Minute trend data
cTestPoint  Minute trend data

enum nds_version

NDS version enumerator

Enumerator:
nds_try  Try nds2 first, revert to nds1 on failure
nds_v1  nds1 server protocol
nds_v2  nds2 server protocol


Function Documentation

int daq_clear_channel_list ( daq_t daq  ) 

Clear the channel list.

Zero the number of requested channels. The number of allocates channel requests is not affected.

Parameters:
daq Pointer to client status structure.
Returns:
The id or -1.

int daq_connect ( daq_t daq,
const char *  host,
int  port,
enum nds_version  version 
)

Make a connection to the NDS1 server.

Connect to the DAQD server on the host identified by `ip' address. A socket is created using a socket() function call. The host address is found using the gethostbyname() function and a connection is established. The server is then asked for the protocol version and revision with "version;" and "revision;" commands. The version/revision are saved in the client structure.

Parameters:
daq Client status structure/
host Server host name string.
port Server port number.
version NDS version (nds_v1 or nds_v2).
Returns:
zero if successful or DAQD status code.

int daq_disconnect ( daq_t daq  ) 

Disconnect from the server.

Disconnect from the server by sending a "quit;" command and close the socket file descriptor.

Parameters:
daq Pointer to client status structure.
Returns:
DAQD status code.

const char* daq_get_channel_addr ( daq_t daq,
const char *  channel 
)

Get a pointer to the data for the specified channel.

Get a pointer to the data block from a specified channel name. Note that the returned address is in the daqd temporary buffer. It is likely that the data will be replaced during the next call to the daq_recv_next and possible that the data for the requested channel will be in a different location after the next request. If an error occurred in fetching the data, the returned pointer is NULL and the error code is stored in the daq->err_num.

Parameters:
daq Pointer to client status structure.
channel Pointer to null terminated channel name string.
Returns:
Pointer to channel data or NULL.

char* daq_get_channel_data ( daq_t daq,
const char *  channel,
char *  data 
)

Copy channel data.

Copy the data from a specified channel name to the target address. The target buffer must be large enough for the full data record. If the requested data are not available a NULL pointer is returned and the error code is stored in daq->err_num.

Parameters:
daq Pointer to client status structure.
channel Pointer to null terminated channel name string.
data pointer to a buffer to receive channel data.
Returns:
Pointer to channel data buffer or NULL.

chan_req_t* daq_get_channel_status ( daq_t daq,
const char *  channel 
)

Get a pointer to channel data.

Get a pointer specified channel request/status block.

Parameters:
daq Pointer to client status structure.
channel Pointer to null terminated channel name string.
Returns:
Pointer to channel request/status structure.

int daq_get_data_length ( daq_t daq,
const char *  channel 
)

Get the channel data length.

Get the number of bytes of data retrieved for the specified channel.

Parameters:
daq Pointer to client status structure.
channel Pointer to null terminated channel name string.
Returns:
Number of data bytes or 0 if channel not found.

int daq_get_scaled_data ( daq_t daq,
const char *  channel,
float *  data 
)

Calibrate and copy channel data.

Copy the data from a specified channel name to the target address. The data are converted to floats and scaled according to the linear transform specified by the NDS server. Complex data are not copied converted or scaled. The number of output data words is returned. It is up to the user to insure that the output array is large enough to accommodate the data.

Parameters:
daq Pointer to client status structure.
channel Pointer to null terminated channel name string.
data pointer to a buffer to receive calibrated channel data.
Returns:
Number of data words copied.

void daq_init_channel ( daq_channel_t chan,
const char *  name,
enum chantype  ctype,
double  rate,
daq_data_t  dtype 
)

Initialize a daq_channel_t structure.

Initialize a daq_channel_t structure with the specified data. If the channel type is _unknown and the name contains a trend channel suffix (e.g. .mean ) the type will be reset to a trend type in accordance with the specified rate. Trend channels are assigned a rate and data_type appropriate to the trend type. If a trend-type channel does not have an appropriate suffix, ".mean" is appended to the channel name.

Parameters:
chan Pointer to structure to be initialized
name Channel name
ctype Channel type code
rate Sample rate
dtype Data type.

int daq_recv_block ( daq_t daq  ) 

Receive a data block.

Receive one data block (data channel samples). A transmission buffer is allocated as needed and its pointer is assigned to `daq->tb'. The block size is assigned to `daq->tb_size'. A zero length block consists of the block header and no data. It is sent by the server when it fails to find the data for the GPS second, specified in the block header (Note: this can only happen for the off-line data request). If channel reconfiguration has occurred, the server sends a special reconfiguration data block. For the client it means he needs to reread channel data conversion variables and status from the *daq structure.

Parameters:
daq Pointer to client status structure.
Returns:
  • >0: Number bytes of sample data read
  • 0: Zero length data block is received
  • -1: Error
  • -2: Channel reconfiguration

int daq_recv_block_num ( daq_t daq  ) 

Receive block number.

Receive a data block number or zero for online data.

Parameters:
daq Pointer to client status structure.
Returns:
Block number or -1 on error.

int daq_recv_channel_list ( daq_t daq,
daq_channel_t channel,
int  num_channels,
int *  num_channels_received,
time_t  gps,
enum chantype  type 
)

Get a list of channels.

Get a list of channel names and information. A list of all channels available at the specified time and of the specified type is returned. A GPS time of zero indicates currently available channels. A type code of cUnknown (0) gives all channel types available at the specified gps time. Note that this will produce a list with multiple channel entries with identical names. The number of channels returned in *num_channels_received is the total number of channels available from the server and may exceed the number of channels for which space has been allocated. In fact, an efficient way to find out how much space is needed for the channel list is to call daq_recv_channel_list with num_channels set to zero and the channel list pointer set to NULL.

Remarks:
This function only works correctly with the NDS2 server. If a non-zero GPS or a data type other than cOnline is requested, the function returns DAQD_VERSION_MISMATCH and *num_channels_received is set to zero.
Parameters:
daq Pointer to client status structure.
channel List of daq_channel structures to receive information.
num_channels Number of channel structures allocated.
num_channels_received Pointer to integer to receive number of channels defined on server (may exceed num_channels ).
gps validity time (or zero for current channels)
type Limit list to specified type.
Returns:
DAQD status code.

int daq_recv_channels ( daq_t daq,
daq_channel_t channel,
int  num_channels,
int *  num_channels_received 
)

Get a list of online channels.

Get a list of online channel names and information. daq_recv_channels requests the channel information as appropriate for the server version. All channel data are then copied into the list. This function is included to allow backward compatibility with the classic nds interface and is implemented with a call to daq_recv_channel_list. See the documentation for daq_recv_channel_list for further details.

Parameters:
daq Pointer to client status structure.
channel List of daq_channel structures to receive information.
num_channels Number of channel structures allocated.
num_channels_received Number of channels defined.
Returns:
DAQD status code.

long daq_recv_id ( daq_t daq  ) 

Receive an ID.

Receive an eight-digit hex ID.

Parameters:
daq Pointer to client status structure.
Returns:
The id or -1

int daq_recv_next ( daq_t daq  ) 

Receive a data block.

Receive one data block, handle all additional protocol, e.g. channel reconfiguration, and swap bytes according to channel list. Data are stored in the internal buffer. For NDS2 requests, the request list is updated with data length, offset, data type and status of each channel. For NDS1 the request list is updated with the inferred lengths and offsets.

Parameters:
daq Pointer to client status structure.
Returns:
DAQD status code.

int daq_recv_shutdown ( daq_t daq  ) 

Close the client connection.

Close the data connection socket and free the allocated buffers (conversion list and transmission buffer).

Parameters:
daq Pointer to client status structure.
Returns:
DAQD status code.

int daq_recv_source_list ( daq_t daq,
char *  sources,
size_t  max_len,
time_t  gps,
long *  str_len 
)

Get a list of source frames.

Get a list of channel sources for the requested channels at the specified gps time. A GPS time of zero indicates currently available channels.

Remarks:
This function only works with the NDS2 server.
Parameters:
daq Pointer to client status structure.
sources List of daq_channel structures to receive information.
max_len Pre-allocated string length.
gps validity time (or zero for current channels)
str_len Output string length pointer.
Returns:
DAQD status code.

int daq_request_channel ( daq_t daq,
const char *  name,
enum chantype  type,
double  rate 
)

Add a channel to the request list.

Add the specified channel to the request list. If the type is set to the default value (cUnknown or 0), the channel type will be inferred from the channel name and sample rate as described in the documentation of daq_init_channel. A zero sample rate results in the full-bandwidth data of the specified type.

Parameters:
daq Pointer to client status structure.
name Pointer to null terminated name string.
type Channel type.
rate Requested sampling rate (in Hz).
Returns:
DAQD status code.

int daq_request_channel_from_chanlist ( daq_t daq,
daq_channel_t channel 
)

Add a channel to the request list.

Add the specified channel to the request list. The channel name data type, sample rate, etc are copied from the channel list entry.

Parameters:
daq Pointer to client status structure.
channel Pointer channel list entry.
Returns:
DAQD status code.

int daq_request_data ( daq_t daq,
time_t  start,
time_t  end,
time_t  dt 
)

Get requested data.

Request data for all channels added to the list for the specified interval and stride width. Data are recived from the start time to the end time in strides of dt seconds. An online data request is made if the start time is zero and only online channels are specified. Online request end times may be specified either as an absolute GPS or as a total data length in seconds (if end is greater than the current time). Note that the NDS1 protocol ignores the stride length specifier.

Parameters:
daq Pointer to client status structure.
start Start time (GPS) or 0 for online data.
end End time (GPS).
dt Time stride.
Returns:
Server response code.

int daq_send ( daq_t daq,
const char *  command 
)

send a command string.

Send a null-terminated command string to the server. Then read and return a response code.

Parameters:
daq Pointer to client status structure.
command Null terminated command text string.
Returns:
DAQD status code.

int daq_startup ( void   ) 

Initialize nds1/nds2 client subsystems.

System initialization.

Returns:
Error code or 0 on success.

const char* daq_strerror ( int  errornum  ) 

determine English equivalent of return code.

Return string equivalent to a return code.

Parameters:
errornum error return code.
Returns:
pointer to static error message string.


Generated on Fri Jul 9 11:41:23 2010 for nds2-client by  doxygen 1.4.7