libnifalcon  1.0.1
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | List of all members
libnifalcon::FalconCommLibUSB Class Reference

#include <FalconCommLibUSB.h>

+ Inheritance diagram for libnifalcon::FalconCommLibUSB:
+ Collaboration diagram for libnifalcon::FalconCommLibUSB:

Public Member Functions

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

Static Public Member Functions

static void cb_in (struct libusb_transfer *transfer)
 
static void cb_out (struct libusb_transfer *transfer)
 

Protected Attributes

bool m_isWriteAllocated
 
bool m_isReadAllocated
 
struct timeval * m_tv
 
libusb_device_handle * m_falconDevice
 
unsigned char input [128]
 
unsigned char output [128]
 
struct libusb_transfer * in_transfer
 
struct libusb_transfer * out_transfer
 
struct libusb_context * m_usbContext
 
- Protected Attributes inherited from libnifalcon::FalconComm
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
 

Private Member Functions

 DECLARE_LOGGER ()
 

Additional Inherited Members

- Public Types inherited from libnifalcon::FalconComm
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
}
 
- Static Protected Attributes inherited from libnifalcon::FalconComm
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

FalconCommLibUSB is the libusb-1.0 implementation of the falcon communications core. This core is meant to be used on non-windows platforms, since it's open source (unlike ftd2xx) and seems to work well. Much of the code is a reimplementation of functions found in libftdi:

http://www.intra2net.com/en/developer/libftdi/

However, due to our need to access the falcon at as close to a sustained 1khz rate as possible, we needed to use a non-blocking communications layer.

FalconCommLibUSB is built directly into the libnifalcon core library, as is chosen for the user by default by the FalconDevice constructor, so it is usually not needed. However, it is left here for code compatibility for code that already used comm behavior setting, which was required before libnifalcon v1.0

Constructor & Destructor Documentation

libnifalcon::FalconCommLibUSB::FalconCommLibUSB ( )

Constructor

libnifalcon::FalconCommLibUSB::~FalconCommLibUSB ( )

Destructor

Member Function Documentation

void libnifalcon::FalconCommLibUSB::cb_in ( struct libusb_transfer *  transfer)
static

Callback for result of reading data

void libnifalcon::FalconCommLibUSB::cb_out ( struct libusb_transfer *  transfer)
static

Callback for result of writing data

bool libnifalcon::FalconCommLibUSB::close ( )
virtual

Closes the device, if open

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

Implements libnifalcon::FalconComm.

libnifalcon::FalconCommLibUSB::DECLARE_LOGGER ( )
private
bool libnifalcon::FalconCommLibUSB::getDeviceCount ( unsigned int &  count)
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.

Implements libnifalcon::FalconComm.

bool libnifalcon::FalconCommLibUSB::initLibUSB ( )

Initializes libusb core

Returns
True on successful initialization, false otherwise
void libnifalcon::FalconCommLibUSB::issueRead ( )

Causes a read to be queued

bool libnifalcon::FalconCommLibUSB::open ( unsigned int  index)
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.

Implements libnifalcon::FalconComm.

void libnifalcon::FalconCommLibUSB::poll ( )
virtual

Polls the object for confirmation of write/read return

Reimplemented from libnifalcon::FalconComm.

bool libnifalcon::FalconCommLibUSB::read ( uint8_t *  str,
unsigned int  size 
)
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.

Implements libnifalcon::FalconComm.

bool libnifalcon::FalconCommLibUSB::readBlocking ( uint8_t *  str,
unsigned int  size 
)
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.

Implements libnifalcon::FalconComm.

void libnifalcon::FalconCommLibUSB::reset ( )
virtual

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

Reimplemented from libnifalcon::FalconComm.

void libnifalcon::FalconCommLibUSB::setBytesAvailable ( uint32_t  b)
virtual

Sets the number of bytes that are ready for reading

Returns
Number of bytes available to read
bool libnifalcon::FalconCommLibUSB::setFirmwareMode ( )
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.

Implements libnifalcon::FalconComm.

void libnifalcon::FalconCommLibUSB::setHasBytesAvailable ( bool  v)

Mutator function needed by static callbacks for class updates

bool libnifalcon::FalconCommLibUSB::setNormalMode ( )
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.

Implements libnifalcon::FalconComm.

void libnifalcon::FalconCommLibUSB::setReceived ( )
inline

Mutator function needed by static callbacks for class updates

void libnifalcon::FalconCommLibUSB::setSent ( )
inline

Mutator function needed by static callbacks for class updates

bool libnifalcon::FalconCommLibUSB::write ( uint8_t *  str,
unsigned int  size 
)
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.

Implements libnifalcon::FalconComm.

bool libnifalcon::FalconCommLibUSB::writeBlocking ( uint8_t *  str,
unsigned int  size 
)
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.

Implements libnifalcon::FalconComm.

Member Data Documentation

struct libusb_transfer* libnifalcon::FalconCommLibUSB::in_transfer
protected

Transfer for reading

unsigned char libnifalcon::FalconCommLibUSB::input[128]
protected

Buffers for I/O

libusb_device_handle* libnifalcon::FalconCommLibUSB::m_falconDevice
protected

libusb device handle struct

bool libnifalcon::FalconCommLibUSB::m_isReadAllocated
protected

True if we currently have a read queued

bool libnifalcon::FalconCommLibUSB::m_isWriteAllocated
protected

True if we currently have a write queued

struct timeval* libnifalcon::FalconCommLibUSB::m_tv
protected

Used for setting timeouts

struct libusb_context* libnifalcon::FalconCommLibUSB::m_usbContext
protected

Transfer for control messages

struct libusb_transfer* libnifalcon::FalconCommLibUSB::out_transfer
protected

Transfer for writing

unsigned char libnifalcon::FalconCommLibUSB::output[128]
protected

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