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

Minor changes


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@17 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 9ab82b3b
......@@ -49,6 +49,13 @@
#include "nmxp_chan.h"
#include "nmxp_crc32.h"
/*! \brief Flag for buffered packets */
typedef enum {
NMXP_BUFFER_NO = 0,
NMXP_BUFFER_YES = 1
} NMXP_BUFFER_FLAG;
/*! \brief Sends the message "Connect" on a socket
*
* \param isock A descriptor referencing the socket.
......@@ -70,10 +77,10 @@ int nmxp_sendConnect(int isock);
* \retval SOCKET_ERROR on error
*
*/
int nmxp_sendTerminateSubscription(int isock, enum NMXP_REASON_SHUTDOWN reason, char *message);
int nmxp_sendTerminateSubscription(int isock, NMXP_REASON_SHUTDOWN reason, char *message);
/*! \brief Receive message "nmxp_ChannelList" from a socket
/*! \brief Receive message "NMXP_CHAN_LIST" from a socket
*
* \param isock A descriptor referencing the socket.
* \param pchannelList[out] List of channels. It will need to be freed!
......@@ -82,14 +89,9 @@ int nmxp_sendTerminateSubscription(int isock, enum NMXP_REASON_SHUTDOWN reason,
* \retval SOCKET_ERROR on error
*
*/
int nmxp_receiveChannelList(int isock, nmxp_ChannelList **pchannelList);
int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList);
enum NMXP_BUFFER_FLAG {
NMXP_BUFFER_NO = 0,
NMXP_BUFFER_YES = 1
};
/*! \brief Sends the message "AddTimeSeriesChannels" on a socket
*
* \param isock A descriptor referencing the socket.
......@@ -105,7 +107,7 @@ enum NMXP_BUFFER_FLAG {
* \retval SOCKET_ERROR on error
*
*/
int nmxp_sendAddTimeSeriesChannel(int isock, nmxp_ChannelList *channelList, uint32_t shortTermCompletion, uint32_t out_format, enum NMXP_BUFFER_FLAG buffer_flag);
int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST *channelList, uint32_t shortTermCompletion, uint32_t out_format, NMXP_BUFFER_FLAG buffer_flag);
/*! \brief Receive Compress Data message from a socket
......@@ -116,13 +118,13 @@ int nmxp_sendAddTimeSeriesChannel(int isock, nmxp_ChannelList *channelList, uint
* \retval SOCKET_ERROR on error
*
*/
int nmxp_receiveCompressedData(int isock, nmxp_ChannelList *channelList);
int nmxp_receiveCompressedData(int isock, NMXP_CHAN_LIST *channelList);
int nmxp_receiveDecompressedData(int isock, nmxp_ChannelList *channelList);
int nmxp_receiveDecompressedData(int isock, NMXP_CHAN_LIST *channelList);
void nmxp_processCompressedData(char* buffer_data, int length_data, nmxp_ChannelList *channelList);
void nmxp_processCompressedData(char* buffer_data, int length_data, NMXP_CHAN_LIST *channelList);
void nmxp_processDecompressedData(char* buffer, int length, nmxp_ChannelList *channelList);
void nmxp_processDecompressedData(char* buffer, int length, NMXP_CHAN_LIST *channelList);
#endif
......@@ -28,14 +28,14 @@
#define NMX_SIGNATURE 0x7abcde0f
/*! \brief Defines the type for reason of shutdown */
enum NMXP_REASON_SHUTDOWN {
typedef enum {
NMXP_NORMAL_SHUTDOWN = 1,
NMXP_ERROR_SHUTDOWN = 2,
NMXP_TIMEOUT_SHUTDOWN = 3
};
} NMXP_REASON_SHUTDOWN;
/*! \brief Defines the client message types */
enum NMXP_MSG_CLIENT {
typedef enum {
NMXPMSG_CONNECT = 100,
NMXPMSG_REQUESTPENDIG = 110,
NMXPMSG_TERMINATESUBSCRIPTION = 200,
......@@ -61,10 +61,10 @@ enum NMXP_MSG_CLIENT {
NMXPMSG_TRIGGERREQUEST = 231,
NMXPMSG_EVENTREQUEST = 232
};
} NMXP_MSG_CLIENT;
/*! \brief Defines the server message types. */
enum NMXP_MSG_SERVER {
typedef enum {
NMXPMSG_CHANNELLIST = 150,
NMXPMSG_ERROR = 190,
NMXPMSG_COMPRESSED = 1,
......@@ -79,16 +79,15 @@ enum NMXP_MSG_SERVER {
NMXPMSG_NAQSEVENT = 260,
NAQSTRIGGER = 259
};
} NMXP_MSG_SERVER;
/*! \brief Header for all messages. */
typedef struct nmxp_MessageHeader
{
uint32_t signature;
uint32_t type;
uint32_t length;
} nmxp_MessageHeader;
typedef struct {
uint32_t signature;
uint32_t type;
uint32_t length;
} NMXP_MESSAGE_HEADER;
/*! \brief Looks up target host, opens a socket and connects
......@@ -152,7 +151,7 @@ int nmxp_recv_ctrl(int isock, void *buffer, int length);
* \retval NMXP_SOCKET_ERROR on error
*
*/
int nmxp_sendHeader(int isock, enum NMXP_MSG_CLIENT type, uint32_t length);
int nmxp_sendHeader(int isock, NMXP_MSG_CLIENT type, uint32_t length);
/*! \brief Receives header of a message.
......@@ -165,7 +164,7 @@ int nmxp_sendHeader(int isock, enum NMXP_MSG_CLIENT type, uint32_t length);
* \retval NMXP_SOCKET_ERROR on error
*
*/
int nmxp_receiveHeader(int isock, enum NMXP_MSG_SERVER *type, uint32_t *length);
int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, uint32_t *length);
/*! \brief Sends header and body of a message.
......@@ -179,7 +178,7 @@ int nmxp_receiveHeader(int isock, enum NMXP_MSG_SERVER *type, uint32_t *length);
* \retval NMXP_SOCKET_ERROR on error
*
*/
int nmxp_sendMessage(int isock, enum NMXP_MSG_CLIENT type, void *buffer, uint32_t length);
int nmxp_sendMessage(int isock, NMXP_MSG_CLIENT type, void *buffer, uint32_t length);
/*! \brief Receives header and body of a message.
......@@ -195,7 +194,7 @@ int nmxp_sendMessage(int isock, enum NMXP_MSG_CLIENT type, void *buffer, uint32_
* \retval NMXP_SOCKET_ERROR on error
*
*/
int nmxp_receiveMessage(int isock, enum NMXP_MSG_SERVER *type, void **buffer, uint32_t *length);
int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, uint32_t *length);
/*! \brief A generic logging/printing routine
......@@ -220,7 +219,7 @@ int nmxp_receiveMessage(int isock, enum NMXP_MSG_SERVER *type, void **buffer, ui
* \param verb
* \param ...
*/
int nmxp_gen_log(int level, int verb, ... );
int nmxp_log(int level, int verb, ... );
#endif
......@@ -15,40 +15,40 @@
#include <sys/types.h>
/*! \brief The key/name info for one channel */
typedef struct nmxp_ChannelKey
{
typedef struct {
uint32_t key;
char name[12];
} nmxp_ChannelKey;
} NMXP_CHAN_KEY;
/*! \brief Max number of channels */
#define MAX_N_CHAN 1000
/*! \brief Channel List */
typedef struct nmxp_ChannelList
{
/*! \brief Channel list */
typedef struct {
uint32_t number;
nmxp_ChannelKey channel[MAX_N_CHAN];
} nmxp_ChannelList;
NMXP_CHAN_KEY channel[MAX_N_CHAN];
} NMXP_CHAN_LIST;
/*! \brief Looks up a channel key in the nmxp_ChannelList using the name
/*! \brief Looks up a channel key in the NMXP_CHAN_LIST using the name
*
* \param name
* \param channelList
* \param name Channel name.
* \param channelList Channel list.
*
* \retval
* \return Key of the channel with name. -1 On error.
*
*/
int lookupChannelKey(char* name, nmxp_ChannelList *channelList);
int nmxp_chan_lookupKey(char* name, NMXP_CHAN_LIST *channelList);
/*! \brief Looks up a channel name in the nmxp_ChannelList using a key
/*! \brief Looks up a channel name in the NMXP_CHAN_LIST using a key
*
* \param key
* \param channelList
* \param key Channel key.
* \param channelList Channel list.
*
* \retval
* \return Name of channel with key. NULL on error.
*
*/
char *lookupChannelName(int key, nmxp_ChannelList *channelList);
char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList);
#endif
......@@ -25,15 +25,15 @@ int nmxp_sendConnect(int isock) {
return nmxp_sendMessage(isock, NMXPMSG_CONNECT, NULL, 0);
}
int nmxp_sendTerminateSubscription(int isock, enum NMXP_REASON_SHUTDOWN reason, char *message) {
int nmxp_sendTerminateSubscription(int isock, NMXP_REASON_SHUTDOWN reason, char *message) {
return nmxp_sendMessage(isock, NMXPMSG_TERMINATESUBSCRIPTION, message, ((message)? strlen(message)-1 : 0));
}
int nmxp_receiveChannelList(int isock, nmxp_ChannelList **pchannelList) {
int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) {
int ret;
int i;
enum NMXP_MSG_SERVER type;
NMXP_MSG_SERVER type;
void *buffer;
uint32_t length;
......@@ -42,19 +42,19 @@ int nmxp_receiveChannelList(int isock, nmxp_ChannelList **pchannelList) {
ret = nmxp_receiveMessage(isock, &type, &buffer, &length);
if(type != NMXPMSG_CHANNELLIST) {
nmxp_gen_log(1, 0, "Type %d is not NMXPMSG_CHANNELLIST!\n", type);
nmxp_log(1, 0, "Type %d is not NMXPMSG_CHANNELLIST!\n", type);
} else {
*pchannelList = buffer;
(*pchannelList)->number = ntohl((*pchannelList)->number);
nmxp_gen_log(0, 1, "number of channels %d\n", (*pchannelList)->number);
nmxp_log(0, 1, "number of channels %d\n", (*pchannelList)->number);
// TODO check
for(i=0; i < (*pchannelList)->number; i++) {
(*pchannelList)->channel[i].key = ntohl((*pchannelList)->channel[i].key);
nmxp_gen_log(0, 1, "%d %s\n", (*pchannelList)->channel[i].key, (*pchannelList)->channel[i].name);
nmxp_log(0, 1, "%d %s\n", (*pchannelList)->channel[i].key, (*pchannelList)->channel[i].name);
}
}
......@@ -63,7 +63,7 @@ int nmxp_receiveChannelList(int isock, nmxp_ChannelList **pchannelList) {
}
int nmxp_sendAddTimeSeriesChannel(int isock, nmxp_ChannelList *channelList, uint32_t shortTermCompletion, uint32_t out_format, enum NMXP_BUFFER_FLAG buffer_flag) {
int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST *channelList, uint32_t shortTermCompletion, uint32_t out_format, NMXP_BUFFER_FLAG buffer_flag) {
int ret;
uint32_t buffer_length = 16 + (4 * channelList->number);
char *buffer = malloc(buffer_length);
......@@ -117,7 +117,8 @@ int unpack_bundle (int *outdata, unsigned char *indata, int *prev)
int d4[4];
short int d2[2];
int cb[4];
int i, j, k;
//mtheo int i, j, k;
int i, j, k=0;
unsigned char cbits;
cbits = (unsigned char)indata[0];
......@@ -131,7 +132,7 @@ int unpack_bundle (int *outdata, unsigned char *indata, int *prev)
for (j=0; j<4; j++) {
/*
nmxp_gen_log (0,0, "cb[%d]=%d\n", j, cb[j]);
nmxp_log (0,0, "cb[%d]=%d\n", j, cb[j]);
*/
switch (cb[j])
{
......@@ -169,7 +170,7 @@ int unpack_bundle (int *outdata, unsigned char *indata, int *prev)
for (i=0; i<k; i++) {
*outdata = *prev + d4[i];
/*
nmxp_gen_log(0,0, "val = %d, diff[%d] = %d, *prev = %d\n",
nmxp_log(0,0, "val = %d, diff[%d] = %d, *prev = %d\n",
*outdata, i, d4[i], *prev);
*/
*prev = *outdata;
......@@ -190,7 +191,7 @@ int unpack_bundle (int *outdata, unsigned char *indata, int *prev)
to the controlling SeedLink server.
------------------------------------------------------------------------*/
void nmxp_processDecompressedData(char* buffer, int length, nmxp_ChannelList *channelList)
void nmxp_processDecompressedData(char* buffer, int length, NMXP_CHAN_LIST *channelList)
{
int32_t netInt = 0;
int32_t pKey = 0;
......@@ -227,9 +228,9 @@ void nmxp_processDecompressedData(char* buffer, int length, nmxp_ChannelList *ch
}
/* Lookup the station and channel code */
sta = strdup(lookupChannelName(pKey, channelList));
sta = strdup(nmxp_chan_lookupName(pKey, channelList));
if ( (chan = strchr(sta, '.')) == NULL ) {
nmxp_gen_log(1,0, "Channel name not in STN.CHAN format: %s\n", sta);
nmxp_log(1,0, "Channel name not in STN.CHAN format: %s\n", sta);
free(sta);
return;
}
......@@ -238,23 +239,23 @@ void nmxp_processDecompressedData(char* buffer, int length, nmxp_ChannelList *ch
/* Send it off to the controlling SeedLink server */
/*
if ( send_raw_depoch(sta, chan, pTime, 0, 100, pDataPtr, pNSamp) < 0 ) {
nmxp_gen_log(1,0, "cannot send data to seedlink: %s", strerror(errno));
nmxp_log(1,0, "cannot send data to seedlink: %s", strerror(errno));
exit(1);
}
*/
nmxp_gen_log(0, 0, "%10d %5s_%3s %10.4f, %04d, %04d, %03d\n", pKey, sta, chan, pTime, length, pNSamp, pSampRate);
nmxp_log(0, 0, "%10d %5s_%3s %10.4f, %04d, %04d, %03d\n", pKey, sta, chan, pTime, length, pNSamp, pSampRate);
/* print out header and/or data for different packet types */
nmxp_gen_log(0,1, "Received uncompressed data for stream %ld (%s_%s)\n",
nmxp_log(0,1, "Received uncompressed data for stream %ld (%s_%s)\n",
pKey, sta, chan);
nmxp_gen_log(0,1, " length: %d, nsamp: %d, samprate: %d, time: %f\n",
nmxp_log(0,1, " length: %d, nsamp: %d, samprate: %d, time: %f\n",
length, pNSamp, pSampRate, pTime);
free(sta);
}
void nmxp_processCompressedData(char* buffer_data, int length_data, nmxp_ChannelList *channelList)
void nmxp_processCompressedData(char* buffer_data, int length_data, NMXP_CHAN_LIST *channelList)
{
int32_t pKey = 0;
double pTime = 0.0;
......@@ -290,17 +291,17 @@ void nmxp_processCompressedData(char* buffer_data, int length_data, nmxp_Channel
int prev_xn;
my_order = get_my_wordorder();
nmxp_gen_log(0, 1, "my_order is %d\n", my_order);
nmxp_log(0, 1, "my_order is %d\n", my_order);
memcpy(&nmx_oldest_sequence_number, buffer_data, 4);
nmxp_gen_log(0, 1, "Oldest sequence number = %d\n", nmx_oldest_sequence_number);
nmxp_log(0, 1, "Oldest sequence number = %d\n", nmx_oldest_sequence_number);
memcpy(nmx_hdr, buffer_data+4, 17);
/* Decode the Nanometrics packet header bundle. */
memcpy (&nmx_ptype, nmx_hdr+0, 1);
if ( (nmx_ptype & 0xf) == 9) {
/* Filler packet. Discard entire packet. */
nmxp_gen_log (1,0, "Filler packet - discarding\n");
nmxp_log (1,0, "Filler packet - discarding\n");
//m continue;
exit(0);
}
......@@ -317,7 +318,7 @@ void nmxp_processCompressedData(char* buffer_data, int length_data, nmxp_Channel
const unsigned int high_scale_p = 4096 * 4096;
/* check if nmx_x0 is negative like as signed 3-byte int */
if( (nmx_x0 & high_scale) == high_scale) {
// nmxp_gen_log(0, 0, "WARNING: changed nmx_x0, old value = %d\n", nmx_x0);
// nmxp_log(0, 0, "WARNING: changed nmx_x0, old value = %d\n", nmx_x0);
nmx_x0 -= high_scale_p;
}
if (my_order != SEED_LITTLE_ENDIAN) {
......@@ -334,17 +335,17 @@ void nmxp_processCompressedData(char* buffer_data, int length_data, nmxp_Channel
chan_code = nmx_sample_rate&7;
this_sample_rate = nmx_rate_code_to_sample_rate[rate_code];
nmxp_gen_log(0, 1, "nmx_ptype = %d\n", nmx_ptype);
nmxp_gen_log(0, 1, "nmx_seconds = %d\n", nmx_seconds);
nmxp_gen_log(0, 1, "nmx_ticks = %d\n", nmx_ticks);
nmxp_log(0, 1, "nmx_ptype = %d\n", nmx_ptype);
nmxp_log(0, 1, "nmx_seconds = %d\n", nmx_seconds);
nmxp_log(0, 1, "nmx_ticks = %d\n", nmx_ticks);
nmxp_gen_log(0, 1, "nmx_seconds_double = %f\n", nmx_seconds_double);
nmxp_gen_log(0, 1, "nmx_x0 = %d\n", nmx_x0);
nmxp_log(0, 1, "nmx_seconds_double = %f\n", nmx_seconds_double);
nmxp_log(0, 1, "nmx_x0 = %d\n", nmx_x0);
nmxp_gen_log(0, 1, "nmx_instr_id = %d\n", nmx_instr_id);
nmxp_gen_log(0, 1, "nmx_seqno = %d\n", nmx_seqno);
nmxp_gen_log(0, 1, "nmx_sample_rate = %d\n", nmx_sample_rate);
nmxp_gen_log(0, 1, "this_sample_rate = %d\n", this_sample_rate);
nmxp_log(0, 1, "nmx_instr_id = %d\n", nmx_instr_id);
nmxp_log(0, 1, "nmx_seqno = %d\n", nmx_seqno);
nmxp_log(0, 1, "nmx_sample_rate = %d\n", nmx_sample_rate);
nmxp_log(0, 1, "this_sample_rate = %d\n", this_sample_rate);
comp_bytecount = length_data-21;
indata = (unsigned char *) buffer_data + 21;
......@@ -355,23 +356,23 @@ void nmxp_processCompressedData(char* buffer_data, int length_data, nmxp_Channel
nout = 1;
for (i=0; i<comp_bytecount; i+=17) {
if (i+17>comp_bytecount) {
nmxp_gen_log (1,0, "comp_bytecount = %d, i+17 = %d\n",
nmxp_log (1,0, "comp_bytecount = %d, i+17 = %d\n",
comp_bytecount, i+17);
exit(1);
}
if (nout+16 > MAX_OUTDATA) {
nmxp_gen_log (1,0, "Output buffer size too small\n");
nmxp_log (1,0, "Output buffer size too small\n");
exit(1);
}
k = unpack_bundle (outdata+nout,indata+i,&prev_xn);
if (k < 0) nmxp_gen_log (1,0, "Break: %d\n", __LINE__);
if (k < 0) nmxp_log (1,0, "Break: %d\n", __LINE__);
if (k < 0) break;
nout += k;
/* prev_xn = outdata[nout-1]; */
}
nout--;
nmxp_gen_log(0, 1, "Unpacked %d samples.\n", nout);
nmxp_log(0, 1, "Unpacked %d samples.\n", nout);
pKey = (nmx_instr_id << 16) | ( 1 << 8) | ( chan_code);
......@@ -382,46 +383,46 @@ void nmxp_processCompressedData(char* buffer_data, int length_data, nmxp_Channel
pNSamp = nout;
/* Lookup the station and channel code */
sta = strdup(lookupChannelName(pKey, channelList));
sta = strdup(nmxp_chan_lookupName(pKey, channelList));
if ( (chan = strchr(sta, '.')) == NULL ) {
nmxp_gen_log(1,0, "Channel name not in STN.CHAN format: %s\n", sta);
nmxp_log(1,0, "Channel name not in STN.CHAN format: %s\n", sta);
free(sta);
return;
}
*chan++ = '\0';
nmxp_gen_log(0, 1, "Channel key %d for %s.%s\n", pKey, sta, chan);
nmxp_log(0, 1, "Channel key %d for %s.%s\n", pKey, sta, chan);
/* Send it off to the controlling SeedLink server */
/*
f ( send_raw_depoch(sta, chan, pTime, 0, 100, pDataPtr, pNSamp) < 0 ) {
nmxp_gen_log(1,0, "cannot send data to seedlink: %s", strerror(errno));
nmxp_log(1,0, "cannot send data to seedlink: %s", strerror(errno));
exit(1);
}
*/
nmxp_gen_log(0, 0, "%10d %5s_%3s %10.4f, %04d, %04d, %03d\n", pKey, sta, chan, pTime, length_data, pNSamp, pSampRate);
nmxp_log(0, 0, "%10d %5s_%3s %10.4f, %04d, %04d, %03d\n", pKey, sta, chan, pTime, length_data, pNSamp, pSampRate);
/* print out header and/or data for different packet types */
nmxp_gen_log(0,2, "Received compressed data for stream %ld (%s_%s)\n",
nmxp_log(0,2, "Received compressed data for stream %ld (%s_%s)\n",
pKey, sta, chan);
nmxp_gen_log(0,2, " length: %d, nsamp: %d, samprate: %d, time: %f\n",
nmxp_log(0,2, " length: %d, nsamp: %d, samprate: %d, time: %f\n",
length_data, pNSamp, pSampRate, pTime);
free(sta);
}
int nmxp_receiveCompressedData(int isock, nmxp_ChannelList *channelList) {
int nmxp_receiveCompressedData(int isock, NMXP_CHAN_LIST *channelList) {
int ret;
enum NMXP_MSG_SERVER type;
NMXP_MSG_SERVER type;
void *buffer;
uint32_t length;
ret = nmxp_receiveMessage(isock, &type, &buffer, &length);
if(type != NMXPMSG_COMPRESSED) {
nmxp_gen_log(1, 0, "Type %d is not NMXPMSG_COMPRESSED!\n", type);
nmxp_log(1, 0, "Type %d is not NMXPMSG_COMPRESSED!\n", type);
} else {
nmxp_processCompressedData(buffer, length, channelList);
......@@ -430,17 +431,17 @@ int nmxp_receiveCompressedData(int isock, nmxp_ChannelList *channelList) {
return ret;
}
int nmxp_receiveDecompressedData(int isock, nmxp_ChannelList *channelList) {
int nmxp_receiveDecompressedData(int isock, NMXP_CHAN_LIST *channelList) {
int ret;
enum NMXP_MSG_SERVER type;
NMXP_MSG_SERVER type;
void *buffer;
uint32_t length;
ret = nmxp_receiveMessage(isock, &type, &buffer, &length);
if(type != NMXPMSG_DECOMPRESSED) {
nmxp_gen_log(1, 0, "Type %d is not NMXPMSG_DECOMPRESSED!\n", type);
nmxp_log(1, 0, "Type %d is not NMXPMSG_DECOMPRESSED!\n", type);
} else {
nmxp_processDecompressedData(buffer, length, channelList);
......
......@@ -35,12 +35,12 @@ int nmxp_openSocket(char *hostname, int portNum)
if (!hostname)
{
nmxp_gen_log(1,0, "Empty host name?\n");
nmxp_log(1,0, "Empty host name?\n");
return -1;
}
if ( (hostinfo = gethostbyname(hostname)) == NULL) {
nmxp_gen_log(1,0, "Cannot lookup host: %s\n", hostname);
nmxp_log(1,0, "Cannot lookup host: %s\n", hostname);
return -1;
}
......@@ -49,7 +49,7 @@ int nmxp_openSocket(char *hostname, int portNum)
isock = socket (AF_INET, SOCK_STREAM, 0);
if (isock < 0)
{
nmxp_gen_log (1,0, "Can't open stream socket\n");
nmxp_log (1,0, "Can't open stream socket\n");
exit(1);
}
......@@ -63,19 +63,19 @@ int nmxp_openSocket(char *hostname, int portNum)
/* Report action and resolved address */
memcpy(&hostaddr.s_addr, *hostinfo->h_addr_list,
sizeof (hostaddr.s_addr));
nmxp_gen_log(0,1, "Attempting to connect to %s port %d\n",
nmxp_log(0,1, "Attempting to connect to %s port %d\n",
inet_ntoa(hostaddr), portNum);
if (connect(isock, (struct sockaddr *)&psServAddr, sizeof(psServAddr)) >= 0)
{
sleepTime = 1;
nmxp_gen_log(0, 1, "Connection established: socket=%i,IP=%s,port=%d\n",
nmxp_log(0, 1, "Connection established: socket=%i,IP=%s,port=%d\n",
isock, inet_ntoa(hostaddr), portNum);
return isock;
}
else
{
nmxp_gen_log(0, 1, "Trying again later...Sleeping\n");
nmxp_log(0, 1, "Trying again later...Sleeping\n");
close (isock);
sleep (sleepTime);
sleepTime *= 2;
......@@ -127,7 +127,7 @@ int nmxp_recv_ctrl(int isock, void* buffer, int length)
strcpy(recv_errno_str, "DEFAULT_NO_VALUE");
break;
}
nmxp_gen_log(0,0, "nmxp_recv_ctrl(): (recvCount != length) %d != %d - errno = %d (%s)\n", recvCount, length, recv_errno, recv_errno_str);
nmxp_log(0,0, "nmxp_recv_ctrl(): (recvCount != length) %d != %d - errno = %d (%s)\n", recvCount, length, recv_errno, recv_errno_str);
return NMXP_SOCKET_ERROR;
}
......@@ -136,24 +136,24 @@ int nmxp_recv_ctrl(int isock, void* buffer, int length)
}
int nmxp_sendHeader(int isock, enum NMXP_MSG_CLIENT type, uint32_t length)
int nmxp_sendHeader(int isock, NMXP_MSG_CLIENT type, uint32_t length)
{
nmxp_MessageHeader msg;
NMXP_MESSAGE_HEADER msg;
msg.signature = htonl(NMX_SIGNATURE);
msg.type = htonl(type);
msg.length = htonl(length);
return nmxp_send_ctrl(isock, &msg, sizeof(nmxp_MessageHeader));
return nmxp_send_ctrl(isock, &msg, sizeof(NMXP_MESSAGE_HEADER));
}
int nmxp_receiveHeader(int isock, enum NMXP_MSG_SERVER *type, uint32_t *length)
int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, uint32_t *length)
{
int ret ;
nmxp_MessageHeader msg;
NMXP_MESSAGE_HEADER msg;
ret = nmxp_recv_ctrl(isock, &msg, sizeof(nmxp_MessageHeader));
ret = nmxp_recv_ctrl(isock, &msg, sizeof(NMXP_MESSAGE_HEADER));
*type = 0;
*length = 0;
......@@ -163,13 +163,13 @@ int nmxp_receiveHeader(int isock, enum NMXP_MSG_SERVER *type, uint32_t *length)
msg.type = ntohl(msg.type);
msg.length = ntohl(msg.length);
nmxp_gen_log(0,1, "nmxp_receiveHeader(): signature = %d, type = %d, length = %d\n",
nmxp_log(0,1, "nmxp_receiveHeader(): signature = %d, type = %d, length = %d\n",
msg.signature, msg.type, msg.length);
if (msg.signature != NMX_SIGNATURE)
{
ret = NMXP_SOCKET_ERROR;
nmxp_gen_log(1,0, "nmxp_receiveHeader(): signature mismatches. signature = %d, type = %d, length = %d\n",
nmxp_log(1,0, "nmxp_receiveHeader(): signature mismatches. signature = %d, type = %d, length = %d\n",
msg.signature, msg.type, msg.length);
} else {
*type = msg.type;
......@@ -181,7 +181,7 @@ int nmxp_receiveHeader(int isock, enum NMXP_MSG_SERVER *type, uint32_t *length)
}
int nmxp_sendMessage(int isock, enum NMXP_MSG_CLIENT type, void *buffer, uint32_t length) {
int nmxp_sendMessage(int isock, NMXP_MSG_CLIENT type, void *buffer, uint32_t length) {
int ret;
ret = nmxp_sendHeader(isock, type, length);
if( ret == NMXP_SOCKET_OK) {
......@@ -193,7 +193,7 @@ int nmxp_sendMessage(int isock, enum NMXP_MSG_CLIENT type, void *buffer, uint32_
}
int nmxp_receiveMessage(int isock, enum NMXP_MSG_SERVER *type, void **buffer, uint32_t *length) {
int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, uint32_t *length) {
int ret;
*buffer = NULL;
*length = 0;
......@@ -204,16 +204,16 @@ int nmxp_receiveMessage(int isock, enum NMXP_MSG_SERVER *type, void **buffer, ui
*buffer = malloc(*length);
ret = nmxp_recv_ctrl(isock, *buffer, *length);
} else {
nmxp_gen_log(1,0, "Error in nmxp_receiveMessage()\n");