Commit 9f697d7e authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Added functions:

    void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list);
    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 *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);
Substitude int32_t for keys


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@181 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent e50905d3
......@@ -14,16 +14,20 @@
#include <stdint.h>
/*! \brief Type of Data */
typedef enum {
NMXP_DATA_TIMESERIES = 1,
NMXP_DATA_SOH = 2,
NMXP_DATA_TRANSERIAL = 6
} NMXP_DATATYPE;
/*! \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;
/*! \brief The key/name info for one channel */
typedef struct {
uint32_t key;
int32_t key;
char name[12];
} NMXP_CHAN_KEY;
......@@ -38,7 +42,7 @@ typedef struct {
/*! \brief Precis Channel item */
typedef struct {
uint32_t key;
int32_t key;
char name[12];
uint32_t start_time;
uint32_t end_time;
......@@ -50,13 +54,33 @@ typedef struct {
NMXP_CHAN_PRECISITEM channel[MAX_N_CHAN];
} NMXP_CHAN_PRECISLIST;
/*! \brief Precis list requst body */
/*! \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 */
typedef struct {
int32_t instr_id;
NMXP_DATATYPE datatype;
int32_t type_of_channel;
} NMXP_MSGBODY_PRECISLISTREQUEST;
/*! \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;
/*! \brief Character separator for channel list */
#define sep_chan_list ','
......@@ -65,6 +89,9 @@ typedef struct {
/*! \brief Return type of data from a channel key */
#define getDataTypeFromKey(key) ((key >> 8) & 0xff)
/*! \brief Return channel number from a channel key */
#define getChannelNumberFromKey(key) ((key) & 0x000f)
/*! \brief Copy station code and channel code from name
......@@ -116,7 +143,7 @@ int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList);
* \return Index of channel with key. -1 on error.
*
*/
int nmxp_chan_lookupKeyIndex(uint32_t key, NMXP_CHAN_LIST *channelList);
int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST *channelList);
/*! \brief Looks up a channel name in the list using a key
......@@ -127,7 +154,7 @@ int nmxp_chan_lookupKeyIndex(uint32_t key, NMXP_CHAN_LIST *channelList);
* \return Name of channel with key. NULL on error.
*
*/
char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList);
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST *channelList);
/*! \brief Looks up a channel with specified data type.
......@@ -180,5 +207,20 @@ void nmxp_chan_sortByName(NMXP_CHAN_LIST *channelList);
*/
void nmxp_chan_print_channelList(NMXP_CHAN_LIST *channelList);
void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list);
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 *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);
#endif
......@@ -148,7 +148,7 @@ int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList)
}
int nmxp_chan_lookupKeyIndex(uint32_t key, NMXP_CHAN_LIST *channelList)
int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST *channelList)
{
int i_chan = 0;
int ret = -1;
......@@ -166,7 +166,7 @@ int nmxp_chan_lookupKeyIndex(uint32_t key, NMXP_CHAN_LIST *channelList)
}
char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList)
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST *channelList)
{
int i_chan = 0;
static char ret[12];
......@@ -294,3 +294,142 @@ void nmxp_chan_print_channelList(NMXP_CHAN_LIST *channelList) {
}
void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list) {
NMXP_META_CHAN_LIST *iter = *chan_list;
NMXP_META_CHAN_LIST *iter_next = NULL;
nmxp_log(0, 1, "nmxp_meta_chan_free()\n");
if(iter) {
iter_next = iter->next;
while(iter) {
free(iter);
iter = iter_next;
iter_next = iter->next;
}
*chan_list = NULL;
}
}
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 *iter = NULL;
NMXP_META_CHAN_LIST *new_item = NULL;
nmxp_log(0, 1, "nmxp_meta_chan_add(%d, %d, %s, %d, %d, %s)\n", *chan_list, key, name, start_time, end_time, network);
new_item = (NMXP_META_CHAN_LIST *) malloc(sizeof(NMXP_META_CHAN_LIST));
new_item->key = 0;
new_item->name[0] = 0;
new_item->start_time = 0;
new_item->end_time = 0;
new_item->network[0] = 0;
new_item->next = NULL;
new_item->key = key;
if(name) {
strncpy(new_item->name, name, 12);
}
new_item->start_time = start_time;
new_item->end_time = end_time;
if(network) {
strncpy(new_item->network, network, 12);
}
if(*chan_list == NULL) {
*chan_list = new_item;
} else {
if(new_item->key < (*chan_list)->key) {
new_item->next = *chan_list;
*chan_list = new_item;
} else {
for(iter = *chan_list; iter->next != NULL && new_item->key > iter->next->key; iter = iter->next) {
}
new_item->next = iter->next;
iter->next = new_item;
}
}
return new_item;
}
NMXP_META_CHAN_LIST *nmxp_meta_chan_search_key(NMXP_META_CHAN_LIST *chan_list, int32_t key) {
NMXP_META_CHAN_LIST *iter = chan_list;
int found = 0;
nmxp_log(0, 1, "nmxp_meta_chan_search_key()\n");
while(iter != NULL && !found) {
if(iter->key == key) {
found = 1;
} else {
iter = iter->next;
}
}
return iter;
}
NMXP_META_CHAN_LIST *nmxp_meta_chan_set_name(NMXP_META_CHAN_LIST *chan_list, int32_t key, char *name) {
NMXP_META_CHAN_LIST *ret = NULL;
nmxp_log(0, 1, "nmxp_meta_chan_set_name()\n");
if( (ret = nmxp_meta_chan_search_key(chan_list, key)) ) {
strncpy(ret->name, name, 12);
}
return ret;
}
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 *ret = NULL;
nmxp_log(0, 1, "nmxp_meta_chan_set_times()\n");
if( (ret = nmxp_meta_chan_search_key(chan_list, key)) ) {
ret->start_time = start_time;
ret->end_time = end_time;
}
return ret;
}
NMXP_META_CHAN_LIST *nmxp_meta_chan_set_network(NMXP_META_CHAN_LIST *chan_list, int32_t key, char *network) {
NMXP_META_CHAN_LIST *ret = NULL;
nmxp_log(0, 1, "nmxp_meta_chan_set_network()\n");
if( (ret = nmxp_meta_chan_search_key(chan_list, key)) ) {
strncpy(ret->network, network, 12);
}
return ret;
}
void nmxp_meta_chan_print(NMXP_META_CHAN_LIST *chan_list) {
NMXP_META_CHAN_LIST *iter = chan_list;
char str_start_time[200], str_end_time[200];
str_start_time[0] = 0;
str_end_time[0] = 0;
nmxp_log(0, 1, "nmxp_meta_chan_print()\n");
while(iter != NULL) {
nmxp_data_to_str(str_start_time, iter->start_time);
nmxp_data_to_str(str_end_time, iter->end_time);
nmxp_log(0, 0, "%10d %11s.%-8s (%s - %s)\n",
iter->key,
iter->name,
iter->network,
str_start_time,
str_end_time
);
iter = iter->next;
}
}
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