#include <FalconComm.h>
Inherits libnifalcon::FalconCore.
Inherited by libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
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 () |
Protected Attributes | |
int | m_deviceErrorCode |
int | m_lastBytesRead |
int | m_lastBytesWritten |
bool | m_isCommOpen |
bool | m_hasBytesAvailable |
int | m_bytesAvailable |
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 |
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:
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:
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.
anonymous enum |
libnifalcon::FalconComm::FalconComm | ( | ) | [inline] |
Constructor
virtual libnifalcon::FalconComm::~FalconComm | ( | ) | [inline, virtual] |
Destructor
virtual bool libnifalcon::FalconComm::close | ( | ) | [pure virtual] |
Closes the device, if open
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
unsigned int libnifalcon::FalconComm::getBytesAvailable | ( | ) | [inline] |
Returns the number of bytes available to read (buffered from object)
virtual bool libnifalcon::FalconComm::getDeviceCount | ( | unsigned int & | count | ) | [pure virtual] |
Returns the number of devices connected to the system
[out] | count | The number of devices available |
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
int libnifalcon::FalconComm::getDeviceErrorCode | ( | ) | [inline] |
Returns the device specific error code for in-depth debugging
int libnifalcon::FalconComm::getLastBytesRead | ( | ) | [inline] |
Returns the number of bytes returned in the last read function
int libnifalcon::FalconComm::getLastBytesWritten | ( | ) | [inline] |
Returns the number of bytes returned in the last write function
bool libnifalcon::FalconComm::hasBytesAvailable | ( | ) | [inline] |
Checks to see whether there are bytes available to read from the object
bool libnifalcon::FalconComm::isCommOpen | ( | ) | [inline] |
Returns whether the device is open or not
virtual bool libnifalcon::FalconComm::open | ( | unsigned int | index | ) | [pure virtual] |
Opens the device at the specified index
[in] | index | Index of the device to open |
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
virtual void libnifalcon::FalconComm::poll | ( | ) | [inline, virtual] |
Polls the object for confirmation of write/read return
Reimplemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
virtual bool libnifalcon::FalconComm::read | ( | uint8_t * | str, | |
unsigned int | size | |||
) | [pure virtual] |
Read a specified number of bytes from the device
[out] | str | Buffer to read data into |
[in] | size | Amount of bytes to read |
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
virtual bool libnifalcon::FalconComm::readBlocking | ( | uint8_t * | str, | |
unsigned int | size | |||
) | [pure virtual] |
Read a specified number of bytes from the device
[out] | str | Buffer to read data into |
[in] | size | Amount of bytes to read |
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
virtual void libnifalcon::FalconComm::reset | ( | ) | [inline, virtual] |
Reset the internal state of the communications object (bytes read/written, etc...)
Reimplemented in libnifalcon::FalconCommLibUSB.
virtual void libnifalcon::FalconComm::setBytesAvailable | ( | unsigned int | b | ) | [inline, virtual] |
Sets the number of bytes that are ready for reading
virtual bool libnifalcon::FalconComm::setFirmwareMode | ( | ) | [pure virtual] |
Sets the communications mode and initializes the device to load firmware
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
virtual bool libnifalcon::FalconComm::setNormalMode | ( | ) | [pure virtual] |
Sets the communications mode and initializes the device to run in normal operation
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
virtual bool libnifalcon::FalconComm::write | ( | uint8_t * | str, | |
unsigned int | size | |||
) | [pure virtual] |
Write a specified number of bytes to the device
[in] | str | Buffer to write data from |
[in] | size | Amount of bytes to write |
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
virtual bool libnifalcon::FalconComm::writeBlocking | ( | uint8_t * | str, | |
unsigned int | size | |||
) | [pure virtual] |
Write a specified number of bytes to the device
[in] | str | Buffer to write data from |
[in] | size | Amount of bytes to write |
Implemented in libnifalcon::FalconCommFTD2XX, and libnifalcon::FalconCommLibUSB.
const unsigned int libnifalcon::FalconComm::FALCON_PRODUCT_ID = 0xCB48 [static, protected] |
USB Product ID from the Falcon
const unsigned int libnifalcon::FalconComm::FALCON_VENDOR_ID = 0x0403 [static, protected] |
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 [static, protected] |
Maximum number of devices to store in count buffers