AlarmNotifications
PANDA Slow Control Alarm Daemon
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
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]

Public Member Functions

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

Static Public Member Functions

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

Private Types

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

Private Member Functions

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

Static Private Member Functions

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

Private Attributes

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

Static Private Attributes

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

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)
delete

Copy constructor (deleted)

This class cannot be copied.

Parameters
otherAnother instance of FlashLight
AlarmNotifications::FlashLight::FlashLight ( FlashLight &&  other)
delete

Move constructor (C++11, deleted)

This class cannot be moved.

Parameters
otherAnother 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_errorThe serial interface has not been opened.
std::runtime_errorThe device settings couldn't be applied.

Definition at line 128 of file flashlight.cpp.

FlashLight::deviceCommand FlashLight::createCommand ( const bool  lightSwitch)
staticprivate

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
lightSwitchTrue 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 ( )
staticnoexcept

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_errorThe device node could not be opened.

Definition at line 120 of file flashlight.cpp.

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

Copy assignment (deleted)

This class cannot be copied.

Parameters
otherAnother instance of FlashLight
Returns
Nothing (deleted)
FlashLight& AlarmNotifications::FlashLight::operator= ( FlashLight &&  other)
delete

Move assignment (C++11, deleted)

This class cannot be moved.

Parameters
otherAnother 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
lightSwitchTrue 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 ( )
staticnoexcept

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 ( )
staticnoexcept

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
commandCommand sequence to be written to the bus
Returns
Nothing
Exceptions
std::logic_errorThe serial interface has not been opened.
std::runtime_errorAn error occured while writing to the device.
std::bad_allocThere 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.

int AlarmNotifications::FlashLight::_fd
private

File descriptor.

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

Definition at line 81 of file flashlight.h.

bool AlarmNotifications::FlashLight::_fdOpen
private

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.

boost::mutex AlarmNotifications::FlashLight::_serialLineMutex
private

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
staticprivate

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: