Update Naming and Tests
This commit is contained in:
+125
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
|
||||
Logic ->
|
||||
Contain all Configured Devices
|
||||
-> Retrieve Devices from Domotica API
|
||||
-> Retrieve Devices from Configuration
|
||||
|
||||
|
||||
WiFi -> Check for Devices
|
||||
Change to Offline
|
||||
-> Ping (Internal to WiFi)
|
||||
Fail
|
||||
-> Update Device to Offline
|
||||
Success
|
||||
-> NOOP
|
||||
Change to Online
|
||||
-> Ping (Internal to WiFi)
|
||||
Fail
|
||||
-> NOOP
|
||||
Success
|
||||
-> Update Device to Online
|
||||
|
||||
|
||||
Bluetooth -> Check for Devices
|
||||
Change to Offline
|
||||
Change to Online
|
||||
|
||||
|
||||
API -> Poll Devices
|
||||
|
||||
- Who keeps track of the devices?
|
||||
Logic?
|
||||
Driver?
|
||||
|
||||
//*/
|
||||
|
||||
#include "Logic.h"
|
||||
#include <Logging.h>
|
||||
#include <json.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace PresenceDetection {
|
||||
namespace Logic {
|
||||
|
||||
Logic::Logic(const std::string& inventoryURL) :
|
||||
m_inventoryURL(inventoryURL)
|
||||
{
|
||||
}
|
||||
|
||||
Logic::~Logic()
|
||||
{
|
||||
}
|
||||
|
||||
void Logic::LoadDevicesFromConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
void Logic::UpdateDevicesFromInventory()
|
||||
{
|
||||
try
|
||||
{
|
||||
Http::HttpRequest request(m_inventoryURL);
|
||||
std::string devices = m_httpClient.Open(request);
|
||||
nlohmann::json json = nlohmann::json::parse(devices);
|
||||
|
||||
m_dynamicDevices.clear();
|
||||
for (auto& element : json)
|
||||
{
|
||||
int id = std::stoi(element["id"].get<std::string>());
|
||||
std::string wifi;
|
||||
std::string bluetooth;
|
||||
|
||||
//if (element["wifi"] != "")
|
||||
if (element["macaddress"] != "")
|
||||
{
|
||||
//wifi = element["wifi"];
|
||||
wifi = element["macaddress"];
|
||||
std::transform(wifi.begin(), wifi.end(), wifi.begin(), ::tolower);
|
||||
}
|
||||
|
||||
if (element["bluetooth"] != "")
|
||||
{
|
||||
bluetooth = element["bluetooth"];
|
||||
std::transform(bluetooth.begin(), bluetooth.end(), bluetooth.begin(), ::tolower);
|
||||
}
|
||||
|
||||
m_dynamicDevices.push_back(Device::Device(id, wifi, bluetooth));
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Logic::GetDevicesFromInventory() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
void Logic::DumpDevices()
|
||||
{
|
||||
std::cout << "Static Devices:" << std::endl;
|
||||
for (auto& device : m_staticDevices)
|
||||
{
|
||||
std::cout << "ID: " << device.ID() << std::endl;
|
||||
std::cout << "Wifi: " << device.WifiMacAddress() << std::endl;
|
||||
std::cout << "Bluetooth: " << device.BluetoothMacAddress() << std::endl;
|
||||
std::cout << "Online: " << device.Online() << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Dynamic Devices:" << std::endl;
|
||||
for (auto& device : m_dynamicDevices)
|
||||
{
|
||||
std::cout << "ID: " << device.ID() << std::endl;
|
||||
std::cout << "Wifi: " << device.WifiMacAddress() << std::endl;
|
||||
std::cout << "Bluetooth: " << device.BluetoothMacAddress() << std::endl;
|
||||
std::cout << "Online: " << device.Online() << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Logic
|
||||
} // namespace PresenceDetection
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef LOGIC_LOGIC_H
|
||||
#define LOGIC_LOGIC_H
|
||||
|
||||
#include "Device/Device.h"
|
||||
#include <HttpClient.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace PresenceDetection {
|
||||
namespace Logic {
|
||||
|
||||
class Logic
|
||||
{
|
||||
public:
|
||||
Logic(const std::string& inventoryURL);
|
||||
~Logic();
|
||||
|
||||
void LoadDevicesFromConfiguration();
|
||||
void UpdateDevicesFromInventory();
|
||||
|
||||
void DumpDevices();
|
||||
|
||||
private:
|
||||
//void UpdatePresentDevices();
|
||||
void PollBluetoothDevices();
|
||||
void PollWiFiDevices();
|
||||
|
||||
private:
|
||||
Http::HttpClient m_httpClient;
|
||||
|
||||
std::string m_inventoryURL;
|
||||
std::vector<Device::Device> m_dynamicDevices;
|
||||
std::vector<Device::Device> m_staticDevices;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Logic
|
||||
} // namespace PresenceDetection
|
||||
|
||||
#endif // LOGIC_LOGIC_H
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../Makefile
|
||||
Reference in New Issue
Block a user