nmxp_chan.c 1.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*! \file
 *
 * \brief Channels for Nanometrics Protocol Libray
 *
 * Author:
 * 	Matteo Quintiliani
 * 	Istituto Nazionale di Geofisica e Vulcanologia - Italy
 *	quintiliani@ingv.it
 *
 */

#include "nmxp_chan.h"

#include <string.h>
15
#include <stdlib.h>
16

Matteo Quintiliani's avatar
Matteo Quintiliani committed
17
int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList)
18
{
19
20
    int chan_number = channelList->number;
    int i_chan = 0;
21

22
    for (i_chan = 0; i_chan < chan_number; i_chan++)
23
    {
24
25
	if (strcasecmp(name, channelList->channel[i_chan].name) == 0)
	    return channelList->channel[i_chan].key;
26
27
28
29
30
    }

    return -1;
}

Matteo Quintiliani's avatar
Matteo Quintiliani committed
31
char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList)
32
{
33
34
    int chan_number = channelList->number;
    int i_chan = 0;
35

36
    for (i_chan = 0; i_chan < chan_number; i_chan++)
37
    {
38
39
	if ( key == channelList->channel[i_chan].key )
	    return &channelList->channel[i_chan].name[0];
40
41
42
43
44
    }

    return NULL;
}

Matteo Quintiliani's avatar
Matteo Quintiliani committed
45
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType) {
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    NMXP_CHAN_LIST *ret_channelList = NULL;

    int chan_number = channelList->number;
    int i_chan = 0;

    ret_channelList = (NMXP_CHAN_LIST *) malloc(sizeof(NMXP_CHAN_LIST));
    ret_channelList->number = 0;

    for (i_chan = 0; i_chan < chan_number; i_chan++)
    {
	if ( ((channelList->channel[i_chan].key >> 8) & 0xff) == dataType) {
	    ret_channelList->channel[ret_channelList->number].key = channelList->channel[i_chan].key;
	    strcpy(ret_channelList->channel[ret_channelList->number].name, channelList->channel[i_chan].name);
	    ret_channelList->number++;
	}
    }

    return ret_channelList;
}