nmxp_chan.h 6.33 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.23 2008-03-05 10:21:12 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

Matteo Quintiliani's avatar
Matteo Quintiliani committed
19 20 21 22 23 24 25 26 27 28
/*! \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;

29 30 31 32 33 34 35
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;

36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*! \brief Max number of channels */
#define MAX_N_CHAN 2000

/*! \brief The key/name info for one channel */
typedef struct {
    int32_t key;
    char name[24];
} NMXP_CHAN_KEY_NET;

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

52
/*! \brief The key/name info for one channel */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
53
typedef struct {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
54
    int32_t key;
55
    char name[12];
Matteo Quintiliani's avatar
Matteo Quintiliani committed
56
} NMXP_CHAN_KEY;
57

Matteo Quintiliani's avatar
Matteo Quintiliani committed
58 59
/*! \brief Channel list */
typedef struct {
60
    int32_t number;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
61 62
    NMXP_CHAN_KEY channel[MAX_N_CHAN];
} NMXP_CHAN_LIST;
63

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

/*! \brief Precis Channel list */
typedef struct {
74
    int32_t number;
75 76
    NMXP_CHAN_PRECISITEM channel[MAX_N_CHAN];
} NMXP_CHAN_PRECISLIST;
77

Matteo Quintiliani's avatar
Matteo Quintiliani committed
78 79 80 81 82 83 84 85
/*! \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 */
86 87 88 89
typedef struct {
    int32_t instr_id;
    NMXP_DATATYPE datatype;
    int32_t type_of_channel;
90
} NMXP_PRECISLISTREQUEST;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
91

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

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

Matteo Quintiliani's avatar
Matteo Quintiliani committed
105

106 107 108 109
/*! \brief Character separator for channel list */
#define sep_chan_list  ','


110 111 112
/*! \brief Return type of data from a channel key */
#define getDataTypeFromKey(key) ((key >> 8) & 0xff)

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

116

117

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


134 135
/*! \brief Match station_dot_channel against pattern, treating errors as no match.
 *
136 137
 * \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 ....
138 139 140 141 142 143 144
 *
 * \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
 *
 */
145
int nmxp_chan_match(const char *net_dot_station_dot_channel, char *pattern);
146 147 148



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

159 160 161 162 163 164 165 166 167

/*! \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.
 *
 */
168
int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList);
169 170


171
/*! \brief Looks up a channel name in the list using a key
172
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
173 174
 * \param key Channel key.
 * \param channelList Channel list.
175
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
176
 * \return Name of channel with key. NULL on error.
177 178
 *
 */
179
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList);
180

181

182 183 184 185 186 187 188 189 190 191
/*! \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!
 *
 */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
192
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType);
193

194

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


210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
/*! 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);

225 226 227 228 229 230

/*! Print channel information
 *
 * \param channelList Channel List
 *
 */
231 232 233 234 235 236 237 238 239
void nmxp_chan_print_channelList(NMXP_CHAN_LIST *channelList);


/*! Print channel information
 *
 * \param channelList Channel List
 *
 */
void nmxp_chan_print_netchannelList(NMXP_CHAN_LIST_NET *channelList);
240

Matteo Quintiliani's avatar
Matteo Quintiliani committed
241 242 243

void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list);

244
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
245 246 247 248 249 250 251 252 253 254 255

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);

256 257
#endif