Commit aca6cb26 authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Added function nmxp_chan_getType()

Minor changes


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@18 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent e689e097
......@@ -30,7 +30,7 @@ typedef struct {
} NMXP_CHAN_LIST;
/*! \brief Looks up a channel key in the NMXP_CHAN_LIST using the name
/*! \brief Looks up a channel key in the list using the name
*
* \param name Channel name.
* \param channelList Channel list.
......@@ -40,7 +40,7 @@ typedef struct {
*/
int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList);
/*! \brief Looks up a channel name in the NMXP_CHAN_LIST using a key
/*! \brief Looks up a channel name in the list using a key
*
* \param key Channel key.
* \param channelList Channel list.
......@@ -50,5 +50,17 @@ int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList);
*/
char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList);
/*! \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!
*
*/
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, uint8_t dataType);
#endif
......@@ -12,16 +12,17 @@
#include "nmxp_chan.h"
#include <string.h>
#include <stdlib.h>
int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList)
{
int length = channelList->number;
int ich = 0;
int chan_number = channelList->number;
int i_chan = 0;
for (ich = 0; ich < length; ich++)
for (i_chan = 0; i_chan < chan_number; i_chan++)
{
if (strcasecmp(name, channelList->channel[ich].name) == 0)
return channelList->channel[ich].key;
if (strcasecmp(name, channelList->channel[i_chan].name) == 0)
return channelList->channel[i_chan].key;
}
return -1;
......@@ -29,15 +30,36 @@ int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList)
char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList)
{
int length = channelList->number;
int ich = 0;
int chan_number = channelList->number;
int i_chan = 0;
for (ich = 0; ich < length; ich++)
for (i_chan = 0; i_chan < chan_number; i_chan++)
{
if ( key == channelList->channel[ich].key )
return &channelList->channel[ich].name[0];
if ( key == channelList->channel[i_chan].key )
return &channelList->channel[i_chan].name[0];
}
return NULL;
}
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, uint8_t dataType) {
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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment