32 const boost::property_tree::ptree &cfg,
35 , kernel_sock_(ctx,
zmqpp::socket_type::req)
36 , sub_(ctx,
zmqpp::socket_type::sub)
38 , test_buzzer_(nullptr)
42 sub_.connect(
"inproc://zmq-bus-pub");
53 boost::property_tree::ptree module_config =
config_.get_child(
"module_config");
54 std::string test_device_led = module_config.get<std::string>(
"test_led",
"");
55 std::string test_device_buzzer =
56 module_config.get<std::string>(
"test_buzzer",
"");
57 run_on_start_ = module_config.get<
bool>(
"run_on_start",
true);
58 promisc_ = module_config.get<
bool>(
"promisc",
false);
59 const auto &devices = module_config.get_child_optional(
"devices");
61 if (!test_device_led.empty())
63 if (!test_device_buzzer.empty())
68 for (
auto &node : module_config.get_child(
"devices"))
70 boost::property_tree::ptree device_cfg = node.second;
72 std::string device_name = device_cfg.get_child(
"name").data();
74 std::string reset_card = device_cfg.get<std::string>(
"reset_card",
"");
75 std::string test_card = device_cfg.get<std::string>(
"test_card",
"");
77 sub_.subscribe(
"S_" + device_name);
78 if (!reset_card.empty())
80 if (!test_card.empty())
87 std::string reset_card = module_config.get<std::string>(
"reset_card");
104 msg >> src >> type >> card;
108 ERROR(
"Invalid auth source type ! Doing nothing.");
120 src = src.substr(2, src.size());
129 INFO(
"Test card read.");
136 DEBUG(
"Running test sequence...");
147 NOTICE(
"Test sequence doing nothing...");
154 [&](std::pair<std::string, std::string> p) ->
bool {
155 return p.second == card_id;
This define message formatting for data source SIMPLE_WIEGAND.
void run_test_sequence()
Do some stuff to let the user known something happened.
bool has_reset_card(const std::string &card_id) const
Search the device_reset_card_ map for an entry whose value is card_id;.
zmqpp::socket sub_
Sub socket on the BUS.
bool run_on_start_
Play the sequence on module startup.
std::unique_ptr< Hardware::FLED > test_buzzer_
Buzzer device for test card.
std::map< std::string, std::string > device_reset_card_
Map a device name to the reset card, since one device can support one reset card currently.
This module provide a way to have feedback when presenting a test card.
TestAndResetModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
Provides facade classes to hardware device implementation.
void config_check(const std::string &obj_name, ConfigChecker::ObjectType type)
An helper that checks configuration the existence of some objects.
Base class for module implementation.
zmqpp::context & ctx_
A reference to the ZeroMQ context in case you need it to create additional socket.
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop.
virtual ~TestAndResetModule()
std::shared_ptr< CoreUtils > CoreUtilsPtr
A Facade to a LED object.
std::map< std::string, std::string > device_test_card_
Map a device name to the test card.
boost::property_tree::ptree config_
The configuration tree passed to the start_module function.
zmqpp::socket kernel_sock_
REQ socket to kernel.
std::unique_ptr< Hardware::FLED > test_led_
Led device for test card.