#ifndef __XPORT_H__
#define __XPORT_H__
/** \file  XPort.h

   XPort.h defines classes implementing an interface to
   Lantronix XPort single port terminal servers. 

   copyright MBARI 2008 
  @author k. headley
 
 */
/****************************************************************************/
/* Copyright (c) 2008 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : XPort.h                                                       */
/* Author   : K Headley                                                     */
/* Project  : Benthic Imaging AUV                                           */
/* Created  : 04/01/2008                                                    */
/****************************************************************************/
/* Modification History:                                                    */
/*  $Id: XPort.h,v 1.6.4.1 2016/05/19 18:28:57 headley Exp $   */
/*  $Name: gnc $ */
/****************************************************************************/

#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
// unix.h must be included AFTER
// socket.h, else gethostname()
// doesn't work
#ifdef _QNX
#include <iostream.h>
#include <iomanip.h>
#include <strstream.h>
#include <unix.h>
#else
#include <iostream>
#include <iomanip>
#include <sstream>
#include <ctime>
#endif
#include <errno.h>
#include "Utils.h"
#include "qnx_port.h"
#include "BicamConsts.h" /* for boolean */
#ifndef _QNX
using namespace std;
#endif

/** default server port for XPort simulator */
#define SERVER_PORT 1500

/** Max XPort message length */
#define MAX_MSG 100

/** default TCP/IP port for GPIO control */
#define GPIO_IP_PORT          0x77F0  /* port for controlling GPIO pins */

/** default TCP/IP port for Serial communication */
/** MatchPort supports two serial ports */
#define SERIAL_IP_PORT        10001   /* port for sending serial data (0x2711) */
#define SERIAL_IP_PORT1       10001   /* port 1 for sending serial data (0x2711) */
#define SERIAL_IP_PORT2       10002   /* port 2 for sending serial data (0x2712) */

/* XPort GPIO commands */
/* MatchPort GPIO commands same as XPort */
/** XPort GPIO command: get pin functions */
#define XP_CMD_GET_FUNCTIONS      0x10 
/** XPort GPIO command: get pin directions (0:input, 1:output) */
#define XP_CMD_GET_DIRECTIONS     0x11
/** XPort GPIO command: get pin active levels (1:active high, 0:active low )*/
#define XP_CMD_GET_ACTIVE_LEVELS  0x12
/** XPort GPIO command: get pin states (1: enabled 0:disabled) */
#define XP_CMD_GET_CURRENT_STATES 0x13
/** XPort GPIO command: set pin directions (0:input, 1:output) */
#define XP_CMD_SET_DIRECTIONS     0x19
/** XPort GPIO command: set active levels (1:active high, 0:active low */
#define XP_CMD_SET_ACTIVE_LEVELS  0x1A
/** XPort GPIO command: set pin states (1: enabled 0:disabled) */
#define XP_CMD_SET_CURRENT_STATES 0x1B

/* Common Xport GPIO masks 
   (note: these are intended for the XPort eval board)
*/
/** mask: Select all GPIO (for XP eval board: pins 0-2 ;for NR board: pins 0-8) */
#define XP_MASK_GPIO_SEL_ALL  0x07
/** mask: select none the GPIO pins */
#define XP_MASK_GPIO_SEL_NONE 0x00
/** mask: set all GPIO */
#define XP_MASK_GPIO_SET_ALL  0x07
/** mask: clear all GPIO */
#define XP_MASK_GPIO_CLR_ALL  0x00
/** mask: GPIO pin 0 */
#define XP_GPIO_0    0x1
/** mask: GPIO pin 1 */
#define XP_GPIO_1    0x2
/** mask: GPIO pin 2 */
#define XP_GPIO_2    0x4
/** mask: GPIO all pins (eval board) */
#define XP_GPIO_ALL  0x7
/** mask: GPIO no pins */
#define XP_GPIO_NONE 0x0
/** mask: GPIO pins all inputs */
#define XP_GPIO_IN   0x0
/** mask: GPIO pins all outputs (eval board) */
#define XP_GPIO_OUT  0x7
/** mask: GPIO pins all active low (eval board) */
#define XP_GPIO_LO   0x0
/** mask: GPIO pins all active high (eval board) */
#define XP_GPIO_HI   0x7
/** mask: GPIO pins all active low (eval board) */
#define XP_GPIO_ACTIVE_LO    0x7
/** mask: GPIO pins all active high (eval board) */
#define XP_GPIO_ACTIVE_HI    0x0
/** mask: GPIO pins all low */
#define XP_GPIO_ALL_LO       0x0
/** mask: GPIO pins all high */
#define XP_GPIO_ALL_HI       0x7
/** mask: GPIO pins all inactive */
#define XP_GPIO_ALL_INACTIVE 0x0
/** mask: GPIO pins all active */
#define XP_GPIO_ALL_ACTIVE   0x7
/** mask: GPIO pins all inactive */
#define XP_GPIO_ALL_INPUTS   0x0
/** mask: GPIO pins all active */
#define XP_GPIO_ALL_OUTPUTS  0x7

/* Imaging AUV GPIO masks to configure
 GPIO pins as follows:
 GPIO_0 : output, active HI
 GPIO_1 : output, active HI
 GPIO_2 : output, active HI
 
 Note that hardware documentation uses 1-based 
 indices for GPIO, software uses 0-based
 
Set Directions
 Bytes 1-4: Mask
 Bit X	
 1 means the direction for GPIO X will be updated with the value in the second parameter.
 0 means the direction for that GPIO will not change. 
 
 Bytes 5-8: New Directions
 Bit X
 1 means GPIO X will become an output. 
 0 means it will become an input.
 
Set Active Levels
Bytes 1-4: Mask
 Bit X	
 1 means the direction for GPIO X will be updated with the value in the second parameter.
 0 means the active type for that GPIO will not change. 
Bytes 5-8: New Active Levels
 Bit X
 1 means GPIO X will become active low. 
 0 means it will become active high.

 */
#define CFG_IAUV_XP_GPIO_DIR_MASK          XP_MASK_GPIO_SEL_ALL // set all pins
#define CFG_IAUV_XP_GPIO_DIR_LEVEL_MASK    XP_GPIO_ALL_HI       // set all pins outputs
#define CFG_IAUV_XP_GPIO_LEVEL_MASK        XP_MASK_GPIO_SEL_ALL // set all pins
#define CFG_IAUV_XP_GPIO_ACTIVE_LEVEL_MASK XP_GPIO_ACTIVE_LO    // set all pins active LO

/* Common Matchport GPIO masks 
 (note: for the MatchPort eval board, w/ 8 GPIO pins)
 */
/** mask: Select all GPIO (for eval board; pins 0-2) */
#define MP_MASK_GPIO_SEL_ALL  0xFF
/** mask: select none the GPIO pins */
#define MP_MASK_GPIO_SEL_NONE 0x00
/** mask: set all GPIO */
#define MP_MASK_GPIO_SET_ALL  0xFF
/** mask: clear all GPIO */
#define MP_MASK_GPIO_CLR_ALL  0x00
/** mask: GPIO pin 0 */
#define MP_GPIO_0    0x01
/** mask: GPIO pin 1 */
#define MP_GPIO_1    0x02
/** mask: GPIO pin 2 */
#define MP_GPIO_2    0x04
/** mask: GPIO pin 3 */
#define MP_GPIO_3    0x08
/** mask: GPIO pin 4 */
#define MP_GPIO_4    0x10
/** mask: GPIO pin 5 */
#define MP_GPIO_5    0x20
/** mask: GPIO pin 6 */
#define MP_GPIO_6    0x40
/** mask: GPIO pin 7 */
#define MP_GPIO_7    0x80
/** mask: GPIO all pins (XP eval board, MP MatchPort) */
#define MP_GPIO_ALL  0xFF
/** mask: GPIO no pins */
#define MP_GPIO_NONE 0x00
/** mask: GPIO pins all inputs */
#define MP_GPIO_IN   0x00
/** mask: GPIO pins all outputs (eval board) */
#define MP_GPIO_OUT  0xFF
/** mask: GPIO pins all active low (eval board) */
#define MP_GPIO_LO   0x00
/** mask: GPIO pins all active high (eval board) */
#define MP_GPIO_HI   0xFF
/** mask: GPIO pins all active low (eval board) */
#define MP_GPIO_ACTIVE_LO    0xFF
/** mask: GPIO pins all active high (eval board) */
#define MP_GPIO_ACTIVE_HI    0x00
/** mask: GPIO pins all low */
#define MP_GPIO_ALL_LO       0x00
/** mask: GPIO pins all high */
#define MP_GPIO_ALL_HI       0xFF
/** mask: GPIO pins all inactive */
#define MP_GPIO_ALL_INACTIVE 0x00
/** mask: GPIO pins all active */
#define MP_GPIO_ALL_ACTIVE   0xFF
/** mask: GPIO pins all inactive */
#define MP_GPIO_ALL_INPUTS   0x00
/** mask: GPIO pins all active */
#define MP_GPIO_ALL_OUTPUTS  0xFF

/* Imaging AUV GPIO masks to configure
	GPIO pins as follows:
 GPIO_0 : output, active LO [shutter trigger]
 GPIO_1 : output, active HI [NC]
 GPIO_2 : output, active HI [laser disable]
 GPIO_3 :  input, N/A       [humidity]
 GPIO_4 : output, active HI [cam vicor disable]
 GPIO_5 : output, active HI [str vicor disable]
 GPIO_6 : output, active HI [NC]
 GPIO_7 : output, active HI [NC]
 
 Note that hardware documentation uses 1-based 
 indices for GPIO, software uses 0-based

 Set Directions
 Bytes 1-4: Mask
 Bit X	
 1 means the direction for GPIO X will be updated with the value in the second parameter.
 0 means the direction for that GPIO will not change. 
 
 Bytes 5-8: New Directions
 Bit X
 1 means GPIO X will become an output. 
 0 means it will become an input.
 
 Set Active Levels
 Bytes 1-4: Mask
 Bit X	
 1 means the direction for GPIO X will be updated with the value in the second parameter.
 0 means the active type for that GPIO will not change. 
 Bytes 5-8: New Active Levels
 Bit X
 1 means GPIO X will become active low. 
 0 means it will become active high.
 */
#define CFG_IAUV_MP_GPIO_DIR_MASK          MP_MASK_GPIO_SEL_ALL // set all pins
#define CFG_IAUV_MP_GPIO_DIR_LEVEL_MASK    0xF7                 // set pins [3:3] input, [0:2],[4:7] outputs
#define CFG_IAUV_MP_GPIO_LEVEL_MASK        0xF7                 // set pins [0:2],[4:7] (input pin 3 not set)
#define CFG_IAUV_MP_GPIO_ACTIVE_LEVEL_MASK 0x01                 // set pins [1:2],[4:7] active HI, [0:0] active LO

/**
 Use these defines to configure the driver for different
 Lantronix devices (XPort, Matchport, etc.)
 These may be set using HW_CFG_FLAGS in the Makefile
 */
#ifdef LANTRONIX_XPORT
// use XPORT by default
#else
 #ifndef LANTRONIX_MATCHPORT
  #define LANTRONIX_XPORT	
 #endif
#endif

#ifdef LANTRONIX_MATCHPORT
// MatchPort GPIO configuration
#define CFG_MASK_GPIO_SEL_ALL                MP_MASK_GPIO_SEL_ALL  
#define CFG_MASK_GPIO_SEL_NONE               MP_MASK_GPIO_SEL_NONE 
#define CFG_MASK_GPIO_NONE                   MP_MASK_GPIO_NONE     
#define CFG_GPIO_NONE                        MP_GPIO_NONE          
#define CFG_GPIO_ALL                         MP_GPIO_ALL           
#define CFG_GPIO_ALL_HI                      MP_GPIO_ALL_HI        
#define CFG_GPIO_OUT                         MP_GPIO_OUT           
#define CFG_GPIO_HI                          MP_GPIO_HI            

#define CFG_GPIO_ALL_OUTPUTS                 MP_GPIO_ALL_OUTPUTS   
#define CFG_GPIO_ALL_INACTIVE                MP_GPIO_ALL_INACTIVE  

#define CFG_GPIO_ACTIVE_HI                   MP_GPIO_ACTIVE_HI     
#define CFG_GPIO_ACTIVE_LO                   MP_GPIO_ACTIVE_LO     

#define CFG_GPIO_DIR_MASK                    CFG_IAUV_MP_GPIO_DIR_MASK         
#define CFG_GPIO_DIR_LEVEL_MASK              CFG_IAUV_MP_GPIO_DIR_LEVEL_MASK   
#define CFG_GPIO_LEVEL_MASK                  CFG_IAUV_MP_GPIO_LEVEL_MASK       
#define CFG_GPIO_ACTIVE_LEVEL_MASK           CFG_IAUV_MP_GPIO_ACTIVE_LEVEL_MASK

#define CAMTRIGGER_GPIO_SELECT_MASK           MP_GPIO_0 
#define CAMTRIGGER_GPIO_DIR_MASK              MP_GPIO_0 
#define CAMTRIGGER_GPIO_ACTIVE_LEVEL_MASK     MP_GPIO_0 
#define CAMTRIGGER_GPIO_STATE_MASK            MP_GPIO_0 

#define LASER_DISABLE_GPIO_SELECT_MASK        MP_GPIO_2 
#define LASER_DISABLE_GPIO_DIR_MASK           MP_GPIO_2 
#define LASER_DISABLE_GPIO_ACTIVE_LEVEL_MASK  MP_GPIO_2 
#define LASER_DISABLE_GPIO_STATE_MASK         MP_GPIO_2 

#define CAMERA_DISABLE_GPIO_SELECT_MASK       MP_GPIO_4 
#define CAMERA_DISABLE_GPIO_DIR_MASK          MP_GPIO_4 
#define CAMERA_DISABLE_GPIO_ACTIVE_LEVEL_MASK MP_GPIO_4 
#define CAMERA_DISABLE_GPIO_STATE_MASK        MP_GPIO_4 

#define STROBE_DISABLE_GPIO_SELECT_MASK       MP_GPIO_5 
#define STROBE_DISABLE_GPIO_DIR_MASK          MP_GPIO_5 
#define STROBE_DISABLE_GPIO_ACTIVE_LEVEL_MASK MP_GPIO_5 
#define STROBE_DISABLE_GPIO_STATE_MASK        MP_GPIO_5 

#endif // LANTRONIX_MATCHPORT

#ifdef LANTRONIX_XPORT
// XPort GPIO configuration (default)
#define CFG_MASK_GPIO_SEL_ALL                XP_MASK_GPIO_SEL_ALL
#define CFG_MASK_GPIO_SEL_NONE               XP_MASK_GPIO_SEL_NONE
#define CFG_MASK_GPIO_NONE                   XP_MASK_GPIO_NONE
#define CFG_GPIO_NONE                        XP_GPIO_NONE
#define CFG_GPIO_ALL                         XP_GPIO_ALL
#define CFG_GPIO_ALL_HI                      XP_GPIO_ALL_HI
#define CFG_GPIO_OUT                         XP_GPIO_OUT
#define CFG_GPIO_HI                          XP_GPIO_HI

#define CFG_GPIO_ALL_OUTPUTS                 XP_GPIO_ALL_OUTPUTS
#define CFG_GPIO_ALL_INACTIVE                XP_GPIO_ALL_INACTIVE

#define CFG_GPIO_ACTIVE_HI                   XP_GPIO_ACTIVE_HI
#define CFG_GPIO_ACTIVE_LO                   XP_GPIO_ACTIVE_LO

#define CFG_GPIO_DIR_MASK                    CFG_IAUV_XP_GPIO_DIR_MASK
#define CFG_GPIO_DIR_LEVEL_MASK              CFG_IAUV_XP_GPIO_DIR_LEVEL_MASK
#define CFG_GPIO_LEVEL_MASK                  CFG_IAUV_XP_GPIO_LEVEL_MASK
#define CFG_GPIO_ACTIVE_LEVEL_MASK           CFG_IAUV_XP_GPIO_ACTIVE_LEVEL_MASK

#define CAMTRIGGER_GPIO_SELECT_MASK           XP_GPIO_0 
#define CAMTRIGGER_GPIO_DIR_MASK              XP_GPIO_0 
#define CAMTRIGGER_GPIO_ACTIVE_LEVEL_MASK     XP_GPIO_0 
#define CAMTRIGGER_GPIO_STATE_MASK            XP_GPIO_0 

#define STROBE_DISABLE_GPIO_SELECT_MASK       XP_GPIO_1 
#define STROBE_DISABLE_GPIO_DIR_MASK          XP_GPIO_1 
#define STROBE_DISABLE_GPIO_ACTIVE_LEVEL_MASK XP_GPIO_1 
#define STROBE_DISABLE_GPIO_STATE_MASK        XP_GPIO_1 

#define CAMERA_DISABLE_GPIO_SELECT_MASK       XP_GPIO_2 
#define CAMERA_DISABLE_GPIO_DIR_MASK          XP_GPIO_2 
#define CAMERA_DISABLE_GPIO_ACTIVE_LEVEL_MASK XP_GPIO_2 
#define CAMERA_DISABLE_GPIO_STATE_MASK        XP_GPIO_2 

#endif // LANTRONIX_XPORT


/* Function return values */
/** error: value is null */
#define ERR_NULL    -1
/** error: invalid command */
#define ERR_BADCMD  -2
/** error: invalid param1 */
#define ERR_BADPAR1 -3
/** error: invalid param2 */
#define ERR_BADPAR2 -4
/** return: test failed */
#define TEST_FAILED -5
/** return: test passed */
#define TEST_OK     0
/** return: is valid */
#define IS_VALID    0

/** Fake XPort/MPort command for sending serial data 
   instead of GPIO. We use same XPortCommand
   struct to send serial data; param1 is 
   an index into the messages[] array containing
   the message to send. param2 is unused.
*/
#define XP_CMD_SEND_MESSAGE       0x7F

/** length of XPort/MPort commands:
   - byte 0: command
   - bytes 1-4: GPIO control mask (param1)
   - bytes 5-8: GPIO value mask (param2)
*/
#define XPORT_COMMAND_LEN  9

/** length (bytes) of XPort/MPort command response:
   - byte 0  : command
   - byte 1-4: value
*/
#define XPORT_RESPONSE_LEN 5

/** Max number of commands accepted on
   command line
*/
#define MAX_XPORT_COMMANDS 32

/** TCP/IP port data type */
typedef short unsigned int t_TCP_PORT;

/** XPort/MPort GPIO command length */
#define XP_CMD_LEN (sizeof(unsigned char))
/** XPort GPIO parameter length */
#define XP_PARAM_LEN (sizeof(unsigned int))

/** Mnemonic IDs for TCP/IP socket connections */
enum ConnectionID{XPCON_SERIAL=0,XPCON_GPIO,XPCON_ALL};

/** [XPort | MPort]Command represents the 9-byte commands 
    used to control the XPort GPIO pins.

    Command format:
    byte 0   : command
    byte 1-4 : control mask indicating which GPIO pins to affect
    byte 5-8 : value mask indicating value to set
*/
class XPortCommand{
  friend ostream& operator<<(ostream& output, const XPortCommand& n);
 protected:
 private:
  /** GPIO command */
  unsigned char command;
  /** GPIO control mask */
  unsigned int param1;
  /** GPIO value mask */  
  unsigned int param2;

 public:
  XPortCommand();
  XPortCommand(unsigned char cmd,unsigned int p1,unsigned int p2);
  void set(unsigned char cmd,unsigned int param1,unsigned int param2);
  int validate();
  int parse(const char *command);
  void show();
  unsigned char getCommand();
  unsigned int getP1();
  unsigned int getP2();
  char *toBytes(char *buf);
};

/** [XPort | MPort]Response represents the 5-byte response returned
    by the XPort after writing a command to the GPIO port.

    Response format:
      - byte 0   
        - command
      - byte 1-4
        - return value indicating which GPIO pins were set\n 
                   (for set commands) or a return value (for get commands)

*/
class XPortResponse{
  friend ostream& operator<<(ostream& output, const XPortResponse& n);

 protected:
 private:
  /** GPIO command (see defined constants XP_CMD_...) */
  unsigned char command;
  /** GPIO return value */
  unsigned int param1;
 public:
  XPortResponse();
  XPortResponse(unsigned char cmd,unsigned int p1);
  void set(unsigned char cmd,unsigned int param1);
  int validate();
  int parse(char *response);
  void show();
  unsigned char getCommand();
  unsigned int getP1();
  char *toBytes(char *buf);
};

/** Encapsulates configuration parameters associated
    with a Lantronix XPort terminal server.

    The XPort has a serial port and a number of GPIO pins that
    may be configured as inputs or outputs, active high or low.
    XPort configuration and control is done via a TCP/IP socket
    connections. XPortConnection is used to store and manage
    these TCP/IP socket connections.

    A MatchPort server supports two XPort connections.
*/
class XPortConnection{
  friend ostream& operator<<(ostream& output, const XPortConnection& n);
 protected:
 private:
  /** XPort TCP/IP host name/address string */
  char *host;
  /** XPort GPIO TCP/IP port */
  int gpioPort;
  /** XPort Serial TCP/IP port */
  int serialPort;
  /** XPort GPIO direction control mask */
  unsigned int dirMask;
  /** XPort GPIO level control mask */
  unsigned int levelMask;
  /** XPort GPIO direction values (state) mask */
  unsigned int dirValues;
  /** XPort GPIO level values (state) mask */
  unsigned int levelValues;
  /** XPort GPIO TCP/IP socket descriptor */
  int sdGPIO;
  /** XPort Serial TCP/IP socket descriptor */
  int sdSERIAL;
 public:
  XPortConnection();
  XPortConnection(char *host, 
		  unsigned int gPort, 
		  unsigned int sPort,
		  unsigned int dMask,
		  unsigned int dValues,
		  unsigned int lMask,
		  unsigned int lValues);
  int configAll( char *host,
		 unsigned int serialIPPort,
		 unsigned int gpioIPPort, 
		 unsigned int dirMask,
		 unsigned int dirValues,
		 unsigned int levelMask,
		 unsigned int levelValues);
  int configHost( char *hostName);
  int configGPIO( int gpioIPPort, 
		 unsigned int dirMask,
		 unsigned int dirValues,
		 unsigned int levelMask,
		 unsigned int levelValues);
  int configSerial( int serialIPPort);
  void setsdGPIO(int sd);
  void setsdSerial(int sd);
  char *getHost();
  unsigned int getpGPIO();
  unsigned int getpSerial();
  int getsdGPIO();
  int getsdSerial();
  unsigned int getDirMask();
  unsigned int getDirValues();
  unsigned int getLevelMask();
  unsigned int getLevelValues();

};
/**
   Encapsulates Lantronix XPort single port terminal server data and behavior.
   These provide a serial port and up to 32 GPIO pins via separate TCP/IP socket
   connections. The GPIO pins are configurable as inputs or outputs,
   inverted or non-inverted outputs. There is another hardware 
   configuration TCP/IP por that these classes do not currently support. 
   An interactive configuration application is presented on this port, 
   and is used to set a number of internal hardware and firmware options.
   Since it is menu driven, it is somewhat difficult to do programmatically
   in a flexible way, and the need to do this isn't clear -- for now,
   it is assumed that this configuration is static.

   The XPort evaluation board implements 3 GPIO pins (some of the 
   constants reflect this, though some masks are 32 bits to support
   all possible GPIO).
   
   The three main classes are XPortConnection, XPortCommand, XPortResponse and
   XPort. The general pattern of use is:

   - Create an XPort object 
     (specifying host name, TCP/IP ports for gpio and serial, and initial GPIO configuration)
   - Open connections for serial/GPIO using the XPort.connectXP method  (establishes TCP/IP sockets)
   - Pass XPortCommand and XPortResponse objects to the XPort via its IO methods 
     (writeRead, writeCommand, readResponse)
   - Write data to the serial port using XPort.writeSerial
   - When finished using the XPort, disconnect sockets using XPort.xpdisconnect

   See xportTest.cc for unit tests and examples of how the XPort is used.

   TODO:
   - readSerial method
   - full XPort configuration support

*/
class XPort{
  /** output stream operator.*/
  friend ostream& operator<<(ostream& output, const XPort& n);
 protected:
 private:
  /** XPortConnection defining XPort TCP/IP and GPIO configuration */
  XPortConnection xpConnection;

  int connectSocket(char *host, int port);
 public:
  XPort();
  XPort(char *host, 
	unsigned int gpioPort, 
	unsigned int serialPort,
	unsigned int dirMask,
	unsigned int dirValues,
	unsigned int levelMask,
	unsigned int levelValues);
  XPortConnection *getConnection();
  int configure( char *host, 
		unsigned int gpioIPPort, 
		unsigned int serialIPPort,
		unsigned int dMask,
		unsigned int dValues,
		unsigned int lMask,
		unsigned int lValues);
  int connectxp(ConnectionID select,boolean doConfig);
  int connectxp(ConnectionID select);
  int disconnectxp(ConnectionID select);
  int writeBytes(int sd, char *buf, int len);
  int readBytes(int sd, char *buf, int len);
  int writeCommand(XPortCommand *xpCommand);
  int readResponse(XPortResponse *xpResponse);
  int writeRead(XPortCommand *xpCommand, XPortResponse *xpResponse);
  int writeSerial(const char *msg, unsigned int len, unsigned int offset);
  char *getHost();
  unsigned int getpGPIO();
  unsigned int getpSerial();
  int getsdGPIO();
  int getsdSerial();

};

#endif /* _XPORT_H_*/
