![]() |
AlarmNotifications
PANDA Slow Control Alarm Daemon
|
Controller for USB relais of red alarm flash light. More...
#include <flashlight.h>
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... | |
FlashLight & | operator= (const FlashLight &other)=delete |
Copy assignment (deleted) More... | |
FlashLight & | operator= (FlashLight &&other)=delete |
Move assignment (C++11, deleted) More... | |
Static Public Member Functions | |
static FlashLight & | instance () 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... | |
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.
|
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.
|
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.
|
delete |
Copy constructor (deleted)
This class cannot be copied.
other | Another instance of FlashLight |
|
delete |
Move constructor (C++11, deleted)
This class cannot be moved.
other | Another instance of FlashLight |
|
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.
Definition at line 212 of file flashlight.cpp.
|
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.
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.
|
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.
lightSwitch | True if the relais should be switched on, false if it should be switched off |
Definition at line 105 of file flashlight.cpp.
|
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.
Definition at line 44 of file flashlight.cpp.
|
private |
Open serial interface.
Tries to create a handle for the device file _deviceNode and stores the file descriptor in _fd.
std::runtime_error | The device node could not be opened. |
Definition at line 120 of file flashlight.cpp.
|
delete |
Copy assignment (deleted)
This class cannot be copied.
other | Another instance of FlashLight |
|
delete |
Move assignment (C++11, deleted)
This class cannot be moved.
other | Another instance of FlashLight |
|
private |
Internal routine to switch relais on or off.
This instance method is called by switchOn() and switchOff() to do the actual work.
lightSwitch | True if the relais should be switched on, false if it should be switched off |
Definition at line 94 of file flashlight.cpp.
|
staticnoexcept |
Switch off red alarm flash light.
This will order the USB relais to switch off the alarm light.
This method cannot throw exceptions.
Definition at line 79 of file flashlight.cpp.
|
staticnoexcept |
Switch on red alarm flash light.
This will order the USB relais to switch on the alarm light.
This method cannot throw exceptions.
Definition at line 64 of file flashlight.cpp.
|
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.
command | Command sequence to be written to the bus |
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.
|
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.
|
private |
File descriptor.
The file descriptor index as returned by the open() system call.
Definition at line 81 of file flashlight.h.
|
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.
|
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.
|
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.