Leosac  0.8.0
Open Source Access Control
FWiegandReader.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 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 #include "FWiegandReader.hpp"
21 
22 using namespace Leosac::Hardware;
23 
24 FWiegandReader::FWiegandReader(zmqpp::context &ctx, std::string const &reader_name)
25  : backend_(ctx, zmqpp::socket_type::req)
26  , name_(reader_name)
27 {
28  backend_.connect("inproc://" + reader_name);
29 }
30 
32 {
33  zmqpp::message msg;
34  msg << "GREEN_LED"
35  << "ON";
36 
37  return send_to_backend(msg);
38 }
39 
41 {
42  zmqpp::message msg;
43  msg << "GREEN_LED"
44  << "OFF";
45 
46  return send_to_backend(msg);
47 }
48 
49 bool FWiegandReader::greenLedBlink(int64_t duration, int64_t speed)
50 {
51  zmqpp::message msg;
52  msg << "GREEN_LED"
53  << "BLINK" << duration << speed;
54 
55  return send_to_backend(msg);
56 }
57 
58 bool FWiegandReader::send_to_backend(zmqpp::message &msg)
59 {
60  std::string rep;
61  backend_.send(msg);
62  backend_.receive(rep);
63 
64  assert(rep == "OK" || rep == "KO");
65  if (rep == "OK")
66  return true;
67  return false;
68 }
69 
70 bool FWiegandReader::beep(int64_t duration)
71 {
72  zmqpp::message msg;
73  msg << "BEEP" << duration;
74 
75  return send_to_backend(msg);
76 }
77 
79 {
80  zmqpp::message msg;
81  msg << "BEEP_ON";
82 
83  return send_to_backend(msg);
84 }
85 
87 {
88  zmqpp::message msg;
89  msg << "BEEP_OFF";
90 
91  return send_to_backend(msg);
92 }
93 
94 const std::string &FWiegandReader::name() const
95 {
96  return name_;
97 }
Leosac::Hardware::FWiegandReader::backend_
zmqpp::socket backend_
A socket to talk to the backend wiegand reader.
Definition: FWiegandReader.hpp:99
zmqpp
Definition: CoreUtils.hpp:27
Leosac::Hardware::FWiegandReader::name
const std::string & name() const
Returns the device's name.
Definition: FWiegandReader.cpp:94
Leosac::Hardware::FWiegandReader::send_to_backend
bool send_to_backend(zmqpp::message &m)
Send a message to the backend_ wiegand reader and wait for a response.
Definition: FWiegandReader.cpp:58
Leosac::Hardware::FWiegandReader::beep
bool beep(int64_t duration=1000)
Beep for a given duration.
Definition: FWiegandReader.cpp:70
Leosac::Hardware::FWiegandReader::buzzerOn
bool buzzerOn()
Turn the buzzer on.
Definition: FWiegandReader.cpp:78
Leosac::Hardware::FWiegandReader::buzzerOff
bool buzzerOff()
Turn the buzzer off.
Definition: FWiegandReader.cpp:86
Leosac::Hardware::FWiegandReader::name_
std::string name_
Definition: FWiegandReader.hpp:101
Leosac::Hardware::FWiegandReader::greenLedOff
bool greenLedOff()
Turn the reader's green led off.
Definition: FWiegandReader.cpp:40
Leosac::Hardware::FWiegandReader::FWiegandReader
FWiegandReader(zmqpp::context &ctx, const std::string &reader_name)
Construct a facade to a wiegand reader; this facade will connect to the reader.
Definition: FWiegandReader.cpp:24
Leosac::Hardware::FWiegandReader::greenLedOn
bool greenLedOn()
Turn the reader's green led on.
Definition: FWiegandReader.cpp:31
Leosac::Hardware::FWiegandReader::greenLedBlink
bool greenLedBlink(int64_t duration=1000, int64_t speed=300)
Make the reader's green led blink.
Definition: FWiegandReader.cpp:49
Leosac::Hardware
Provides facade classes to hardware device implementation.
Definition: Buzzer.cpp:25
FWiegandReader.hpp