devices_info.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // Created by lenovo on 2024-12-20.
  3. //
  4. #ifndef DEVICES_INFO_H
  5. #define DEVICES_INFO_H
  6. #include <microhttpd.h>
  7. #include <iostream>
  8. #include <nlohmann/json.hpp>
  9. #include <vector>
  10. #include <string>
  11. using namespace std;
  12. using json = nlohmann::json;
  13. // 模拟的数据结构
  14. struct Measure {
  15. string point;
  16. string value;
  17. };
  18. struct Device {
  19. string device_name;
  20. vector<Measure> measures;
  21. };
  22. struct AllowDevice {
  23. string device_name;
  24. };
  25. // 定义 HistoryItem 结构体
  26. struct HistoryItem {
  27. string time; // 时间戳
  28. map<string, float> values; // 测点名称 -> 测点值的映射
  29. };
  30. // 定义 DeviceMeasurement 结构体
  31. struct DeviceMeasurement {
  32. string name; // 测点名称(如 "湿度"、"温度" 等)
  33. vector<HistoryItem> historyItems; // 多个时间点的历史数据
  34. };
  35. // 定义 DeviceHistory 结构体
  36. struct DeviceHistory {
  37. string device_name; // 设备名称(如 "温湿度-1"、"烟感-1" 等)
  38. vector<DeviceMeasurement> measurements; // 该设备的所有测点数据
  39. };
  40. vector<Device> control_devices_status();
  41. json deviceInfoToJson(const vector<Device>& devices);
  42. vector<Device> createDeviceInfo();
  43. vector<Device> createNariDeviceInfo();
  44. vector<AllowDevice> allowDevice();
  45. json createNariAbnormalStatus();
  46. json getAbnormalStatus();
  47. json createDeviceHistoryData(const char* start_time, const char* end_time);
  48. json createNariDeviceHistoryData();
  49. json deviceHistoryToJson(const vector<DeviceHistory>& devices_history);
  50. json allowDeviceInfoToJson(const vector<AllowDevice>& devices);
  51. void save_cmd_to_sqlite(const std::string& device_name, const std::string& json_body);
  52. #endif //DEVICES_INFO_H