TwiceAsNice  2019-02-18
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
MGenDevice Class Reference

#include <mgen_device.h>

Collaboration diagram for MGenDevice:
Collaboration graph

Public Member Functions

bool lock ()
 
void unlock ()
 
void enable ()
 Enabling the device for use. More...
 
void disable ()
 Disabling the device from use. More...
 
int write (IOBuffer const &)
 Writing the query field of a command to the device. More...
 
int read (IOBuffer &)
 Reading the answer part of a command from the device. More...
 
int TurnPowerOn ()
 Turning the device on. More...
 
IOMode getOpMode () const
 Returning the current operational mode the device is in. More...
 
int setOpMode (IOMode)
 Setting the current operational mode of the device. More...
 
 MGenDevice ()
 
virtual ~MGenDevice ()
 
int Connect (unsigned short vid=0, unsigned short pid=0)
 Connecting a device identified by VID:PID. More...
 
bool isConnected () const
 

Static Public Member Functions

static char constDBG_OpModeString (IOMode)
 

Protected Attributes

pthread_mutex_t _lock
 
struct ftdi_context * ftdi
 
bool is_device_connected
 
bool tried_turn_on
 
IOMode mode
 
unsigned short vid
 
unsigned short pid
 

Constructor & Destructor Documentation

◆ MGenDevice()

MGenDevice::MGenDevice ( )

◆ ~MGenDevice()

MGenDevice::~MGenDevice ( )
virtual

Member Function Documentation

◆ Connect()

int MGenDevice::Connect ( unsigned short  vid = 0,
unsigned short  pid = 0 
)

Connecting a device identified by VID:PID.

This function only connects to the FTDI device.

Parameters
vidis the Vendor identifier of the device to connect (0x0403 for instance).
pidis the Product identifier of the device to connect (0x6001 for instance).
Returns
0 if successful
the return code of the last ftdi failure, and disable() is called.
Note
PID:VID=0:0 is used as default to connect to the first available FTDI device.
If PID:VID connection is not successful, enumerates and log devices to debug output.

◆ DBG_OpModeString()

char const * MGenDevice::DBG_OpModeString ( IOMode  mode)
static

◆ disable()

void MGenDevice::disable ( )

Disabling the device from use.

This function thread-safely marks the device as disconnected and deletes its FTDI context.

◆ enable()

void MGenDevice::enable ( )

Enabling the device for use.

This function thread-safely marks the device as connected.

Warning
This function does not run a connection, use Connect() for this purpose.

◆ getOpMode()

IOMode MGenDevice::getOpMode ( ) const
inline

Returning the current operational mode the device is in.

Returns
the IOMode the device was set to by setOpMode().

◆ isConnected()

bool MGenDevice::isConnected ( ) const
inline

◆ lock()

bool MGenDevice::lock ( )

◆ read()

int MGenDevice::read ( IOBuffer answer)

Reading the answer part of a command from the device.

Returns
the number of bytes read, or -1 if the command is invalid or device is not accessible.
Exceptions
IOErrorwhen device communication is malfunctioning.

◆ setOpMode()

int MGenDevice::setOpMode ( IOMode  _mode)

Setting the current operational mode of the device.

This function thread-safely updates the operational mode, and switch the device line to the adequate baudrate.

Returns
0 if successful, else a FTDI failure code.

◆ TurnPowerOn()

int MGenDevice::TurnPowerOn ( )

Turning the device on.

This function uses the FTDI special functions to obtain the same functionality as a long press on ESC to turn the M-Gen device on.

Note
Switches operational mode to UNKNOWN if successful.

◆ unlock()

void MGenDevice::unlock ( )

◆ write()

int MGenDevice::write ( IOBuffer const query)

Writing the query field of a command to the device.

Returns
the number of bytes written, or -1 if the command is invalid or device is not accessible.
Exceptions
IOErrorwhen device communication is malfunctioning.

Member Data Documentation

◆ _lock

pthread_mutex_t MGenDevice::_lock
protected

◆ ftdi

struct ftdi_context* MGenDevice::ftdi
protected

◆ is_device_connected

bool MGenDevice::is_device_connected
protected

◆ mode

IOMode MGenDevice::mode
protected

◆ pid

unsigned short MGenDevice::pid
protected

◆ tried_turn_on

bool MGenDevice::tried_turn_on
protected

◆ vid

unsigned short MGenDevice::vid
protected

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