#include <XPort.h>
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:
See xportTest.cc for unit tests and examples of how the XPort is used.
TODO:
Public Member Functions | |
| XPort () | |
| Default no argument constructor. | |
| XPort (char *host, unsigned int gpioPort, unsigned int serialPort, unsigned int dirMask, unsigned int dirValues, unsigned int levelMask, unsigned int levelValues) | |
| Initializing constructor. | |
| XPortConnection * | getConnection () |
| |
| int | configure (char *host, unsigned int gpioIPPort, unsigned int serialIPPort, unsigned int dMask, unsigned int dValues, unsigned int lMask, unsigned int lValues) |
| Configures XPortConnection member variable. | |
| int | connectxp (ConnectionID select, boolean doConfig) |
| Establish socket connections to one or more XPort sockets. | |
| int | connectxp (ConnectionID select) |
| Establish socket connections to one or more XPort sockets. | |
| int | disconnectxp (ConnectionID select) |
| Disconnect socket connections to one or more XPort sockets. | |
| int | writeBytes (int sd, char *buf, int len) |
| Write bytes to the specified socket descriptor. | |
| int | readBytes (int sd, char *buf, int len) |
| Resd bytes from the specified socket descriptor into a buffer. | |
| int | writeCommand (XPortCommand *xpCommand) |
| Send XPortCommand to XPort GPIO port. | |
| int | readResponse (XPortResponse *xpResponse) |
| Read response to XPortCommand into XPortResponse. | |
| int | writeRead (XPortCommand *xpCommand, XPortResponse *xpResponse) |
| Write XPCommand and get response in single operation. | |
| int | writeSerial (const char *msg, unsigned int len, unsigned int offset) |
| Write bytes to XPort serial port. | |
| char * | getHost () |
| |
| unsigned int | getpGPIO () |
| |
| unsigned int | getpSerial () |
| |
| int | getsdGPIO () |
| |
| int | getsdSerial () |
| |
Private Member Functions | |
| int | connectSocket (char *host, int port) |
| Connect to specified XPort TCP/IP socket. | |
Private Attributes | |
| XPortConnection | xpConnection |
| XPortConnection defining XPort TCP/IP and GPIO configuration. | |
Friends | |
| ostream & | operator<< (ostream &output, const XPort &n) |
| output stream operator. | |
| XPort::XPort | ( | char * | host, | |
| unsigned int | gpioIPPort, | |||
| unsigned int | serialIPPort, | |||
| unsigned int | dMask, | |||
| unsigned int | dValues, | |||
| unsigned int | lMask, | |||
| unsigned int | lValues | |||
| ) |
Initializing constructor.
Configures XPortConnection member variable.
| host | XPort host name | |
| gpioIPPort | TCP/IP port to use for GPIO | |
| serialIPPort | TCP/IP port to use for serial IO | |
| dMask | GPIO direction pin-select mask | |
| dValues | GPIO initial direction values mask | |
| lMask | GPIO level pin-select mask | |
| lValues | GPIO initial level (state) values mask |
| int XPort::connectSocket | ( | char * | host, | |
| int | port | |||
| ) | [private] |
| int XPort::configure | ( | char * | host, | |
| unsigned int | gpioIPPort, | |||
| unsigned int | serialIPPort, | |||
| unsigned int | dMask, | |||
| unsigned int | dValues, | |||
| unsigned int | lMask, | |||
| unsigned int | lValues | |||
| ) |
Configures XPortConnection member variable.
| host | XPort host name | |
| gpioIPPort | TCP/IP port to use for GPIO | |
| serialIPPort | TCP/IP port to use for serial IO | |
| dMask | GPIO direction pin-select mask | |
| dValues | GPIO initial direction values mask | |
| lMask | GPIO level pin-select mask | |
| lValues | GPIO initial level (state) values mask |
| int XPort::connectxp | ( | ConnectionID | select, | |
| boolean | doConfig | |||
| ) |
| int XPort::connectxp | ( | ConnectionID | select | ) |
| int XPort::disconnectxp | ( | ConnectionID | select | ) |
| int XPort::writeBytes | ( | int | sd, | |
| char * | buf, | |||
| int | len | |||
| ) |
Write bytes to the specified socket descriptor.
| sd | Socket descriptor | |
| buf | pointer to character buffer | |
| len | number of bytes to write |
| int XPort::readBytes | ( | int | sd, | |
| char * | buf, | |||
| int | len | |||
| ) |
Resd bytes from the specified socket descriptor into a buffer.
| sd | Socket descriptor | |
| buf | pointer to character buffer | |
| len | number of bytes to write |
| int XPort::writeCommand | ( | XPortCommand * | xpCommand | ) |
Send XPortCommand to XPort GPIO port.
| xpCommand | Command to send |
| int XPort::readResponse | ( | XPortResponse * | xpResponse | ) |
Read response to XPortCommand into XPortResponse.
| xpResponse | pointer to XPResponse to store results in |
| int XPort::writeRead | ( | XPortCommand * | xpCommand, | |
| XPortResponse * | xpResponse | |||
| ) |
Write XPCommand and get response in single operation.
| xpCommand | Command to send | |
| xpResponse | pointer to XPResponse to store results in |
| int XPort::writeSerial | ( | const char * | msg, | |
| unsigned int | len, | |||
| unsigned int | offset | |||
| ) |
Write bytes to XPort serial port.
| msg | pointer to character buffer | |
| len | number of bytes to send | |
| offset | offset from start of buffer |
| char * XPort::getHost | ( | ) |
| unsigned int XPort::getpGPIO | ( | ) |
| unsigned int XPort::getpSerial | ( | ) |
| int XPort::getsdGPIO | ( | ) |
| int XPort::getsdSerial | ( | ) |
| ostream& operator<< | ( | ostream & | output, | |
| const XPort & | n | |||
| ) | [friend] |
output stream operator.
1.5.4