Leosac  0.8.0
Open Source Access Control
WiegandConfig.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2017 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #define ODB_NO_BASE_VERSION
23 #include "hardware/Buzzer.hpp"
24 #include "hardware/GPIO.hpp"
25 #include "hardware/HardwareFwd.hpp"
26 #include "hardware/LED.hpp"
27 #include "hardware/RFIDReader.hpp"
29 #include "tools/db/database.hpp"
30 #include <chrono>
31 
32 #pragma db model version(1, 1, open)
33 
34 namespace Leosac
35 {
36 namespace Module
37 {
38 namespace Wiegand
39 {
40 
45 #pragma db object callback(validation_callback) table("HARDWARE_RFIDReader_Wiegand")
47 {
49  : mode("SIMPLE_WIEGAND")
50  , pin_timeout(2500)
51  , pin_key_end('#')
52  , nowait(0){};
53 
54  WiegandReaderConfig(const WiegandReaderConfig &) = default;
55 
59  template <typename DevicePtrT>
60  std::string device_name(const DevicePtrT &dev) const
61  {
62  if (dev)
63  return dev->name();
64  return "";
65  }
66 
67  std::string gpio_high_name() const
68  {
69  return device_name(gpio_high_);
70  }
71 
72  std::string gpio_low_name() const
73  {
74  return device_name(gpio_low_);
75  }
76 
77  std::string green_led_name() const
78  {
79  return device_name(green_led_);
80  }
81 
82  std::string buzzer_name() const
83  {
84  return device_name(buzzer_);
85  }
86 
90  void validation_callback(odb::callback_event, odb::database &) const;
91 
96  std::string mode;
97 
98  std::chrono::milliseconds pin_timeout;
100  bool nowait;
101 
105  constexpr static std::array<const char *const, 8> valid_operation_modes{
106  "SIMPLE_WIEGAND",
107  "WIEGAND_PIN_4BITS",
108  "WIEGAND_PIN_8BITS",
109  "WIEGAND_PIN_BUFFERED",
110  "WIEGAND_CARD_PIN_4BITS",
111  "WIEGAND_CARD_PIN_8BITS",
112  "WIEGAND_CARD_PIN_BUFFERED",
113  "AUTODETECT"};
114 };
115 
124 {
125  public:
126  WiegandConfig() = default;
127 
129  const std::vector<WiegandReaderConfigPtr> &readers() const;
130 
131  private:
132  std::vector<WiegandReaderConfigPtr> readers_;
133 };
134 }
135 }
136 }
137 
138 #ifdef ODB_COMPILER
139 #include "hardware/Buzzer.hpp"
140 #include "hardware/GPIO.hpp"
141 #include "hardware/LED.hpp"
142 #endif
Leosac::Module::Wiegand::WiegandReaderConfig::WiegandReaderConfig
WiegandReaderConfig()
Definition: WiegandConfig.hpp:48
Leosac::Module::Wiegand::WiegandReaderConfig::gpio_low_
Hardware::GPIOPtr gpio_low_
Definition: WiegandConfig.hpp:93
Leosac::Module::Wiegand::WiegandReaderConfig::buzzer_name
std::string buzzer_name() const
Definition: WiegandConfig.hpp:82
Leosac::Hardware::GPIOPtr
std::shared_ptr< GPIO > GPIOPtr
Definition: HardwareFwd.hpp:58
Leosac::Module::Wiegand::WiegandReaderConfig::buzzer_
Hardware::BuzzerPtr buzzer_
Definition: WiegandConfig.hpp:95
database.hpp
Leosac::Hardware::LEDPtr
std::shared_ptr< LED > LEDPtr
Definition: HardwareFwd.hpp:61
Leosac::Module::Wiegand::WiegandReaderConfig::green_led_
Hardware::LEDPtr green_led_
Definition: WiegandConfig.hpp:94
WiegandFwd.hpp
Leosac::Module::Wiegand::WiegandConfig::add_reader
void add_reader(WiegandReaderConfigPtr)
Definition: WiegandConfig.cpp:33
Leosac::Module::Wiegand::WiegandReaderConfig::gpio_high_name
std::string gpio_high_name() const
Definition: WiegandConfig.hpp:67
Leosac::Module::Wiegand::WiegandConfig
Transient configuration object that stores the list of reader use/configure.
Definition: WiegandConfig.hpp:123
Leosac::Module::Wiegand::WiegandConfig::readers_
std::vector< WiegandReaderConfigPtr > readers_
Definition: WiegandConfig.hpp:132
Leosac::Module::Wiegand::WiegandConfig::WiegandConfig
WiegandConfig()=default
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::Wiegand::WiegandConfig::readers
const std::vector< WiegandReaderConfigPtr > & readers() const
Definition: WiegandConfig.cpp:38
Leosac::Module::Wiegand::WiegandReaderConfig::pin_timeout
std::chrono::milliseconds pin_timeout
Definition: WiegandConfig.hpp:98
Buzzer.hpp
GPIO.hpp
HardwareFwd.hpp
Leosac::Module::Wiegand::WiegandReaderConfig::validation_callback
void validation_callback(odb::callback_event, odb::database &) const
ODB callback wrt database operation.
Definition: WiegandConfig.cpp:43
LED.hpp
Leosac::Module::Wiegand::WiegandReaderConfig::mode
std::string mode
Definition: WiegandConfig.hpp:96
Leosac::Module::Wiegand::WiegandReaderConfig::nowait
bool nowait
Definition: WiegandConfig.hpp:100
Leosac::Module::Wiegand::WiegandReaderConfig::valid_operation_modes
constexpr static std::array< const char *const, 8 > valid_operation_modes
List of valid operation mode for a reader.
Definition: WiegandConfig.hpp:105
Leosac::Module::Wiegand::WiegandReaderConfig::gpio_low_name
std::string gpio_low_name() const
Definition: WiegandConfig.hpp:72
RFIDReader.hpp
Leosac::Module::Wiegand::WiegandReaderConfig::gpio_high_
Hardware::GPIOPtr gpio_high_
Definition: WiegandConfig.hpp:92
Leosac::Hardware::RFIDReader
Abstraction of a RFID Reader device.
Definition: RFIDReader.hpp:42
Leosac::Module::Wiegand::WiegandReaderConfigPtr
std::shared_ptr< WiegandReaderConfig > WiegandReaderConfigPtr
Definition: WiegandFwd.hpp:31
Leosac::Module::Wiegand::WiegandReaderConfig
An instance of this class represents the configuration of one Wiegand reader.
Definition: WiegandConfig.hpp:46
Leosac::Module::Wiegand::WiegandReaderConfig::pin_key_end
char pin_key_end
Definition: WiegandConfig.hpp:99
Leosac::Module::Wiegand::WiegandReaderConfig::device_name
std::string device_name(const DevicePtrT &dev) const
Returns the name of a device, or the empty string.
Definition: WiegandConfig.hpp:60
Leosac::Hardware::BuzzerPtr
std::shared_ptr< Buzzer > BuzzerPtr
Definition: HardwareFwd.hpp:64
Leosac::Module::Wiegand::WiegandReaderConfig::green_led_name
std::string green_led_name() const
Definition: WiegandConfig.hpp:77