nmxp_chan.h 6.81 KB
Newer Older
1 2
/*! \file
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
3
 * \brief Channels for Nanometrics Protocol Library
4 5 6 7 8 9
 *
 * Author:
 * 	Matteo Quintiliani
 * 	Istituto Nazionale di Geofisica e Vulcanologia - Italy
 *	quintiliani@ingv.it
 *
10
 * $Id: nmxp_chan.h,v 1.26 2009-08-31 12:16:41 mtheo Exp $
Matteo Quintiliani's avatar
Matteo Quintiliani committed
11
 *
12 13 14 15 16
 */

#ifndef NMXP_CHAN_H
#define NMXP_CHAN_H 1

17
#include <stdint.h>
18

19 20
#define NMXP_CHAN_MAX_SIZE_STR_PATTERN 20

Matteo Quintiliani's avatar
Matteo Quintiliani committed
21 22 23 24 25 26 27 28 29 30
/*! \brief Channel list */
typedef struct NMXP_META_CHAN_LIST {
    int32_t key;
    char name[12];
    int32_t start_time;
    int32_t end_time;
    char network[12];
    struct NMXP_META_CHAN_LIST *next;
} NMXP_META_CHAN_LIST;

31 32 33 34 35 36 37
typedef enum {
    NMXP_META_SORT_KEY = 1,
    NMXP_META_SORT_NAME,
    NMXP_META_SORT_START_TIME,
    NMXP_META_SORT_END_TIME
} NMXP_META_CHAN_LIST_SORT_TYPE;

38

39 40 41
/*! \brief Max number of channels */
#define MAX_N_CHAN 2000

42 43
#define NMXP_CHAN_MAX_SIZE_NAME 24

44 45 46
/*! \brief The key/name info for one channel */
typedef struct {
    int32_t key;
47
    char name[NMXP_CHAN_MAX_SIZE_NAME];
48 49 50 51 52 53 54 55
} NMXP_CHAN_KEY_NET;

/*! \brief Channel list */
typedef struct {
    int32_t number;
    NMXP_CHAN_KEY_NET channel[MAX_N_CHAN];
} NMXP_CHAN_LIST_NET;

56
/*! \brief The key/name info for one channel */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
57
typedef struct {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
58
    int32_t key;
59
    char name[12];
Matteo Quintiliani's avatar
Matteo Quintiliani committed
60
} NMXP_CHAN_KEY;
61

Matteo Quintiliani's avatar
Matteo Quintiliani committed
62 63
/*! \brief Channel list */
typedef struct {
64
    int32_t number;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
65 66
    NMXP_CHAN_KEY channel[MAX_N_CHAN];
} NMXP_CHAN_LIST;
67

68 69
/*! \brief Precis Channel item */
typedef struct {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
70
    int32_t key;
71
    char name[12];
72 73
    int32_t start_time;
    int32_t end_time;
74 75 76 77
} NMXP_CHAN_PRECISITEM;

/*! \brief Precis Channel list */
typedef struct {
78
    int32_t number;
79 80
    NMXP_CHAN_PRECISITEM channel[MAX_N_CHAN];
} NMXP_CHAN_PRECISLIST;
81

Matteo Quintiliani's avatar
Matteo Quintiliani committed
82 83 84 85 86 87 88 89
/*! \brief Type of Data */
typedef enum {
    NMXP_DATA_TIMESERIES	= 1,
    NMXP_DATA_SOH		= 2,
    NMXP_DATA_TRANSERIAL	= 6
} NMXP_DATATYPE;

/*! \brief Precis list request body */
90 91 92 93
typedef struct {
    int32_t instr_id;
    NMXP_DATATYPE datatype;
    int32_t type_of_channel;
94
} NMXP_PRECISLISTREQUEST;
95

Matteo Quintiliani's avatar
Matteo Quintiliani committed
96 97 98 99 100
/*! \brief Channel info request body */
typedef struct {
    int32_t key;
    char name[12];
    char network[12];
101
} NMXP_CHANNELINFORESPONSE;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
102 103 104 105 106

/*! \brief Channel info request body */
typedef struct {
    int32_t key;
    int32_t ignored;
107
} NMXP_CHANNELINFOREQUEST;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
108

109

110 111 112 113
/*! \brief Character separator for channel list */
#define sep_chan_list  ','


114 115 116
/*! \brief Return type of data from a channel key */
#define getDataTypeFromKey(key) ((key >> 8) & 0xff)

Matteo Quintiliani's avatar
Matteo Quintiliani committed
117 118 119
/*! \brief Return channel number from a channel key */
#define getChannelNumberFromKey(key) ((key) & 0x000f)

120

121

122 123
/*! \brief Copy station code and channel code from name
 *
124
 * \param net_dot_station_dot_channel string containing NET.STA.CHAN where NET. is optional
125
 * \param[out] station_code Pointer to string for station code
126 127
 * \param[out] channel_code Pointer to string for channel code
 * \param[out] network_code Pointer to string for station code
128 129 130 131 132 133 134
 *
 * \warning Parametes can not be NULL!
 *
 * \retval 1 on success
 * \retval 0 on error
 *
 */
135
int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *station_code, char *channel_code, char *network_code);
136 137


138 139
/*! \brief Match station_dot_channel against pattern, treating errors as no match.
 *
140 141
 * \param net_dot_station_dot_channel NET.STA.CHAN format (NET. is optional)
 * \param pattern N1.STA.?HZ or N2.STA.H?Z or STA.HH? or STA.?H? or ....
142 143 144 145 146 147 148
 *
 * \retval 1 for match
 * \retval 0 for no match
 * \retval -1 on error for invalid pattern
 * \retval -2 on error for invalid station_dot_channel
 *
 */
149
int nmxp_chan_match(const char *net_dot_station_dot_channel, char *pattern);
150 151 152



153
/*! \brief Looks up a channel key in the list using the name
154
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
155 156
 * \param name Channel name.
 * \param channelList Channel list.
157
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
158
 * \return Key of the channel with name. -1 On error.
159 160
 *
 */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
161
int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList);
162

163 164 165 166 167 168 169 170 171

/*! \brief Looks up a channel name in the list using a key
 *
 * \param key Channel key.
 * \param channelList Channel list.
 *
 * \return Index of channel with key. -1 on error.
 *
 */
172
int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList);
173 174


175
/*! \brief Looks up a channel name in the list using a key
176
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
177 178
 * \param key Channel key.
 * \param channelList Channel list.
179
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
180
 * \return Name of channel with key. NULL on error.
181
 *
182 183
 * \warning Returned value will need to be freed!
 *
184
 */
185
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList);
186

187

188 189 190 191 192 193 194 195 196 197
/*! \brief Looks up a channel with specified data type.
 *
 * \param channelList Channel list.
 * \param dataType Type of channel.
 *
 * \return Channel list with specified dataType. It will need to be freed!
 *
 * \warning Returned value will need to be freed!
 *
 */
198
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType);
199

200

201 202 203 204
/*! \brief Looks up a channel with specified data type.
 *
 * \param channelList Channel list.
 * \param dataType Type of channel.
205
 * \param sta_chan_list String list of item STA.CHAN, separeted by comma.
206
 * \param network_code_default Default Network code
207 208 209 210 211 212
 *
 * \return Channel list with specified dataType. It will need to be freed!
 *
 * \warning Returned value will need to be freed!
 *
 */
213
NMXP_CHAN_LIST_NET *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType, char *sta_chan_list, const char *network_code_default);
214 215


216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
/*! Sort list by channel key
 *
 * \param channelList Channel List
 *
 */
void nmxp_chan_sortByKey(NMXP_CHAN_LIST *channelList);


/*! Sort list by channel name
 *
 * \param channelList Channel List
 *
 */
void nmxp_chan_sortByName(NMXP_CHAN_LIST *channelList);

231 232 233 234 235 236

/*! Print channel information
 *
 * \param channelList Channel List
 *
 */
237 238 239
void nmxp_chan_print_channelList(NMXP_CHAN_LIST *channelList);


240 241 242 243 244 245 246 247 248
/*! Print channel information using channel pattern list
 *
 * \param channelList Channel List
 * \param sta_chan_list Channel pattern list
 *
 */
void nmxp_chan_print_channelList_with_match(NMXP_CHAN_LIST *channelList, char *sta_chan_list);


249 250 251 252 253 254
/*! Print channel information
 *
 * \param channelList Channel List
 *
 */
void nmxp_chan_print_netchannelList(NMXP_CHAN_LIST_NET *channelList);
255

Matteo Quintiliani's avatar
Matteo Quintiliani committed
256 257 258

void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list);

259
NMXP_META_CHAN_LIST *nmxp_meta_chan_add(NMXP_META_CHAN_LIST **chan_list, int32_t key, char *name, int32_t start_time, int32_t end_time, char *network, NMXP_META_CHAN_LIST_SORT_TYPE sorttype);
Matteo Quintiliani's avatar
Matteo Quintiliani committed
260 261 262 263 264 265 266 267 268 269 270

NMXP_META_CHAN_LIST *nmxp_meta_chan_search_key(NMXP_META_CHAN_LIST *chan_list, int32_t key);

NMXP_META_CHAN_LIST *nmxp_meta_chan_set_name(NMXP_META_CHAN_LIST *chan_list, int32_t key, char *name);

NMXP_META_CHAN_LIST *nmxp_meta_chan_set_times(NMXP_META_CHAN_LIST *chan_list, int32_t key, int32_t start_time, int32_t end_time);

NMXP_META_CHAN_LIST *nmxp_meta_chan_set_network(NMXP_META_CHAN_LIST *chan_list, int32_t key, char *network);

void nmxp_meta_chan_print(NMXP_META_CHAN_LIST *chan_list);

271 272
void nmxp_meta_chan_print_with_match(NMXP_META_CHAN_LIST *chan_list, char *sta_chan_list);

273 274
#endif