Update Naming and Tests

This commit is contained in:
2021-07-28 16:23:27 +02:00
parent f03e90f5b9
commit 03b00fa6de
17 changed files with 566 additions and 104 deletions
+28 -28
View File
@@ -1,6 +1,6 @@
#include "Bluetooth/Device.h"
#include "UniFi/Device.h"
#include "Bluetooth/Driver.h"
#include "Util/StaticDevice.h"
#include "WiFi/Driver.h"
#include <clipp.h>
#include <INIReader.h>
#include <Logging.h>
@@ -70,7 +70,7 @@ int main(int argc, char** argv)
std::string target = iniReader.Get("PresenceDetection", "Target", "");
bool unifi = iniReader.GetBoolean("PresenceDetection", "UniFi", false);
bool wifi = iniReader.GetBoolean("PresenceDetection", "WiFi", false);
bool bluetooth = iniReader.GetBoolean("PresenceDetection", "Bluetooth", false);
@@ -80,7 +80,7 @@ int main(int argc, char** argv)
for (auto section : sections)
{
if (section != "PresenceDetection" &&
section != "UniFi" &&
section != "WiFi" &&
section != "Bluetooth")
{
std::string WifiMac = iniReader.Get(section, "WifiMac", "");
@@ -123,42 +123,42 @@ int main(int argc, char** argv)
}
}
std::shared_ptr<PresenceDetection::UniFi::Device> pUniFiDevice;
if (unifi)
std::shared_ptr<PresenceDetection::WiFi::Driver> pWiFiDriver;
if (wifi)
{
std::string hostname = iniReader.Get("UniFi", "Hostname", "");
std::string hostname = iniReader.Get("WiFi", "Hostname", "");
if (hostname.empty())
throw std::runtime_error("UniFi Hostname directive missing in ini file.");
throw std::runtime_error("WiFi Hostname directive missing in ini file.");
int port = iniReader.GetInteger("UniFi", "Port", 8443);
int port = iniReader.GetInteger("WiFi", "Port", 8443);
std::string username = iniReader.Get("UniFi", "Username", "");
std::string username = iniReader.Get("WiFi", "Username", "");
if (username.empty())
throw std::runtime_error("UniFi Username directive missing in ini file.");
throw std::runtime_error("WiFi Username directive missing in ini file.");
std::string password = iniReader.Get("UniFi", "Password", "");
std::string password = iniReader.Get("WiFi", "Password", "");
if (password.empty())
throw std::runtime_error("UniFi Password directive missing in ini file.");
throw std::runtime_error("WiFi Password directive missing in ini file.");
std::string cookiefile = iniReader.Get("UniFi", "CookieFile", "");
std::string cookiefile = iniReader.Get("WiFi", "CookieFile", "");
if (cookiefile.empty())
throw std::runtime_error("UniFi CookieFile directive missing in ini file.");
throw std::runtime_error("WiFi CookieFile directive missing in ini file.");
int timeout = iniReader.GetInteger("UniFi", "Timeout", 150);
int timeout = iniReader.GetInteger("WiFi", "Timeout", 150);
std::string inventoryURL = iniReader.Get("UniFi", "Inventory", "");
std::string inventoryURL = iniReader.Get("WiFi", "Inventory", "");
pUniFiDevice = std::make_shared<PresenceDetection::UniFi::Device>(hostname, port, username, password, cookiefile, timeout, inventoryURL, target, staticDevices);
pWiFiDriver = std::make_shared<PresenceDetection::WiFi::Driver>(hostname, port, username, password, cookiefile, timeout, inventoryURL, target, staticDevices);
}
std::shared_ptr<PresenceDetection::Bluetooth::Device> pBluetoothDevice;
std::shared_ptr<PresenceDetection::Bluetooth::Driver> pBluetoothDriver;
if (bluetooth)
{
int timeout = iniReader.GetInteger("Bluetooth", "Timeout", 150);
std::string inventoryURL = iniReader.Get("Bluetooth", "Inventory", "");
pBluetoothDevice = std::make_shared<PresenceDetection::Bluetooth::Device>(timeout, inventoryURL, target, staticDevices);
pBluetoothDriver = std::make_shared<PresenceDetection::Bluetooth::Driver>(timeout, inventoryURL, target, staticDevices);
}
sigset_t wset;
@@ -171,17 +171,17 @@ int main(int argc, char** argv)
Logging::Log(Logging::Severity::Info, "Stopping PresenceDetection...");
if (pUniFiDevice)
pUniFiDevice->Stop();
if (pWiFiDriver)
pWiFiDriver->Stop();
if (pBluetoothDevice)
pBluetoothDevice->Stop();
if (pBluetoothDriver)
pBluetoothDriver->Stop();
if (pUniFiDevice)
pUniFiDevice->Wait();
if (pWiFiDriver)
pWiFiDriver->Wait();
if (pBluetoothDevice)
pBluetoothDevice->Wait();
if (pBluetoothDriver)
pBluetoothDriver->Wait();
Logging::CloseLog();
}
+62 -10
View File
@@ -1,11 +1,9 @@
#include "Bluetooth/Functions.h"
#include "Logic/Logic.h"
#include "WiFi/Functions.h"
#include <INIReader.h>
#include <Timer.h>
#include <unistd.h>
#include <algorithm>
#include <chrono>
#include <deque>
#include <iostream>
#include <memory>
#include <string>
@@ -16,6 +14,9 @@ void print()
void TestINIReader()
{
std::cout << "--------------------------------" << std::endl;
std::cout << "TestINIReader" << std::endl << std::endl;
INIReader reader("PresenceDetection.ini");
std::string target = reader.Get("PresenceDetection", "Target", "");
@@ -23,22 +24,73 @@ void TestINIReader()
std::cout << "Error" << std::endl;
std::cout << target.size() << " " << target << std::endl;
bool unifi = reader.GetBoolean("PresenceDetection", "UniFi", false);
if (unifi)
std::cout << "UniFi On" << std::endl;
bool wifi = reader.GetBoolean("PresenceDetection", "WiFi", false);
if (wifi)
std::cout << "WiFi On" << std::endl;
else
std::cout << "UniFi Off" << std::endl;
std::cout << "WiFi Off" << std::endl;
bool test = reader.GetBoolean("PresenceDetection", "Test", false);
if (test)
std::cout << "Test On" << std::endl;
else
std::cout << "Test Off" << std::endl;
std::cout << "--------------------------------" << std::endl << std::endl;
}
void TestLogic()
{
std::cout << "--------------------------------" << std::endl;
std::cout << "TestLogic" << std::endl << std::endl;
PresenceDetection::Logic::Logic logic("http://DomoticaPi:8080/api/inventory/WirelessDevice");
logic.LoadDevicesFromConfiguration();
logic.UpdateDevicesFromInventory();
logic.DumpDevices();
std::cout << "--------------------------------" << std::endl << std::endl;
}
void TestPing()
{
std::cout << "--------------------------------" << std::endl;
std::cout << "TestPing" << std::endl << std::endl;
bool wifi = PresenceDetection::WiFi::Functions::Ping("192.168.1.174");
if (wifi)
std::cout << "192.168.1.174 Online" << std::endl;
else
std::cout << "192.168.1.174 Offline" << std::endl;
bool bluetooth = PresenceDetection::Bluetooth::Functions::Ping("64:C7:53:77:2A:32");
if (bluetooth)
std::cout << "64:C7:53:77:2A:32 Online" << std::endl;
else
std::cout << "64:C7:53:77:2A:32 Offline" << std::endl;
bluetooth = PresenceDetection::Bluetooth::Functions::Ping("C8:BC:C8:22:94:68");
if (bluetooth)
std::cout << "C8:BC:C8:22:94:68 Online" << std::endl;
else
std::cout << "C8:BC:C8:22:94:68 Offline" << std::endl;
bluetooth = PresenceDetection::Bluetooth::Functions::Ping("E8:9E:B4:25:E1:E8");
if (bluetooth)
std::cout << "E8:9E:B4:25:E1:E8 Online" << std::endl;
else
std::cout << "E8:9E:B4:25:E1:E8 Offline" << std::endl;
std::cout << "--------------------------------" << std::endl << std::endl;
}
int main(int /*argc*/, char** /*argv[]*/)
{
TestINIReader();
//TestINIReader();
//TestLogic();
TestPing();
return 0;
}