Test.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "Bluetooth/Functions.h"
  2. #include "Logic/Logic.h"
  3. #include "Util/StaticDevice.h"
  4. #include "WiFi/Driver.h"
  5. #include "WiFi/Functions.h"
  6. #include <INIReader.h>
  7. #include <algorithm>
  8. #include <iostream>
  9. #include <signal.h>
  10. #include <string>
  11. void print()
  12. {
  13. std::cout << "Print" << std::endl;
  14. }
  15. void TestINIReader()
  16. {
  17. std::cout << "--------------------------------" << std::endl;
  18. std::cout << "TestINIReader" << std::endl << std::endl;
  19. INIReader reader("PresenceDetection.ini");
  20. std::string target = reader.Get("PresenceDetection", "Target", "");
  21. if (!target.empty())
  22. std::cout << "Error" << std::endl;
  23. std::cout << target.size() << " " << target << std::endl;
  24. bool wifi = reader.GetBoolean("PresenceDetection", "WiFi", false);
  25. if (wifi)
  26. std::cout << "WiFi On" << std::endl;
  27. else
  28. std::cout << "WiFi Off" << std::endl;
  29. bool test = reader.GetBoolean("PresenceDetection", "Test", false);
  30. if (test)
  31. std::cout << "Test On" << std::endl;
  32. else
  33. std::cout << "Test Off" << std::endl;
  34. std::cout << "--------------------------------" << std::endl << std::endl;
  35. }
  36. void TestLogic()
  37. {
  38. std::cout << "--------------------------------" << std::endl;
  39. std::cout << "TestLogic" << std::endl << std::endl;
  40. PresenceDetection::Logic::Logic logic("http://DomoticaPi:8080/api/inventory/WirelessDevice");
  41. logic.LoadDevicesFromConfiguration();
  42. logic.UpdateDevicesFromInventory();
  43. logic.DumpDevices();
  44. std::cout << "--------------------------------" << std::endl << std::endl;
  45. }
  46. void TestPing()
  47. {
  48. std::cout << "--------------------------------" << std::endl;
  49. std::cout << "TestPing" << std::endl << std::endl;
  50. bool wifi = PresenceDetection::WiFi::Functions::Ping("192.168.1.174");
  51. if (wifi)
  52. std::cout << "192.168.1.174 Online" << std::endl;
  53. else
  54. std::cout << "192.168.1.174 Offline" << std::endl;
  55. bool bluetooth = PresenceDetection::Bluetooth::Functions::Ping("64:C7:53:77:2A:32");
  56. if (bluetooth)
  57. std::cout << "64:C7:53:77:2A:32 Online" << std::endl;
  58. else
  59. std::cout << "64:C7:53:77:2A:32 Offline" << std::endl;
  60. bluetooth = PresenceDetection::Bluetooth::Functions::Ping("C8:BC:C8:22:94:68");
  61. if (bluetooth)
  62. std::cout << "C8:BC:C8:22:94:68 Online" << std::endl;
  63. else
  64. std::cout << "C8:BC:C8:22:94:68 Offline" << std::endl;
  65. bluetooth = PresenceDetection::Bluetooth::Functions::Ping("E8:9E:B4:25:E1:E8");
  66. if (bluetooth)
  67. std::cout << "E8:9E:B4:25:E1:E8 Online" << std::endl;
  68. else
  69. std::cout << "E8:9E:B4:25:E1:E8 Offline" << std::endl;
  70. std::cout << "--------------------------------" << std::endl << std::endl;
  71. }
  72. void TestUniFi()
  73. {
  74. std::shared_ptr<PresenceDetection::WiFi::Driver> pWiFiDriver;
  75. std::string hostname = "UniFi-Controller";
  76. int port = 8443;
  77. std::string username = "admin";
  78. std::string password = "Wh1sK3y196909";
  79. std::string cookiefile = "UniFi_Cookies";
  80. int timeout = 60;
  81. std::string inventoryURL = "http://DomoticaPi:8080/api/inventory/WirelessDevice";
  82. std::string target = "";
  83. std::vector<PresenceDetection::Util::StaticDevice> staticDevices;
  84. pWiFiDriver = std::make_shared<PresenceDetection::WiFi::Driver>(hostname, port, username, password, cookiefile, timeout, inventoryURL, target, staticDevices);
  85. sigset_t wset;
  86. sigemptyset(&wset);
  87. sigaddset(&wset,SIGHUP);
  88. sigaddset(&wset,SIGINT);
  89. sigaddset(&wset,SIGTERM);
  90. int sig;
  91. sigwait(&wset,&sig);
  92. pWiFiDriver->Stop();
  93. pWiFiDriver->Wait();
  94. }
  95. int main(int /*argc*/, char** /*argv[]*/)
  96. {
  97. //TestINIReader();
  98. //TestLogic();
  99. //TestPing();
  100. TestUniFi();
  101. return 0;
  102. }