AlarmNotifications
PANDA Slow Control Alarm Daemon
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
flashlight.h
Go to the documentation of this file.
1 
34 #ifndef FLASHLIGHT_H
35 #define FLASHLIGHT_H
36 
37 #include "oldgcccompat.h" // Compatibilty macros for GCC < 4.7
38 
39 #include <string>
40 #include <termios.h>
41 #include <vector>
42 
43 #include <boost/thread.hpp>
44 
45 namespace AlarmNotifications
46 {
47 
56 {
62  typedef std::vector<uint8_t> deviceCommand ;
63 private:
69  const std::string _deviceNode;
75  boost::mutex _serialLineMutex;
81  int _fd;
87  bool _fdOpen;
93  static const unsigned int deviceBaudRate = B9600; // Taken from the manual of the USB relais
94 
100  FlashLight();
108  void switchInternal ( const bool lightSwitch );
116  static deviceCommand createCommand ( const bool lightSwitch );
124  void openSerialInterface();
144  void writeSerialInteface ( const deviceCommand command );
151  void closeSerialInterface();
152 public:
159  static FlashLight& instance() noexcept;
165  ~FlashLight();
174  static void switchOn() noexcept;
183  static void switchOff() noexcept;
190  FlashLight ( const FlashLight& other ) = delete;
197  FlashLight ( FlashLight&& other ) = delete;
205  FlashLight& operator= ( const FlashLight& other ) = delete;
213  FlashLight& operator= ( FlashLight&& other ) = delete;
214 };
215 
216 }
217 
218 #endif // FLASHLIGHT_H
void configureSerialInterface()
Set options of serial interface for USB relais.
Definition: flashlight.cpp:128
int _fd
File descriptor.
Definition: flashlight.h:81
void switchInternal(const bool lightSwitch)
Internal routine to switch relais on or off.
Definition: flashlight.cpp:94
static void switchOff() noexcept
Switch off red alarm flash light.
Definition: flashlight.cpp:79
Compatibility macros for older versions of the GCC.
boost::mutex _serialLineMutex
Mutex to protect device access.
Definition: flashlight.h:75
const std::string _deviceNode
Path to the device file.
Definition: flashlight.h:69
static const unsigned int deviceBaudRate
Constant for baud rate.
Definition: flashlight.h:93
static void switchOn() noexcept
Switch on red alarm flash light.
Definition: flashlight.cpp:64
void closeSerialInterface()
Close the device handle.
Definition: flashlight.cpp:212
std::vector< uint8_t > deviceCommand
Type for storing commands to the device.
Definition: flashlight.h:62
Namespace for Alarm Notifications application.
void writeSerialInteface(const deviceCommand command)
Write command sequence to the USB relais.
Definition: flashlight.cpp:175
bool _fdOpen
File descriptor use flag.
Definition: flashlight.h:87
#define noexcept
Allow using the noexcept keyword with GCC < 4.6.
Definition: oldgcccompat.h:52
void openSerialInterface()
Open serial interface.
Definition: flashlight.cpp:120
static deviceCommand createCommand(const bool lightSwitch)
Assemble command sequence.
Definition: flashlight.cpp:105
static FlashLight & instance() noexcept
Get singleton instance.
Definition: flashlight.cpp:44
Controller for USB relais of red alarm flash light.
Definition: flashlight.h:55