nmxp_chan.h 5.64 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
10
11
12
13
14
 *
 * Author:
 * 	Matteo Quintiliani
 * 	Istituto Nazionale di Geofisica e Vulcanologia - Italy
 *	quintiliani@ingv.it
 *
 */

#ifndef NMXP_CHAN_H
#define NMXP_CHAN_H 1

15
#include <stdint.h>
16

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

27
28
29
30
31
32
33
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;

34

35
/*! \brief The key/name info for one channel */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
36
typedef struct {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
37
    int32_t key;
38
    char name[12];
Matteo Quintiliani's avatar
Matteo Quintiliani committed
39
} NMXP_CHAN_KEY;
40

Matteo Quintiliani's avatar
Matteo Quintiliani committed
41
/*! \brief Max number of channels */
42
#define MAX_N_CHAN 1000
Matteo Quintiliani's avatar
Matteo Quintiliani committed
43
44
45

/*! \brief Channel list */
typedef struct {
46
    uint32_t number;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
47
48
    NMXP_CHAN_KEY channel[MAX_N_CHAN];
} NMXP_CHAN_LIST;
49

50
51
/*! \brief Precis Channel item */
typedef struct {
Matteo Quintiliani's avatar
Matteo Quintiliani committed
52
    int32_t key;
53
54
55
56
57
58
59
60
61
62
    char name[12];
    uint32_t start_time;
    uint32_t end_time;
} NMXP_CHAN_PRECISITEM;

/*! \brief Precis Channel list */
typedef struct {
    uint32_t number;
    NMXP_CHAN_PRECISITEM channel[MAX_N_CHAN];
} NMXP_CHAN_PRECISLIST;
63

Matteo Quintiliani's avatar
Matteo Quintiliani committed
64
65
66
67
68
69
70
71
/*! \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 */
72
73
74
75
typedef struct {
    int32_t instr_id;
    NMXP_DATATYPE datatype;
    int32_t type_of_channel;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
76
} NMXP_MSGBODY_PRECISLISTREQUEST;
Matteo Quintiliani's avatar
Matteo Quintiliani committed
77

Matteo Quintiliani's avatar
Matteo Quintiliani committed
78
79
80
81
82
83
84
85
86
87
88
89
90
/*! \brief Channel info request body */
typedef struct {
    int32_t key;
    char name[12];
    char network[12];
} NMXP_MSGBODY_CHANNELINFORESPONSE;

/*! \brief Channel info request body */
typedef struct {
    int32_t key;
    int32_t ignored;
} NMXP_MSGBODY_CHANNELINFOREQUEST;

Matteo Quintiliani's avatar
Matteo Quintiliani committed
91

92
93
94
95
/*! \brief Character separator for channel list */
#define sep_chan_list  ','


96
97
98
/*! \brief Return type of data from a channel key */
#define getDataTypeFromKey(key) ((key >> 8) & 0xff)

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

102

103

104
105
/*! \brief Copy station code and channel code from name
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
106
 * \param station_dot_channel string containing STA.CHAN
107
108
109
110
111
112
113
114
115
116
117
118
 * \param[out] station_code Pointer to string for station code
 * \param[out] channel_code Pointer to string for char code
 *
 * \warning Parametes can not be NULL!
 *
 * \retval 1 on success
 * \retval 0 on error
 *
 */
int nmxp_chan_cpy_sta_chan(const char *station_dot_channel, char *station_code, char *channel_code);


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*! \brief Match station_dot_channel against pattern, treating errors as no match.
 *
 * \param station_dot_channel STA.CHAN format
 * \param pattern STA.?HZ or STA.H?Z or STA.HH? or STA.?H? or ....
 *
 * \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
 *
 */
int nmxp_chan_match(const char *station_dot_channel, char *pattern);



134
/*! \brief Looks up a channel key in the list using the name
135
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
136
137
 * \param name Channel name.
 * \param channelList Channel list.
138
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
139
 * \return Key of the channel with name. -1 On error.
140
141
 *
 */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
142
int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList);
143

144
145
146
147
148
149
150
151
152

/*! \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.
 *
 */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
153
int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST *channelList);
154
155


156
/*! \brief Looks up a channel name in the list using a key
157
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
158
159
 * \param key Channel key.
 * \param channelList Channel list.
160
 *
Matteo Quintiliani's avatar
Matteo Quintiliani committed
161
 * \return Name of channel with key. NULL on error.
162
163
 *
 */
Matteo Quintiliani's avatar
Matteo Quintiliani committed
164
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST *channelList);
165

166

167
168
169
170
171
172
173
174
175
176
/*! \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
177
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType);
178

179

180
181
182
183
/*! \brief Looks up a channel with specified data type.
 *
 * \param channelList Channel list.
 * \param dataType Type of channel.
184
 * \param sta_chan_list String list of item STA.CHAN, separeted by comma.
185
186
187
188
189
190
191
192
193
 *
 * \return Channel list with specified dataType. It will need to be freed!
 *
 * \warning Returned value will need to be freed!
 *
 */
NMXP_CHAN_LIST *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType, char *sta_chan_list);


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*! 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);

209
210
211
212
213
214
215
216

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

Matteo Quintiliani's avatar
Matteo Quintiliani committed
217
218
219

void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list);

220
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
221
222
223
224
225
226
227
228
229
230
231

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

232
233
#endif