Leosac  0.7.0
OpenSourceAccessControl
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 
53  WiegandReaderConfig(const WiegandReaderConfig &) = default;
54 
58  template <typename DevicePtrT>
59  std::string device_name(const DevicePtrT &dev) const
60  {
61  if (dev)
62  return dev->name();
63  return "";
64  }
65 
66  std::string gpio_high_name() const
67  {
68  return device_name(gpio_high_);
69  }
70 
71  std::string gpio_low_name() const
72  {
73  return device_name(gpio_low_);
74  }
75 
76  std::string green_led_name() const
77  {
78  return device_name(green_led_);
79  }
80 
81  std::string buzzer_name() const
82  {
83  return device_name(buzzer_);
84  }
85 
89  void validation_callback(odb::callback_event, odb::database &) const;
90 
95  std::string mode;
96 
97  std::chrono::milliseconds pin_timeout;
99 
103  constexpr static std::array<const char *const, 8> valid_operation_modes{
104  "SIMPLE_WIEGAND",
105  "WIEGAND_PIN_4BITS",
106  "WIEGAND_PIN_8BITS",
107  "WIEGAND_PIN_BUFFERED",
108  "WIEGAND_CARD_PIN_4BITS",
109  "WIEGAND_CARD_PIN_8BITS",
110  "WIEGAND_CARD_PIN_BUFFERED",
111  "AUTODETECT"};
112 };
113 
122 {
123  public:
124  WiegandConfig() = default;
125 
126  void add_reader(WiegandReaderConfigPtr);
127  const std::vector<WiegandReaderConfigPtr> &readers() const;
128 
129  private:
130  std::vector<WiegandReaderConfigPtr> readers_;
131 };
132 }
133 }
134 }
135 
136 #ifdef ODB_COMPILER
137 #include "hardware/Buzzer.hpp"
138 #include "hardware/GPIO.hpp"
139 #include "hardware/LED.hpp"
140 #endif
void validation_callback(odb::callback_event, odb::database &) const
ODB callback wrt database operation.
An instance of this class represents the configuration of one Wiegand reader.
std::shared_ptr< GPIO > GPIOPtr
Definition: HardwareFwd.hpp:55
This is the header file for a generated source file, GitSHA1.cpp.
std::shared_ptr< WiegandReaderConfig > WiegandReaderConfigPtr
Definition: WiegandFwd.hpp:33
std::string device_name(const DevicePtrT &dev) const
Returns the name of a device, or the empty string.
Abstraction of a RFID Reader device.
Definition: RFIDReader.hpp:42
std::shared_ptr< LED > LEDPtr
Definition: HardwareFwd.hpp:58
std::vector< WiegandReaderConfigPtr > readers_
Transient configuration object that stores the list of reader use/configure.
static constexpr std::array< const char *const, 8 > valid_operation_modes
List of valid operation mode for a reader.
std::shared_ptr< Buzzer > BuzzerPtr
Definition: HardwareFwd.hpp:61