/************************************************************************/
/* Copyright 2009-2012 MBARI						*/
/************************************************************************/
/* Summary  : Definitions for interfacing to libSensorNode		*/
/* Filename : sensorNode.h						*/
/* Author   : Robert Herlien (rah)					*/
/* Project  : xFOCE							*/
/* Revision: 1.0							*/
/* Created  : 04/22/2013						*/
/*									    */
/* MBARI provides this documentation and code "as is", with no warranty,    */
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium  */
/* Research Institute to assist in its use, correction, modification, or    */
/* enhancement. This information should not be published or distributed to  */
/* third parties without specific written permission from MBARI.            */
/*									    */
/************************************************************************/
/* Modification History:						*/
/* 22apr2013, rah							*/
/************************************************************************/

#ifndef INCsensorNodeh
#define INCsensorNodeh	1

#include <sys/types.h>


/****************************************/
/* Typedefs and definitions		*/
/****************************************/

#define SENSOR_NODES	16		/* Max SensorNodes supported	*/
#define SN_SER_PORTS	3		/* Number ser ports on SensorNode*/
#define SN_PWR_PORTS	4		/* Num pwr ports on SensorNode  */
#define SN_AD_CHANS	8		/* Num A/D channels on SensorNode*/

#ifndef SNLIB
typedef void	*SensorNodeHandle;
typedef void	*RemSerHandle;
#endif

typedef short int	MBool;
typedef int		Errno;

typedef enum {BlinkyOff=0, BlinkyOn, BlinkyDebug} BlinkyState;

#ifndef FALSE
#define FALSE	0
#endif
#ifndef TRUE
#define	TRUE	~FALSE
#endif
#ifndef ON
#define ON	TRUE
#endif
#ifndef OFF
#define	OFF	FALSE
#endif

#define OK	 0
#define SUCCESS	 0
#define ERROR	-1
#define FOREVER	while(TRUE)

    
/****************************************/
/* Function Declarations		*/
/****************************************/

/* Library-wide functions	*/
void		initSensorNodeLib(void);
void		snSetDebug(MBool onoff);
SensorNodeHandle openSensorNode(char *dev, int baud, int slaveID);
Errno		closeSensorNode(SensorNodeHandle snh);

/* Remote Serial Functions	*/
RemSerHandle	snOpenSerial(SensorNodeHandle snh, uint16_t port);
Errno		snSerInit(RemSerHandle rsh, int baud, char parity, int stop);
Errno		snCloseSerial(RemSerHandle rsh);

uint32_t		snSerRead(RemSerHandle rsh, char *buffer, uint32_t len);
uint32_t		snSerWrite(RemSerHandle rsh, const char *buffer, uint32_t len);
Errno		snSerDrain(RemSerHandle rsh, uint32_t tmout);
Errno		snSerIFlush(RemSerHandle rsh);
Errno		snSerOFlush(RemSerHandle rsh);
int16_t		snSerRxCount(RemSerHandle rsh);
Errno		snSerBreak(RemSerHandle rsh, uint16_t breakTime);
Errno		snSerSetTxEnbl(RemSerHandle rsh, MBool enbl);

/* Remote Power Functions	*/
Errno		snPower(SensorNodeHandle snh, uint16_t port, MBool onoff);
int16_t		snPowerIsOn(SensorNodeHandle snh, uint16_t port);
Errno		snGetPowerVector(SensorNodeHandle snh, uint16_t *vect);

/* Remote A/D Functions		*/
Errno		snAnalogChan(SensorNodeHandle snh, uint16_t chan, uint16_t *val);
Errno		snAnalogChans(SensorNodeHandle snh, uint16_t chan, uint16_t nchans, uint16_t *val);
Errno		snSetAnalogParms(SensorNodeHandle snh, uint16_t chan, uint16_t nchans, uint16_t *parms);
Errno		snGetAnalogParms(SensorNodeHandle snh, uint16_t chan, uint16_t nchans, uint16_t *parms);
Errno		snAnalogUse16bit(SensorNodeHandle snh, MBool use16bit);

/* Misc		*/
Errno		snGetSerialNum(SensorNodeHandle snh, uint16_t *num);
Errno		snGetSoftwareRev(SensorNodeHandle snh, uint16_t *num);
Errno		snGetBoardConfig(SensorNodeHandle snh, uint32_t *cfg);
Errno		snBlinky(SensorNodeHandle snh, BlinkyState state);
Errno		snSetDCAlwaysOn(SensorNodeHandle snh, MBool on);

#endif	/* INCsensorNodeh */
