Commit 256b08d7 authored by Matteo Quintiliani's avatar Matteo Quintiliani

Fixed bugs from branch nmxptool_1_2_4_beta8_fixing_MTSAFE2


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1284 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent aef3f0e8
...@@ -11,7 +11,7 @@ m4_define([major_version], [1]) ...@@ -11,7 +11,7 @@ m4_define([major_version], [1])
m4_define([minor_version], [2]) m4_define([minor_version], [2])
m4_define([micro_version], [4]) m4_define([micro_version], [4])
# Comment build_version for stable release # Comment build_version for stable release
m4_define([build_version], [beta8]) m4_define([build_version], [beta9])
m4_ifdef([build_version], [ m4_ifdef([build_version], [
m4_define([version], m4_define([version],
...@@ -119,6 +119,8 @@ AM_CONDITIONAL(ENABLE_DLL_PTHREAD, test x$DLL_PTHREAD != x) ...@@ -119,6 +119,8 @@ AM_CONDITIONAL(ENABLE_DLL_PTHREAD, test x$DLL_PTHREAD != x)
AC_ARG_VAR(DIR_PTHREAD, [Directory containing PThread DDL library]) AC_ARG_VAR(DIR_PTHREAD, [Directory containing PThread DDL library])
AC_ARG_VAR(DLL_PTHREAD, [Name of PThread DLL library - i.e. pthreadVC2.dll]) AC_ARG_VAR(DLL_PTHREAD, [Name of PThread DLL library - i.e. pthreadVC2.dll])
CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS"
# Checks for header files. # Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/stat.h sys/time.h unistd.h pthread.h]) AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/stat.h sys/time.h unistd.h pthread.h])
...@@ -257,7 +259,7 @@ AC_STRUCT_TM ...@@ -257,7 +259,7 @@ AC_STRUCT_TM
# AC_CHECK_SIZEOF([long int]) # AC_CHECK_SIZEOF([long int])
# Checks for library functions. # Checks for library functions.
AC_FUNC_MALLOC # AC_FUNC_MALLOC
AC_FUNC_MKTIME AC_FUNC_MKTIME
AC_FUNC_SELECT_ARGTYPES AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STRERROR_R AC_FUNC_STRERROR_R
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * quintiliani@ingv.it
* *
* $Id: nmxp_base.h,v 1.34 2009-08-17 08:47:13 mtheo Exp $ * $Id: nmxp_base.h,v 1.35 2009-08-31 12:16:41 mtheo Exp $
* *
*/ */
...@@ -78,7 +78,7 @@ int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec); ...@@ -78,7 +78,7 @@ int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec);
/*! \brief Wrapper to strerror, strerror_r or WSAGetLastErrorMessage /*! \brief Wrapper to strerror, strerror_r or WSAGetLastErrorMessage
* *
* \return String message of errno_value. It is static, not need to be freed. * \return String message of errno_value. It is not static, need to be freed.
* *
*/ */
char *nmxp_strerror(int errno_value); char *nmxp_strerror(int errno_value);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * quintiliani@ingv.it
* *
* $Id: nmxp_chan.h,v 1.25 2009-03-10 16:36:25 mtheo Exp $ * $Id: nmxp_chan.h,v 1.26 2009-08-31 12:16:41 mtheo Exp $
* *
*/ */
...@@ -179,6 +179,8 @@ int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList); ...@@ -179,6 +179,8 @@ int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList);
* *
* \return Name of channel with key. NULL on error. * \return Name of channel with key. NULL on error.
* *
* \warning Returned value will need to be freed!
*
*/ */
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList); char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * quintiliani@ingv.it
* *
* $Id: nmxp.c,v 1.94 2009-08-17 08:57:10 mtheo Exp $ * $Id: nmxp.c,v 1.95 2009-08-31 12:16:41 mtheo Exp $
* *
*/ */
...@@ -46,39 +46,41 @@ int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) { ...@@ -46,39 +46,41 @@ int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) {
int recv_errno; int recv_errno;
NMXP_MSG_SERVER type; NMXP_MSG_SERVER type;
char buffer[NMXP_MAX_LENGTH_DATA_BUFFER]; char buffer[NMXP_MAX_LENGTH_DATA_BUFFER]={0};
int32_t length; int32_t length;
*pchannelList = NULL; *pchannelList = NULL;
ret = nmxp_receiveMessage(isock, &type, buffer, &length, 0, &recv_errno, NMXP_MAX_LENGTH_DATA_BUFFER); ret = nmxp_receiveMessage(isock, &type, buffer, &length, 0, &recv_errno, NMXP_MAX_LENGTH_DATA_BUFFER);
if(type != NMXP_MSG_CHANNELLIST) { /*TODO controllare ret*/
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Type %d is not NMXP_MSG_CHANNELLIST!\n", type); if (ret == NMXP_SOCKET_OK) {
} else { if(type != NMXP_MSG_CHANNELLIST) {
(*pchannelList) = (NMXP_CHAN_LIST *) NMXP_MEM_MALLOC(length); nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Type %d is not NMXP_MSG_CHANNELLIST!\n", type);
} else {
if( (*pchannelList) != NULL) { (*pchannelList) = (NMXP_CHAN_LIST *) NMXP_MEM_MALLOC(length);
memmove((*pchannelList), buffer, length); if( (*pchannelList) != NULL) {
(*pchannelList)->number = ntohl((*pchannelList)->number); memmove((*pchannelList), buffer, length);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "number of channels %d\n", (*pchannelList)->number); (*pchannelList)->number = ntohl((*pchannelList)->number);
/* TODO check*/ nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "number of channels %d\n", (*pchannelList)->number);
for(i=0; i < (*pchannelList)->number; i++) { /* TODO check*/
(*pchannelList)->channel[i].key = ntohl((*pchannelList)->channel[i].key);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "%12d %s\n", for(i=0; i < (*pchannelList)->number; i++) {
(*pchannelList)->channel[i].key, (*pchannelList)->channel[i].key = ntohl((*pchannelList)->channel[i].key);
NMXP_LOG_STR((*pchannelList)->channel[i].name)); nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "%12d %s\n",
} (*pchannelList)->channel[i].key,
} else { NMXP_LOG_STR((*pchannelList)->channel[i].name));
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "nmxp_receiveChannelList() Error allocating pchannelList!\n"); }
ret = NMXP_SOCKET_ERROR; } else {
} nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "nmxp_receiveChannelList() Error allocating pchannelList!\n");
ret = NMXP_SOCKET_ERROR;
}
}
} }
return ret; return ret;
...@@ -136,6 +138,7 @@ int nmxp_sendAddTimeSeriesChannel_raw(int isock, NMXP_CHAN_LIST_NET *channelList ...@@ -136,6 +138,7 @@ int nmxp_sendAddTimeSeriesChannel_raw(int isock, NMXP_CHAN_LIST_NET *channelList
int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, int32_t shortTermCompletion, int32_t out_format, NMXP_BUFFER_FLAG buffer_flag, int n_channel, int n_usec, int flag_restart) { int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, int32_t shortTermCompletion, int32_t out_format, NMXP_BUFFER_FLAG buffer_flag, int n_channel, int n_usec, int flag_restart) {
static int i = 0; static int i = 0;
static int first_time = 1; static int first_time = 1;
/*TODO avoid static Stefano*/
static struct timeval last_tp_now; static struct timeval last_tp_now;
char s_channels[MAX_LEN_S_CHANNELS]; char s_channels[MAX_LEN_S_CHANNELS];
...@@ -221,7 +224,7 @@ int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, in ...@@ -221,7 +224,7 @@ int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, in
NMXP_DATA_PROCESS *nmxp_receiveData(int isock, NMXP_CHAN_LIST_NET *channelList, const char *network_code, int timeoutsec, int *recv_errno ) { NMXP_DATA_PROCESS *nmxp_receiveData(int isock, NMXP_CHAN_LIST_NET *channelList, const char *network_code, int timeoutsec, int *recv_errno ) {
NMXP_MSG_SERVER type; NMXP_MSG_SERVER type;
char buffer[NMXP_MAX_LENGTH_DATA_BUFFER]; char buffer[NMXP_MAX_LENGTH_DATA_BUFFER]={0};
int32_t length; int32_t length;
NMXP_DATA_PROCESS *pd = NULL; NMXP_DATA_PROCESS *pd = NULL;
...@@ -744,6 +747,8 @@ void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_t ...@@ -744,6 +747,8 @@ void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_t
raw_stream_buffer->max_pdlist_items = max_tolerable_latency * 4; raw_stream_buffer->max_pdlist_items = max_tolerable_latency * 4;
raw_stream_buffer->timeoutrecv = timeoutrecv; raw_stream_buffer->timeoutrecv = timeoutrecv;
raw_stream_buffer->n_pdlist = 0; raw_stream_buffer->n_pdlist = 0;
raw_stream_buffer->pdlist=NULL;
raw_stream_buffer->pdlist = (NMXP_DATA_PROCESS **) NMXP_MEM_MALLOC(raw_stream_buffer->max_pdlist_items * sizeof(NMXP_DATA_PROCESS *)); raw_stream_buffer->pdlist = (NMXP_DATA_PROCESS **) NMXP_MEM_MALLOC(raw_stream_buffer->max_pdlist_items * sizeof(NMXP_DATA_PROCESS *));
for(j=0; j<raw_stream_buffer->max_pdlist_items; j++) { for(j=0; j<raw_stream_buffer->max_pdlist_items; j++) {
raw_stream_buffer->pdlist[j] = NULL; raw_stream_buffer->pdlist[j] = NULL;
...@@ -797,6 +802,10 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int ...@@ -797,6 +802,10 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
/* Allocate memory for pd and copy a_pd */ /* Allocate memory for pd and copy a_pd */
pd = (NMXP_DATA_PROCESS *) NMXP_MEM_MALLOC(sizeof(NMXP_DATA_PROCESS)); pd = (NMXP_DATA_PROCESS *) NMXP_MEM_MALLOC(sizeof(NMXP_DATA_PROCESS));
if (pd == NULL) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_RAWSTREAM,"nmxp_raw_stream_manage(): Error allocating memory\n");
exit(-1);
}
memcpy(pd, a_pd, sizeof(NMXP_DATA_PROCESS)); memcpy(pd, a_pd, sizeof(NMXP_DATA_PROCESS));
if(a_pd->nSamp * sizeof(int) > 0) { if(a_pd->nSamp * sizeof(int) > 0) {
pd->pDataPtr = (int *) NMXP_MEM_MALLOC(a_pd->nSamp * sizeof(int)); pd->pDataPtr = (int *) NMXP_MEM_MALLOC(a_pd->nSamp * sizeof(int));
...@@ -889,7 +898,8 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int ...@@ -889,7 +898,8 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
} }
} else { } else {
if(pd) { if(pd) {
p->pdlist[p->n_pdlist++] = pd; p->pdlist[p->n_pdlist] = pd;
p->n_pdlist++;
} }
} }
...@@ -1021,10 +1031,12 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int ...@@ -1021,10 +1031,12 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
if(p->pdlist[k]) { if(p->pdlist[k]) {
NMXP_MEM_FREE(p->pdlist[k]); NMXP_MEM_FREE(p->pdlist[k]);
p->pdlist[k] = NULL; p->pdlist[k] = NULL;
/*nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_RAWSTREAM, "Freeing p->pdlist[%d]\n", k);*/
} }
} }
if(k + j < p->n_pdlist) { if(k + j < p->n_pdlist) {
p->pdlist[k] = p->pdlist[k+j]; p->pdlist[k] = p->pdlist[k+j];
p->pdlist[k+j]=NULL;
} else { } else {
p->pdlist[k] = NULL; p->pdlist[k] = NULL;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * quintiliani@ingv.it
* *
* $Id: nmxp_base.c,v 1.80 2009-08-17 08:47:13 mtheo Exp $ * $Id: nmxp_base.c,v 1.81 2009-08-31 12:16:41 mtheo Exp $
* *
*/ */
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
int nmxp_openSocket(char *hostname, int portNum, int (*func_cond)(void)) int nmxp_openSocket(char *hostname, int portNum, int (*func_cond)(void))
{ {
/*TODO stefano avoid static*/
static int sleepTime = 1; static int sleepTime = 1;
int isock = -1; int isock = -1;
struct hostent *hostinfo = NULL; struct hostent *hostinfo = NULL;
...@@ -227,19 +228,19 @@ int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec) { ...@@ -227,19 +228,19 @@ int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec) {
#define MAXLEN_RECV_ERRNO_STR 200 #define MAXLEN_RECV_ERRNO_STR 200
char *nmxp_strerror(int errno_value) { char *nmxp_strerror(int errno_value) {
static char ret_recv_errno_str[MAXLEN_RECV_ERRNO_STR]; char * ret_recv_errno_str;
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
char *recv_errno_str; char *recv_errno_str;
#else #else
#ifdef HAVE_STRERROR_R #ifdef HAVE_STRERROR_R
char recv_errno_str[MAXLEN_RECV_ERRNO_STR]; char recv_errno_str[MAXLEN_RECV_ERRNO_STR]="";
#else #else
char *recv_errno_str; char *recv_errno_str=NULL;
#endif #endif
#endif #endif
ret_recv_errno_str= (char *) NMXP_MEM_MALLOC (MAXLEN_RECV_ERRNO_STR * sizeof(char));
ret_recv_errno_str[0] = 0; ret_recv_errno_str[0] = 0;
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
...@@ -319,7 +320,7 @@ int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *rec ...@@ -319,7 +320,7 @@ int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *rec
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CONNFLOW, "nmxp_recv_ctrl(): %s (errno=%d recvCount=%d length=%d cc=%d)\n", nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CONNFLOW, "nmxp_recv_ctrl(): %s (errno=%d recvCount=%d length=%d cc=%d)\n",
NMXP_LOG_STR(recv_errno_str), *recv_errno, recvCount, length, cc); NMXP_LOG_STR(recv_errno_str), *recv_errno, recvCount, length, cc);
} }
NMXP_MEM_FREE(recv_errno_str);
/* TO IMPROVE /* TO IMPROVE
* Fixed bug receiving zero byte from recv() 'TCP FIN or EOF received' * Fixed bug receiving zero byte from recv() 'TCP FIN or EOF received'
* */ * */
...@@ -356,14 +357,14 @@ int nmxp_sendHeader(int isock, NMXP_MSG_CLIENT type, int32_t length) ...@@ -356,14 +357,14 @@ int nmxp_sendHeader(int isock, NMXP_MSG_CLIENT type, int32_t length)
int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, int32_t *length, int timeoutsec, int *recv_errno ) int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, int32_t *length, int timeoutsec, int *recv_errno )
{ {
int ret ; int ret ;
NMXP_MESSAGE_HEADER msg; NMXP_MESSAGE_HEADER msg={0};
ret = nmxp_recv_ctrl(isock, &msg, sizeof(NMXP_MESSAGE_HEADER), timeoutsec, recv_errno); ret = nmxp_recv_ctrl(isock, &msg, sizeof(NMXP_MESSAGE_HEADER), timeoutsec, recv_errno);
*type = 0; *type = 0;
*length = 0; *length = 0;
if(ret == NMXP_SOCKET_OK) { if((ret == NMXP_SOCKET_OK) && (msg.type != 0)) {
msg.signature = ntohl(msg.signature); msg.signature = ntohl(msg.signature);
msg.type = ntohl(msg.type); msg.type = ntohl(msg.type);
msg.length = ntohl(msg.length); msg.length = ntohl(msg.length);
...@@ -464,25 +465,26 @@ NMXP_DATA_PROCESS *nmxp_processDecompressedData(char* buffer_data, int length_da ...@@ -464,25 +465,26 @@ NMXP_DATA_PROCESS *nmxp_processDecompressedData(char* buffer_data, int length_da
int32_t *pDataPtr = NULL; int32_t *pDataPtr = NULL;
int swap = 0; int swap = 0;
int idx; int idx;
static int32_t outdata[MAX_OUTDATA]; int32_t *outdata = NULL;
char station_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN]; char station_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN]; char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN]; char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char *nmxp_channel_name = NULL; char *nmxp_channel_name = NULL;
static NMXP_DATA_PROCESS pd; NMXP_DATA_PROCESS *pd = NULL;
/* copy the header contents into local fields and swap */ /* copy the header contents into local fields and swap */
memcpy(&netInt, &buffer_data[0], 4); memcpy(&netInt, &buffer_data[0], 4);
pKey = ntohl(netInt); pKey = ntohl(netInt);
if ( pKey != netInt ) { swap = 1; } if ( pKey != netInt ) { swap = 1; }
nmxp_data_init(&pd); nmxp_data_init(pd);
outdata = (int32_t *) NMXP_MEM_MALLOC(MAX_OUTDATA*sizeof(int32_t));
nmxp_channel_name = nmxp_chan_lookupName(pKey, channelList); nmxp_channel_name = nmxp_chan_lookupName(pKey, channelList);
if(nmxp_channel_name) { if(nmxp_channel_name != NULL) {
memcpy(&pTime, &buffer_data[4], 8); memcpy(&pTime, &buffer_data[4], 8);
if ( swap ) { nmxp_data_swap_8b(&pTime); } if ( swap ) { nmxp_data_swap_8b(&pTime); }
...@@ -506,36 +508,40 @@ NMXP_DATA_PROCESS *nmxp_processDecompressedData(char* buffer_data, int length_da ...@@ -506,36 +508,40 @@ NMXP_DATA_PROCESS *nmxp_processDecompressedData(char* buffer_data, int length_da
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not in STA.CHAN format: %s\n", nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not in STA.CHAN format: %s\n",
NMXP_LOG_STR(nmxp_channel_name)); NMXP_LOG_STR(nmxp_channel_name));
} }
pd.key = pKey; pd->key = pKey;
if(network_code[0] != 0) { if(network_code[0] != 0) {
strncpy(pd.network, network_code, NMXP_DATA_NETWORK_LENGTH); strncpy(pd->network, network_code, NMXP_DATA_NETWORK_LENGTH);
} else { } else {
strncpy(pd.network, network_code_default, NMXP_DATA_NETWORK_LENGTH); strncpy(pd->network, network_code_default, NMXP_DATA_NETWORK_LENGTH);
} }
if(station_code[0] != 0) { if(station_code[0] != 0) {
strncpy(pd.station, station_code, NMXP_DATA_STATION_LENGTH); strncpy(pd->station, station_code, NMXP_DATA_STATION_LENGTH);
} }
if(channel_code[0] != 0) { if(channel_code[0] != 0) {
strncpy(pd.channel, channel_code, NMXP_DATA_CHANNEL_LENGTH); strncpy(pd->channel, channel_code, NMXP_DATA_CHANNEL_LENGTH);
} }
pd.packet_type = NMXP_MSG_DECOMPRESSED; pd->packet_type = NMXP_MSG_DECOMPRESSED;
pd.x0 = -1; pd->x0 = -1;
pd.xn = -1; pd->xn = -1;
pd.x0n_significant = 0; pd->x0n_significant = 0;
pd->time = pTime;
pd->nSamp = pNSamp;
pd->pDataPtr = pDataPtr;
pd->sampRate = pSampRate;
/* TODO*/ /* TODO*/
/* pd.oldest_seq_no = ;*/ /* pd.oldest_seq_no = ;*/
/* pd.seq_no = ;*/ /* pd.seq_no = ;*/
pd.time = pTime;
pd.nSamp = pNSamp;
pd.pDataPtr = pDataPtr;
pd.sampRate = pSampRate;
NMXP_MEM_FREE(nmxp_channel_name);
} else { } else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not found for key %d\n", pKey); nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not found for key %d\n", pKey);
} }
return &pd; return pd;
} }
...@@ -551,7 +557,9 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data ...@@ -551,7 +557,9 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN]; char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN]; char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
static NMXP_DATA_PROCESS pd; NMXP_DATA_PROCESS *pd = NULL;
int32_t nmx_rate_code_to_sample_rate[32] = { int32_t nmx_rate_code_to_sample_rate[32] = {
0,1,2,5,10,20,40,50, 0,1,2,5,10,20,40,50,
...@@ -572,7 +580,8 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data ...@@ -572,7 +580,8 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
int32_t comp_bytecount; int32_t comp_bytecount;
unsigned char *indata; unsigned char *indata;
static int32_t outdata[MAX_OUTDATA]; int32_t * outdata = NULL;
int32_t nout, i, k; int32_t nout, i, k;
int32_t prev_xn; int32_t prev_xn;
const uint32_t high_scale = 4096 * 2048; const uint32_t high_scale = 4096 * 2048;
...@@ -580,6 +589,9 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data ...@@ -580,6 +589,9 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
char *nmxp_channel_name = NULL; char *nmxp_channel_name = NULL;
pd= (NMXP_DATA_PROCESS *) NMXP_MEM_MALLOC(sizeof(NMXP_DATA_PROCESS));
memset(pd,0,sizeof(NMXP_DATA_PROCESS));
/* TOREMOVE int my_order = get_my_wordorder();*/ /* TOREMOVE int my_order = get_my_wordorder();*/
int my_host_is_bigendian = nmxp_data_bigendianhost(); int my_host_is_bigendian = nmxp_data_bigendianhost();
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_PACKETMAN, "my_host_is_bigendian %d\n", my_host_is_bigendian); nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_PACKETMAN, "my_host_is_bigendian %d\n", my_host_is_bigendian);
...@@ -645,8 +657,8 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data ...@@ -645,8 +657,8 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
pSampRate = this_sample_rate; pSampRate = this_sample_rate;
nmxp_data_init(&pd); nmxp_data_init(pd);
outdata = (int32_t *) NMXP_MEM_MALLOC(MAX_OUTDATA*sizeof(int32_t));
nmxp_channel_name = nmxp_chan_lookupName(pKey, channelList); nmxp_channel_name = nmxp_chan_lookupName(pKey, channelList);
if(nmxp_channel_name) { if(nmxp_channel_name) {
...@@ -693,37 +705,38 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data ...@@ -693,37 +705,38 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_PACKETMAN, "Unpacked %d samples.\n", nout); nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_PACKETMAN, "Unpacked %d samples.\n", nout);
pDataPtr = outdata; pDataPtr = outdata;
pNSamp = nout; pNSamp = nout;
pd.key = pKey; pd->key = pKey;
if(network_code[0] != 0) { if(network_code[0] != 0) {
strncpy(pd.network, network_code, NMXP_DATA_NETWORK_LENGTH); strncpy(pd->network, network_code, NMXP_DATA_NETWORK_LENGTH);
} else { } else {
strncpy(pd.network, network_code_default, NMXP_DATA_NETWORK_LENGTH); strncpy(pd->network, network_code_default, NMXP_DATA_NETWORK_LENGTH);
} }
if(station_code[0] != 0) { if(station_code[0] != 0) {
strncpy(pd.station, station_code, NMXP_DATA_STATION_LENGTH); strncpy(pd->station, station_code, NMXP_DATA_STATION_LENGTH);
} }
if(channel_code[0] != 0) { if(channel_code[0] != 0) {
strncpy(pd.channel, channel_code, NMXP_DATA_CHANNEL_LENGTH); strncpy(pd->channel, channel_code, NMXP_DATA_CHANNEL_LENGTH);
} }
pd.packet_type = nmx_ptype; pd->packet_type = nmx_ptype;
pd.x0 = nmx_x0; pd->x0 = nmx_x0;
pd.xn = pDataPtr[nout]; pd->xn = pDataPtr[nout];
pd.x0n_significant = 1; pd->x0n_significant = 1;
pd.oldest_seq_no = nmx_oldest_sequence_number; pd->oldest_seq_no = nmx_oldest_sequence_number;
pd.seq_no = nmx_seqno; pd->seq_no = nmx_seqno;
pd.time = pTime; pd->time = pTime;
pd.nSamp = pNSamp; pd->nSamp = pNSamp;
pd.pDataPtr = pDataPtr; pd->pDataPtr = pDataPtr;
pd.sampRate = pSampRate; pd->sampRate = pSampRate;
NMXP_MEM_FREE(nmxp_channel_name);
} else { } else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not found for key %d\n", pKey); nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not found for key %d\n", pKey);
} }
return &pd; return pd;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * quintiliani@ingv.it
* *
* $Id: nmxp_chan.c,v 1.44 2009-03-10 16:57:07 mtheo Exp $ * $Id: nmxp_chan.c,v 1.45 2009-08-31 12:16:41 mtheo Exp $
* *
*/ */
...@@ -231,7 +231,7 @@ int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList) ...@@ -231,7 +231,7 @@ int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList)
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList) char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList)
{ {
int i_chan = 0; int i_chan = 0;
static char ret[NMXP_CHAN_MAX_SIZE_NAME]; char *ret = (char *) NMXP_MEM_MALLOC(NMXP_CHAN_MAX_SIZE_NAME);
ret[0] = 0; ret[0] = 0;
...@@ -243,6 +243,7 @@ char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList) ...@@ -243,6 +243,7 @@ char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList)
} }
if(ret[0] == 0) { if(ret[0] == 0) {
NMXP_MEM_FREE(ret);
return NULL; return NULL;
} else { } else {
return ret; return ret;
...@@ -338,6 +339,8 @@ NMXP_CHAN_LIST_NET *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE ...@@ -338,6 +339,8 @@ NMXP_CHAN_LIST_NET *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE
i_chan_duplicated, channelList->channel[i_chan_duplicated].key); i_chan_duplicated, channelList->channel[i_chan_duplicated].key);
} }
NMXP_MEM_FREE(nmxp_channel_name);
nmxp_channel_name = NULL;
} }
} }
} }
......
...@@ -2,16 +2,14 @@ ...@@ -2,16 +2,14 @@
* *
* \brief Computing a 32 bit CRC. * \brief Computing a 32 bit CRC.
* *
* $Id: nmxp_crc32.c,v 1.6 2008-02-24 15:10:52 mtheo Exp $ * $Id: nmxp_crc32.c,v 1.7 2009-08-31 12:16:41 mtheo Exp $
* *
* *
*/ */
#include "nmxp_crc32.h" #include "nmxp_crc32.h"
static uint32_t crc32_tab[256]; void crc32_init_table (uint32_t crc32_tab[256]) {
void crc32_init_table () {
unsigned int i, j; unsigned int i, j;
uint32_t h = 1; uint32_t h = 1;
crc32_tab[0] = 0; crc32_tab[0] = 0;
...@@ -27,8 +25,9 @@ void crc32_init_table () { ...@@ -27,8 +25,9 @@ void crc32_init_table () {
uint32_t crc32(uint32_t crc32val, const char *s, uint32_t len) uint32_t crc32(uint32_t crc32val, const char *s, uint32_t len)
{ {
uint32_t i; uint32_t i;
uint32_t crc32_tab[256];
crc32_init_table(); crc32_init_table(crc32_tab);
crc32val ^= 0xffffffff; crc32val ^= 0xffffffff;
for (i = 0; i < len; i ++) { for (i = 0; i < len; i ++) {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * quintiliani@ingv.it
* *
* $Id: nmxp_data.c,v 1.69 2009-08-17 08:19:46 mtheo Exp $ * $Id: nmxp_data.c,v 1.70 2009-08-31 12:16:41 mtheo Exp $
* *
*/ */
...@@ -41,31 +41,29 @@ UTC, call mktime() and restore the value of TZ. Something like ...@@ -41,31 +41,29 @@ UTC, call mktime() and restore the value of TZ. Something like
time_t my_timegm (struct tm *tm) { time_t my_timegm (struct tm *tm) {
time_t ret; time_t ret;
/*TODO stefano avoid static*/
static char first_time = 1;
char *tz;
#ifndef HAVE_SETENV #ifndef HAVE_SETENV
#ifndef HAVE_UNDERSCORE_TIMEZONE #ifndef HAVE_UNDERSCORE_TIMEZONE
#warning Computation of packet latencies could be wrong if local time is not equal to UTC. #warning Computation of packet latencies could be wrong if local time is not equal to UTC.
static int first_time = 1;
if(first_time) { if(first_time) {
first_time = 0; first_time = 0;
nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "Computation of packet latencies could be wrong if local time is not equal to UTC.\n"); nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "Computation of packet latencies could be wrong if local time is not equal to UTC.\n");
} }
#endif #endif
#else
char *tz;
</