diff --git a/.gitignore b/.gitignore index e55fe75..313fbde 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ mosquitto/data/ mosquitto/log/ hls_streams/ hls_streams/live +*.db # 特例列表 !rknn_sdk/librknn_api/aarch64/*.so diff --git a/CMakeLists.txt b/CMakeLists.txt index a4dc827..5dd4d0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,7 @@ target_include_directories(edge_proxy_lib PUBLIC /usr/include/opencv4 ${CMAKE_CURRENT_SOURCE_DIR}/src ${GST_INCLUDE_DIRS} - /usr/include/rga # 编译器会在这里面找 rga.h 和 im2d.h + /usr/include/rga ) target_link_libraries(edge_proxy_lib PRIVATE diff --git a/config/edge_data_cache.db b/config/edge_data_cache.db deleted file mode 100644 index 0090570..0000000 Binary files a/config/edge_data_cache.db and /dev/null differ diff --git a/config/edge_proxy_data.db b/config/edge_proxy_data.db deleted file mode 100644 index 95299f6..0000000 Binary files a/config/edge_proxy_data.db and /dev/null differ diff --git a/src/alarm/alarm_service.cc b/src/alarm/alarm_service.cc index 8538d05..d61f6f0 100644 --- a/src/alarm/alarm_service.cc +++ b/src/alarm/alarm_service.cc @@ -1,16 +1,16 @@ // alarm/alarm_service.cpp #include "alarm_service.h" +#include "dataStorage/data_storage.h" #include #include AlarmService::AlarmService(boost::asio::io_context& io, PiperTTSInterface& tts_service, - MqttClient& mqtt_client, DataStorage& data_storage) + MqttClient& mqtt_client) : m_io_context(io), m_tts_service(tts_service), m_mqtt_client(mqtt_client), - m_data_storage(data_storage), m_tts_running(true) { m_tts_thread = std::thread(&AlarmService::tts_worker, this); spdlog::info("AlarmService created and TTS worker thread started."); @@ -278,7 +278,7 @@ void AlarmService::trigger_alarm_action(AlarmRule& rule, double value, m_mqtt_client.publish(topic, AlarmEvent::toJson(event).dump(), 1, false); // 3. 写入数据库 - if (!m_data_storage.storeAlarmEvent(event)) { + if (!DataStorage::getInstance().storeAlarmEvent(event)) { spdlog::error("Failed to store ACTIVE alarm event for rule: {}", rule.rule_id); } @@ -316,7 +316,7 @@ void AlarmService::clear_alarm(AlarmRule& rule, double value, m_mqtt_client.publish(topic, AlarmEvent::toJson(event).dump(), 1, false); // 3. 写入数据库 - if (!m_data_storage.storeAlarmEvent(event)) { + if (!DataStorage::getInstance().storeAlarmEvent(event)) { spdlog::error("Failed to store CLEARED alarm event for rule: {}", rule.rule_id); } @@ -362,7 +362,7 @@ void AlarmService::schedule_tts(const std::string& text) { } nlohmann::json AlarmService::getActiveAlarmsJson() { - auto alarms = m_data_storage.getActiveAlarms(); + auto alarms = DataStorage::getInstance().getActiveAlarms(); json j_alarms = json::array(); for (const auto& alarm : alarms) { j_alarms.push_back(AlarmEvent::toJson(alarm)); @@ -371,7 +371,7 @@ nlohmann::json AlarmService::getActiveAlarmsJson() { } nlohmann::json AlarmService::getAlarmHistoryJson(int limit) { - auto alarms = m_data_storage.getAlarmHistory(limit); + auto alarms = DataStorage::getInstance().getAlarmHistory(limit); json j_alarms = json::array(); for (const auto& alarm : alarms) { j_alarms.push_back(AlarmEvent::toJson(alarm)); diff --git a/src/alarm/alarm_service.h b/src/alarm/alarm_service.h index 8a0f40c..4e37f65 100644 --- a/src/alarm/alarm_service.h +++ b/src/alarm/alarm_service.h @@ -13,17 +13,16 @@ #include "alarm_defs.h" #include "alarm_event.h" -#include "dataStorage/data_storage.h" #include "mqtt/mqtt_client.h" #include "spdlog/spdlog.h" -#include "tts/piper_tts_interface.h" // 你的 TTS 接口 +#include "tts/piper_tts_interface.h" using json = nlohmann::json; class AlarmService { public: AlarmService(boost::asio::io_context& io, PiperTTSInterface& tts_service, - MqttClient& mqtt_client, DataStorage& data_storage); + MqttClient& mqtt_client); ~AlarmService(); @@ -59,13 +58,12 @@ class AlarmService { boost::asio::io_context& m_io_context; PiperTTSInterface& m_tts_service; MqttClient& m_mqtt_client; - DataStorage& m_data_storage; std::vector m_rules; std::map m_alarm_states; - std::string m_rules_config_path; // <--- 新增:存储配置文件路径 - std::mutex m_rules_mutex; // <--- 新增:保护 m_rules 和 m_alarm_states + std::string m_rules_config_path; + std::mutex m_rules_mutex; // TTS 播报队列 std::mutex m_tts_queue_mutex; diff --git a/src/main.cpp b/src/main.cpp index 0ebb105..bcc97cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,8 +116,7 @@ int main(int argc, char* argv[]) { PiperTTSInterface tts_service(config.getPiperExecutablePath(), config.getPiperModelPath()); - AlarmService alarm_service(g_io_context, tts_service, mqtt_client, - data_storage); + AlarmService alarm_service(g_io_context, tts_service, mqtt_client); if (!alarm_service.load_rules(config.getAlarmRulesPath())) { spdlog::error("Failed to load alarm rules. Alarms may be disabled.");