libnifalcon  1.0.1
Public Types | Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
libnifalcon::FalconComm Class Referenceabstract

#include <FalconComm.h>

+ Inheritance diagram for libnifalcon::FalconComm:
+ Collaboration diagram for libnifalcon::FalconComm:

Public Types

enum  {
  FALCON_COMM_DEVICE_ERROR = 2000, FALCON_COMM_NOT_INITIALIZED, FALCON_COMM_DEVICE_NOT_FOUND_ERROR, FALCON_COMM_DEVICE_NOT_VALID_ERROR,
  FALCON_COMM_DEVICE_INDEX_OUT_OF_RANGE_ERROR, FALCON_COMM_FIRMWARE_NOT_FOUND_ERROR, FALCON_COMM_WRITE_ERROR, FALCON_COMM_READ_ERROR
}
 

Public Member Functions

 FalconComm ()
 
virtual ~FalconComm ()
 
virtual bool getDeviceCount (unsigned int &count)=0
 
virtual bool open (unsigned int index)=0
 
virtual bool close ()=0
 
virtual bool read (uint8_t *str, unsigned int size)=0
 
virtual bool write (uint8_t *str, unsigned int size)=0
 
virtual bool readBlocking (uint8_t *str, unsigned int size)=0
 
virtual bool writeBlocking (uint8_t *str, unsigned int size)=0
 
virtual bool setFirmwareMode ()=0
 
virtual bool setNormalMode ()=0
 
int getLastBytesRead ()
 
int getLastBytesWritten ()
 
int getDeviceErrorCode ()
 
bool isCommOpen ()
 
virtual void reset ()
 
bool hasBytesAvailable ()
 
unsigned int getBytesAvailable ()
 
virtual void setBytesAvailable (unsigned int b)
 
virtual void poll ()
 
- Public Member Functions inherited from libnifalcon::FalconCore
 FalconCore ()
 
virtual ~FalconCore ()
 
int getErrorCode ()
 

Protected Attributes

int m_deviceErrorCode
 
int m_lastBytesRead
 
int m_lastBytesWritten
 
bool m_isCommOpen
 
bool m_hasBytesAvailable
 
int m_bytesAvailable
 
- Protected Attributes inherited from libnifalcon::FalconCore
int m_errorCode
 

Static Protected Attributes

static const unsigned int MAX_DEVICES = 128
 
static const unsigned int FALCON_VENDOR_ID = 0x0403
 
static const unsigned int FALCON_PRODUCT_ID = 0xCB48
 

Detailed Description

FalconComm is the base class for all communications behavior implementations. The Falcon itself uses an FTDI chip to talk to the computer, so these will most likely be proxies to either an FTDI library (like FTD2XX), or reimplementation of FTDI calls (like our libusb implementation).

FalconComm is responsible for handling a few different tasks

All communications objects are considered to be non-blocking, and should reimplement a poll function to maintain this. Both FTD2XX and libusb, the two implementations of the FalconComm class as of this writing, operate in a non-blocking way. If blocking calls are required (currently only used for loading firmware), blocking functions are provided but are specified as such to warn the user.

As mentioned above, the falcon can operate in two modes

To get the device into firmware mode, the follow set of steps needs to happen:

  1. Clear send and receive buffers
  2. Set FTDI latency timer to 16ms
  3. Set line properties to 8N1
  4. Set baud to 9600
  5. Disable flow control
  6. Set RTS low
  7. Set DTR low
  8. Set DTR high
  9. Send 3 bytes: 0x0a 0x43 0x0d
  10. Receive 5 bytes: 0x00 0xa 0x44 0x2c 0xd
  11. Set DTR low
  12. Set baud to new value (0x15 in control message)
  13. Send 1 byte: 0x40
  14. Receive 1 byte: 0x41

Once this set of commands has been run and the send/receives match what is listed above, we can continue with loading the firmware. The actual firmware loading simply consists of sending 128 byte blocks of the firmware to the device, and receiving back those blocks for error checking. This happens in the FalconFirmware::loadFirmware function.

Child classes of FalconComm implement the above code in their setFirmwareMode() function.

Once firmware is loaded, the falcon needs to be returned to normal mode in order to exchange useful data with the driver. To do this, we execute the following steps:

  1. Set the FTDI latency timer to 1ms
  2. Set the baud rate to the appropriate value (0x2 in control message)
  3. Clear send and receive buffers

After this, the falcon will be in normal communications mode, and regular I/O can begin. I/O specifics are defined in the firmware classes of libnifalcon.

While FalconComm is mainly geared toward making sure we can talk to the device, it can also be used for test purposes, like building network interfaces to emulate the falcon hardware.

Member Enumeration Documentation

anonymous enum
Enumerator
FALCON_COMM_DEVICE_ERROR 

Device driver specific error, check getDeviceErrorCode

FALCON_COMM_NOT_INITIALIZED 

Device drivers not initialized

FALCON_COMM_DEVICE_NOT_FOUND_ERROR 

No devices found on the system

FALCON_COMM_DEVICE_NOT_VALID_ERROR 

Device not opened

FALCON_COMM_DEVICE_INDEX_OUT_OF_RANGE_ERROR 

Device index for opening out of range of available devices

FALCON_COMM_FIRMWARE_NOT_FOUND_ERROR 

Firmware file not found

FALCON_COMM_WRITE_ERROR 

Write timeout hit, underflow, etc...

FALCON_COMM_READ_ERROR 

Read timeout hit, underflow, etc...

Constructor & Destructor Documentation

libnifalcon::FalconComm::FalconComm ( )
inline

Constructor

virtual libnifalcon::FalconComm::~FalconComm ( )
inlinevirtual

Destructor

Member Function Documentation

virtual bool libnifalcon::FalconComm::close ( )
pure virtual

Closes the device, if open

Returns
True if device is closed successfully, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

unsigned int libnifalcon::FalconComm::getBytesAvailable ( )
inline

Returns the number of bytes available to read (buffered from object)

Returns
Number of bytes available to read
virtual bool libnifalcon::FalconComm::getDeviceCount ( unsigned int &  count)
pure virtual

Returns the number of devices connected to the system

Parameters
[out]countThe number of devices available
Returns
True if count was retreived correctly, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

int libnifalcon::FalconComm::getDeviceErrorCode ( )
inline

Returns the device specific error code for in-depth debugging

Returns
Index for the communication policy specific error code
int libnifalcon::FalconComm::getLastBytesRead ( )
inline

Returns the number of bytes returned in the last read function

Returns
Number of bytes read
int libnifalcon::FalconComm::getLastBytesWritten ( )
inline

Returns the number of bytes returned in the last write function

Returns
Number of bytes written
bool libnifalcon::FalconComm::hasBytesAvailable ( )
inline

Checks to see whether there are bytes available to read from the object

Returns
True if comm object has bytes available to read
bool libnifalcon::FalconComm::isCommOpen ( )
inline

Returns whether the device is open or not

Returns
True if open, false otherwise
virtual bool libnifalcon::FalconComm::open ( unsigned int  index)
pure virtual

Opens the device at the specified index

Parameters
[in]indexIndex of the device to open
Returns
True if device is opened successfully, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

virtual void libnifalcon::FalconComm::poll ( )
inlinevirtual

Polls the object for confirmation of write/read return

Reimplemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

virtual bool libnifalcon::FalconComm::read ( uint8_t *  str,
unsigned int  size 
)
pure virtual

Read a specified number of bytes from the device

Parameters
[out]strBuffer to read data into
[in]sizeAmount of bytes to read
Returns
True if (size) amount of bytes is read successfully, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

virtual bool libnifalcon::FalconComm::readBlocking ( uint8_t *  str,
unsigned int  size 
)
pure virtual

Read a specified number of bytes from the device

Parameters
[out]strBuffer to read data into
[in]sizeAmount of bytes to read
Returns
True if (size) amount of bytes is read successfully, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

virtual void libnifalcon::FalconComm::reset ( )
inlinevirtual

Reset the internal state of the communications object (bytes read/written, etc...)

Reimplemented in libnifalcon::FalconCommLibUSB.

virtual void libnifalcon::FalconComm::setBytesAvailable ( unsigned int  b)
inlinevirtual

Sets the number of bytes that are ready for reading

Returns
Number of bytes available to read
virtual bool libnifalcon::FalconComm::setFirmwareMode ( )
pure virtual

Sets the communications mode and initializes the device to load firmware

Returns
True if device is successfully set to load firwmare, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

virtual bool libnifalcon::FalconComm::setNormalMode ( )
pure virtual

Sets the communications mode and initializes the device to run in normal operation

Returns
True if device is successfully set to normal operation, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

virtual bool libnifalcon::FalconComm::write ( uint8_t *  str,
unsigned int  size 
)
pure virtual

Write a specified number of bytes to the device

Parameters
[in]strBuffer to write data from
[in]sizeAmount of bytes to write
Returns
True if (size) amount of bytes is written successfully, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

virtual bool libnifalcon::FalconComm::writeBlocking ( uint8_t *  str,
unsigned int  size 
)
pure virtual

Write a specified number of bytes to the device

Parameters
[in]strBuffer to write data from
[in]sizeAmount of bytes to write
Returns
True if (size) amount of bytes is written successfully, false otherwise. Error code set if false.

Implemented in libnifalcon::FalconCommLibUSB, and libnifalcon::FalconCommFTD2XX.

Member Data Documentation

const unsigned int libnifalcon::FalconComm::FALCON_PRODUCT_ID = 0xCB48
staticprotected

USB Product ID from the Falcon

const unsigned int libnifalcon::FalconComm::FALCON_VENDOR_ID = 0x0403
staticprotected

USB Vendor ID for the Falcon

int libnifalcon::FalconComm::m_bytesAvailable
protected

Number of bytes object has available to read

int libnifalcon::FalconComm::m_deviceErrorCode
protected

Communications policy specific error code

bool libnifalcon::FalconComm::m_hasBytesAvailable
protected

Whether or not the object has bytes available to read

bool libnifalcon::FalconComm::m_isCommOpen
protected

Whether or not the communications are open

int libnifalcon::FalconComm::m_lastBytesRead
protected

Number of bytes read in last read operation

int libnifalcon::FalconComm::m_lastBytesWritten
protected

Number of bytes written in the last write operation

const unsigned int libnifalcon::FalconComm::MAX_DEVICES = 128
staticprotected

Maximum number of devices to store in count buffers


The documentation for this class was generated from the following file: