AlarmNotifications::FlashLight Class Reference

Controller for USB relais of red alarm flash light. More...

#include <flashlight.h>

Collaboration diagram for AlarmNotifications::FlashLight:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ~FlashLight ()
 Destructor.
 FlashLight (const FlashLight &other)
 Copy constructor (deleted).
 FlashLight (FlashLight &&other)
 Move constructor (C++11, deleted).
FlashLightoperator= (const FlashLight &other)
 Copy assignment (deleted).
FlashLightoperator= (FlashLight &&other)
 Move assignment (C++11, deleted).

Static Public Member Functions

static FlashLightinstance () noexcept
 Get singleton instance.
static void switchOn () noexcept
 Switch on red alarm flash light.
static void switchOff () noexcept
 Switch off red alarm flash light.

Private Types

typedef std::vector< uint8_t > deviceCommand
 Type for storing commands to the device.

Private Member Functions

 FlashLight ()
 Constructor.
void switchInternal (const bool lightSwitch)
 Internal routine to switch relais on or off.
void openSerialInterface ()
 Open serial interface.
void configureSerialInterface ()
 Set options of serial interface for USB relais.
void writeSerialInteface (const deviceCommand command)
 Write command sequence to the USB relais.
void closeSerialInterface ()
 Close the device handle.

Static Private Member Functions

static deviceCommand createCommand (const bool lightSwitch)
 Assemble command sequence.

Private Attributes

const std::string _deviceNode
 Path to the device file.
boost::mutex _serialLineMutex
 Mutex to protect device access.
int _fd
 File descriptor.
bool _fdOpen
 File descriptor use flag.

Static Private Attributes

static const unsigned int deviceBaudRate = B9600
 Constant for baud rate.

Detailed Description

Controller for USB relais of red alarm flash light.

This class controls a USB relais of type "KMTronic USB One Relay". For communication with a PC, the USB relais uses the "FT232 USB-Serial (UART) IC". A standard Linux driver exists for this IC and it should appear as "/dev/ttyUSBn" with a non-negative integer n.

The communication protocol of the device is implemented in this class, although for now only writing to the bus is supported. As there is only one alarm flash light, this class is implemented as a singleton. The user just has to call the static methods switchOn() and switchOff(), everything else is done internally. The two switch functions will never throw exceptions, any occuring exception will be forwarded to the global ExceptionHandler().

Definition at line 55 of file flashlight.h.


Member Typedef Documentation

typedef std::vector<uint8_t> AlarmNotifications::FlashLight::deviceCommand [private]

Type for storing commands to the device.

The relais is controlled by sending a sequence of 8-bit characters over USB. Using a vector, these sequences can be handled quite easily.

Definition at line 62 of file flashlight.h.


Constructor & Destructor Documentation

FlashLight::FlashLight (  )  [private]

Constructor.

Queries the location of the device file from AlarmConfiguration, but does not create a handle. This is only done when needed in openSerialInterface().

Definition at line 51 of file flashlight.cpp.

FlashLight::~FlashLight (  ) 

Destructor.

If the _fdOpen flag is set, closeSerialInterface() is invoked.

Definition at line 58 of file flashlight.cpp.

AlarmNotifications::FlashLight::FlashLight ( const FlashLight other  ) 

Copy constructor (deleted).

This class cannot be copied.

Parameters:
other Another instance of FlashLight
AlarmNotifications::FlashLight::FlashLight ( FlashLight &&  other  ) 

Move constructor (C++11, deleted).

This class cannot be moved.

Parameters:
other Another instance of FlashLight

Member Function Documentation

void FlashLight::closeSerialInterface (  )  [private]

Close the device handle.

The device handle is closed and destroyed, _fdOpen is reset to false. Errors occuring during close, e.g. because the USB device has been removed while using it, are silently ignored.

Returns:
Nothing

Definition at line 212 of file flashlight.cpp.

void FlashLight::configureSerialInterface (  )  [private]

Set options of serial interface for USB relais.

This method sets the required flags in the termios structure for the serial device and applies these settings.

Returns:
Nothing
Exceptions:
std::logic_error The serial interface has not been opened.
std::runtime_error The device settings couldn't be applied.

Definition at line 128 of file flashlight.cpp.

FlashLight::deviceCommand FlashLight::createCommand ( const bool  lightSwitch  )  [static, private]

Assemble command sequence.

This method implements the communication protocol of the USB relais and returns a command sequence according to the requested switch action.

Parameters:
lightSwitch True if the relais should be switched on, false if it should be switched off
Returns:
Command sequence to be forwarded to writeSerialInteface()

Definition at line 105 of file flashlight.cpp.

FlashLight & FlashLight::instance (  )  [static]

Get singleton instance.

This returns a reference (not a pointer) to the singleton instance. On the first invocation, the singleton instance is created. Please note that this will not create a handle on the device node - it is only allocated while it is really in use.

Returns:
Reference to singleton instance

Definition at line 44 of file flashlight.cpp.

void FlashLight::openSerialInterface (  )  [private]

Open serial interface.

Tries to create a handle for the device file _deviceNode and stores the file descriptor in _fd.

Returns:
Nothing
Exceptions:
std::runtime_error The device node could not be opened.

Definition at line 120 of file flashlight.cpp.

FlashLight& AlarmNotifications::FlashLight::operator= ( FlashLight &&  other  ) 

Move assignment (C++11, deleted).

This class cannot be moved.

Parameters:
other Another instance of FlashLight
Returns:
Nothing (deleted)
FlashLight& AlarmNotifications::FlashLight::operator= ( const FlashLight other  ) 

Copy assignment (deleted).

This class cannot be copied.

Parameters:
other Another instance of FlashLight
Returns:
Nothing (deleted)
void FlashLight::switchInternal ( const bool  lightSwitch  )  [private]

Internal routine to switch relais on or off.

This instance method is called by switchOn() and switchOff() to do the actual work.

Parameters:
lightSwitch True if the relais should be switched on, false if it should be switched off
Returns:
Nothing

Definition at line 94 of file flashlight.cpp.

void FlashLight::switchOff (  )  [static]

Switch off red alarm flash light.

This will order the USB relais to switch off the alarm light.

This method cannot throw exceptions.

Returns:
Nothing

Definition at line 79 of file flashlight.cpp.

void FlashLight::switchOn (  )  [static]

Switch on red alarm flash light.

This will order the USB relais to switch on the alarm light.

This method cannot throw exceptions.

Returns:
Nothing

Definition at line 64 of file flashlight.cpp.

void FlashLight::writeSerialInteface ( const deviceCommand  command  )  [private]

Write command sequence to the USB relais.

The command sequence is transfered into a local buffer that can be fed into the write() system call.

Parameters:
command Command sequence to be written to the bus
Returns:
Nothing
Exceptions:
std::logic_error The serial interface has not been opened.
std::runtime_error An error occured while writing to the device.
std::bad_alloc There is not enough memory available to transfer the command to a local buffer.

Definition at line 175 of file flashlight.cpp.


Member Data Documentation

const std::string AlarmNotifications::FlashLight::_deviceNode [private]

Path to the device file.

Path to the file representing the access to the FT232 UART IC. It should appear under Linux as "/dev/ttyUSBn" with a non-negative integer n.

Definition at line 69 of file flashlight.h.

File descriptor.

The file descriptor index as returned by the open() system call.

Definition at line 81 of file flashlight.h.

File descriptor use flag.

Set by openSerialInterface() when a handle on the device could be achieved and reset by closeSerialInterface() when the file handle is released.

Definition at line 87 of file flashlight.h.

Mutex to protect device access.

The serial interface can only be accessed by one thread at a time, so for safety this mutex is used to exclude concurrent access.

Definition at line 75 of file flashlight.h.

const unsigned int AlarmNotifications::FlashLight::deviceBaudRate = B9600 [static, private]

Constant for baud rate.

The baud rate of the virtual serial interface emulated by USB, to be used in configureSerialInterface().

Definition at line 93 of file flashlight.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 2 Dec 2014 for AlarmNotifications by  doxygen 1.6.1