Commit 72df2aee authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Start


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@5 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent ad17a6cc
/*! \mainpage
*
* \section intro_sec Introduction
*
* This is the introduction.
*
* \section install_sec Installation
*
* ./configure
*
* make
*
* make install
*
* \section usage_sec Usage
*
* \subsection step1 Step 1: Opening the box
*
* etc...
*
* \section about_sec About
*
* Author:
* Matteo Quintiliani
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*/
/*! \file
*
* \brief Nanometrics Protocol Libray
*
* Author:
* Matteo Quintiliani
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
*/
#ifndef NMXP_H
#define NMXP_H 1
#include "nmxpbase.h"
/*! \brief Sends the message "Connect" on a socket
*
* \param isock A descriptor referencing the socket.
*
* \retval SOCKET_OK on success
* \retval SOCKET_ERROR on error
*
*/
int sendConnect(int isock);
/*! \brief Sends the message "TerminateSubscription" on a socket
*
* \param isock A descriptor referencing the socket.
* \param reason Reason for the shutdown.
* \param message String message. It could be NULL.
*
* \retval SOCKET_OK on success
* \retval SOCKET_ERROR on error
*
*/
int sendTerminateSubscription(int isock, enum NMXP_REASON_SHUTDOWN reason, char *message);
/*! \brief The key/name info for one channel */
typedef struct ChannelKey
{
uint32_t key;
char name[12];
} ChannelKey;
#define MAX_N_CHAN 1000
/*! \brief Channel List */
typedef struct ChannelList
{
uint32_t number;
ChannelKey channel[MAX_N_CHAN];
} ChannelList;
/*! \brief Receive message "ChannelList" from a socket
*
* \param isock A descriptor referencing the socket.
* \param pchannelList[out] List of channels. It will need to be freed!
*
* \retval SOCKET_OK on success
* \retval SOCKET_ERROR on error
*
*/
int receiveChannelList(int isock, ChannelList **pchannelList);
#endif
/*! \file
*
* \brief Nanometrics Protocol Libray
*
* Author:
* Matteo Quintiliani
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
*/
#include "nmxp.h"
#include <stdio.h>
#include <string.h>
int sendConnect(int isock) {
return sendMessage(isock, NMXPMSG_CONNECT, NULL, 0);
}
int sendTerminateSubscription(int isock, enum NMXP_REASON_SHUTDOWN reason, char *message) {
return sendMessage(isock, NMXPMSG_TERMINATESUBSCRIPTION, message, ((message)? strlen(message)-1 : 0));
}
int receiveChannelList(int isock, ChannelList **pchannelList) {
int ret;
int i;
enum NMXP_MSG_SERVER type;
void *buffer;
uint32_t length;
*pchannelList = NULL;
ret = receiveMessage(isock, &type, &buffer, &length);
if(type != NMXPMSG_CHANNELLIST) {
gen_log(1, 0, "Type %d is not NMXPMSG_CHANNELLIST!\n", type);
} else {
*pchannelList = buffer;
(*pchannelList)->number = ntohl((*pchannelList)->number);
gen_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);
gen_log(0, 1, "%d %s\n", (*pchannelList)->channel[i].key, (*pchannelList)->channel[i].name);
}
}
return ret;
}
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