diff --git a/src/appPowerMangerGui/CMakeLists.txt b/src/appPowerMangerGui/CMakeLists.txt deleted file mode 100644 index f524141..0000000 --- a/src/appPowerMangerGui/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -#-------------------------------------------------------- -# The CMakeLists.txt for: appPowerMangerGui -# Author(s): -#-------------------------------------------------------- - -SET(SRC - PowerMangerGui.cpp - PowerMangerGui_Info.cpp - main.cpp -) - -ADD_EXECUTABLE(appPowerMangerGui ${SRC}) - -TARGET_LINK_LIBRARIES(appPowerMangerGui - ${MOOS_LIBRARIES} - mbutil - m - pthread) - diff --git a/src/appPowerMangerGui/PowerMangerGui.cpp b/src/appPowerMangerGui/PowerMangerGui.cpp deleted file mode 100644 index c22d29a..0000000 --- a/src/appPowerMangerGui/PowerMangerGui.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/************************************************************/ -/* NAME: */ -/* ORGN: MIT */ -/* FILE: PowerMangerGui.cpp */ -/* DATE: */ -/************************************************************/ - -#include -#include "MBUtils.h" -#include "PowerMangerGui.h" - -using namespace std; - -//--------------------------------------------------------- -// Constructor - -PowerMangerGui::PowerMangerGui() -{ -} - -//--------------------------------------------------------- -// Destructor - -PowerMangerGui::~PowerMangerGui() -{ -} - -//--------------------------------------------------------- -// Procedure: OnNewMail - -bool PowerMangerGui::OnNewMail(MOOSMSG_LIST &NewMail) -{ - MOOSMSG_LIST::iterator p; - - for(p=NewMail.begin(); p!=NewMail.end(); p++) { - CMOOSMsg &msg = *p; - -#if 0 // Keep these around just for template - string key = msg.GetKey(); - string comm = msg.GetCommunity(); - double dval = msg.GetDouble(); - string sval = msg.GetString(); - string msrc = msg.GetSource(); - double mtime = msg.GetTime(); - bool mdbl = msg.IsDouble(); - bool mstr = msg.IsString(); -#endif - } - - return(true); -} - -//--------------------------------------------------------- -// Procedure: OnConnectToServer - -bool PowerMangerGui::OnConnectToServer() -{ - RegisterVariables(); - return(true); -} - -//--------------------------------------------------------- -// Procedure: Iterate() -// happens AppTick times per second - -bool PowerMangerGui::Iterate() -{ - return(true); -} - -//--------------------------------------------------------- -// Procedure: OnStartUp() -// happens before connection is open - -bool PowerMangerGui::OnStartUp() -{ - list sParams; - m_MissionReader.EnableVerbatimQuoting(false); - if(m_MissionReader.GetConfiguration(GetAppName(), sParams)) { - list::iterator p; - for(p=sParams.begin(); p!=sParams.end(); p++) { - string line = *p; - string param = tolower(biteStringX(line, '=')); - string value = line; - - if(param == "foo") { - //handled - } - else if(param == "bar") { - //handled - } - } - } - - RegisterVariables(); - return(true); -} - -//--------------------------------------------------------- -// Procedure: RegisterVariables - -void PowerMangerGui::RegisterVariables() -{ - // Register("FOOBAR", 0); -} - diff --git a/src/appPowerMangerGui/PowerMangerGui.h b/src/appPowerMangerGui/PowerMangerGui.h deleted file mode 100644 index 9e4a53d..0000000 --- a/src/appPowerMangerGui/PowerMangerGui.h +++ /dev/null @@ -1,33 +0,0 @@ -/************************************************************/ -/* NAME: */ -/* ORGN: MIT */ -/* FILE: PowerMangerGui.h */ -/* DATE: */ -/************************************************************/ - -#ifndef PowerMangerGui_HEADER -#define PowerMangerGui_HEADER - -#include "FL/Fl.H" -#include "MOOS/libMOOS/MOOSLib.h" - -class PowerMangerGui : public CMOOSApp { -public: - PowerMangerGui(); - ~PowerMangerGui(); - bool minWindows(); - -protected: // Standard MOOSApp functions to overload - bool OnNewMail(MOOSMSG_LIST &NewMail); - bool Iterate(); - bool OnConnectToServer(); - bool OnStartUp(); - -protected: - void RegisterVariables(); - -private: // Configuration variables -private: // State variables -}; - -#endif diff --git a/src/appPowerMangerGui/PowerMangerGui_Info.cpp b/src/appPowerMangerGui/PowerMangerGui_Info.cpp deleted file mode 100644 index f834c52..0000000 --- a/src/appPowerMangerGui/PowerMangerGui_Info.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/****************************************************************/ -/* NAME: */ -/* ORGN: MIT Cambridge MA */ -/* FILE: PowerMangerGui_Info.cpp */ -/* DATE: Dec 29th 1963 */ -/****************************************************************/ - -#include -#include -#include "PowerMangerGui_Info.h" -#include "ColorParse.h" -#include "ReleaseInfo.h" - -using namespace std; - -//---------------------------------------------------------------- -// Procedure: showSynopsis - -void showSynopsis() -{ - blk("SYNOPSIS: "); - blk("------------------------------------ "); - blk(" The appPowerMangerGui application is used for "); - blk(" "); - blk(" "); - blk(" "); - blk(" "); -} - -//---------------------------------------------------------------- -// Procedure: showHelpAndExit - -void showHelpAndExit() -{ - blk(" "); - blu("=============================================================== "); - blu("Usage: appPowerMangerGui file.moos [OPTIONS] "); - blu("=============================================================== "); - blk(" "); - showSynopsis(); - blk(" "); - blk("Options: "); - mag(" --alias","= "); - blk(" Launch appPowerMangerGui with the given process name "); - blk(" rather than appPowerMangerGui. "); - mag(" --example, -e "); - blk(" Display example MOOS configuration block. "); - mag(" --help, -h "); - blk(" Display this help message. "); - mag(" --interface, -i "); - blk(" Display MOOS publications and subscriptions. "); - mag(" --version,-v "); - blk(" Display the release version of appPowerMangerGui. "); - blk(" "); - blk("Note: If argv[2] does not otherwise match a known option, "); - blk(" then it will be interpreted as a run alias. This is "); - blk(" to support pAntler launching conventions. "); - blk(" "); - exit(0); -} - -//---------------------------------------------------------------- -// Procedure: showExampleConfigAndExit - -void showExampleConfigAndExit() -{ - blk(" "); - blu("=============================================================== "); - blu("appPowerMangerGui Example MOOS Configuration "); - blu("=============================================================== "); - blk(" "); - blk("ProcessConfig = appPowerMangerGui "); - blk("{ "); - blk(" AppTick = 4 "); - blk(" CommsTick = 4 "); - blk(" "); - blk("} "); - blk(" "); - exit(0); -} - - -//---------------------------------------------------------------- -// Procedure: showInterfaceAndExit - -void showInterfaceAndExit() -{ - blk(" "); - blu("=============================================================== "); - blu("appPowerMangerGui INTERFACE "); - blu("=============================================================== "); - blk(" "); - showSynopsis(); - blk(" "); - blk("SUBSCRIPTIONS: "); - blk("------------------------------------ "); - blk(" NODE_MESSAGE = src_node=alpha,dest_node=bravo,var_name=FOO, "); - blk(" string_val=BAR "); - blk(" "); - blk("PUBLICATIONS: "); - blk("------------------------------------ "); - blk(" Publications are determined by the node message content. "); - blk(" "); - exit(0); -} - -//---------------------------------------------------------------- -// Procedure: showReleaseInfoAndExit - -void showReleaseInfoAndExit() -{ - showReleaseInfo("appPowerMangerGui", "gpl"); - exit(0); -} - diff --git a/src/appPowerMangerGui/PowerMangerGui_Info.h b/src/appPowerMangerGui/PowerMangerGui_Info.h deleted file mode 100644 index 64a4576..0000000 --- a/src/appPowerMangerGui/PowerMangerGui_Info.h +++ /dev/null @@ -1,18 +0,0 @@ -/****************************************************************/ -/* NAME: */ -/* ORGN: MIT Cambridge MA */ -/* FILE: PowerMangerGui_Info.h */ -/* DATE: Dec 29th 1963 */ -/****************************************************************/ - -#ifndef PowerMangerGui_INFO_HEADER -#define PowerMangerGui_INFO_HEADER - -void showSynopsis(); -void showHelpAndExit(); -void showExampleConfigAndExit(); -void showInterfaceAndExit(); -void showReleaseInfoAndExit(); - -#endif - diff --git a/src/appPowerMangerGui/appPowerMangerGui.moos b/src/appPowerMangerGui/appPowerMangerGui.moos deleted file mode 100644 index a7528fc..0000000 --- a/src/appPowerMangerGui/appPowerMangerGui.moos +++ /dev/null @@ -1,9 +0,0 @@ -//------------------------------------------------ -// appPowerMangerGui config block - -ProcessConfig = appPowerMangerGui -{ - AppTick = 4 - CommsTick = 4 -} - diff --git a/src/appPowerMangerGui/main.cpp b/src/appPowerMangerGui/main.cpp deleted file mode 100644 index 8f97daa..0000000 --- a/src/appPowerMangerGui/main.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/************************************************************/ -/* NAME: */ -/* ORGN: MIT */ -/* FILE: main.cpp */ -/* DATE: */ -/************************************************************/ - -#include -#include "MBUtils.h" -#include "ColorParse.h" -#include "PowerMangerGui.h" -#include "PowerMangerGui_Info.h" - -using namespace std; - -int main(int argc, char *argv[]) -{ - string mission_file; - string run_command = argv[0]; - - for(int i=1; i @@ -174,6 +228,17 @@ 正在连接MOOSDB... +
+
+ + +
+
+ + +
+ +

本地数据库

@@ -315,6 +380,45 @@ }); } + // MOOS通知功能 + function sendMoosNotify() { + const varValue = document.getElementById('moos-var').value.trim(); + const keyValue = document.getElementById('moos-key').value.trim(); + + if (!varValue || !keyValue) { + alert('请填写Var和Key值'); + return; + } + + const payload = { + var: varValue, + // key: isNaN(keyValue) ? keyValue : Number(keyValue) + key: keyValue + }; + + fetch('/api/moos-notify', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload) + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + alert('发送成功'); + } else { + alert('发送失败: ' + data.message); + } + }) + .catch(error => { + console.error('Error:', error); + alert('发送请求失败'); + }); + } + + document.getElementById('moos-send-btn').addEventListener('click', sendMoosNotify); + // 每1秒更新一次数据 setInterval(updateData, 1000); updateData(); // 初始加载 diff --git a/src/appPowerMangerWebUI/main.cpp b/src/appPowerMangerWebUI/main.cpp index 192b4de..e68297c 100644 --- a/src/appPowerMangerWebUI/main.cpp +++ b/src/appPowerMangerWebUI/main.cpp @@ -49,7 +49,7 @@ int main() { // 定义路由,处理 /api/power-data 的请求 CROW_ROUTE(app, "/api/download-db") ([&db]() { - std::ifstream file("/home/zjk/project/H100/H100PowerManger/data/power_data.db", std::ios::binary); + std::ifstream file("/home/zjk/project/H100/H100PowerManger/src/appPowerMangerWebUI/static/index.html", std::ios::binary); if (!file) { return crow::response(404, "Database file not found"); } @@ -86,12 +86,39 @@ int main() { } return response; }); - // 定义路由,处理 /api/moos-notify 的请求(POST) - CROW_ROUTE(app, "/api/moos-notify") - ([&moosClient]() { - crow::json::wvalue response; - response["message"] = "Received MOOS notification"; - return response; + // 定义路由,处理 /api/moos-notify 的请求(POST) + CROW_ROUTE(app, "/api/moos-notify").methods("POST"_method) + ([&moosClient](const crow::request& req) { + auto json = crow::json::load(req.body); + if (!json) { + return crow::response(400, "Invalid JSON"); + } + + std::string var = json["var"].s(); + std::string key = json["key"].s(); + + // 发送MOOS消息 + bool notifyResult = moosClient.Notify(var, key); + std::cout << "MOOS Notify: var=" << var << ", key=" << key + << ", result=" << (notifyResult ? "success" : "failed") << std::endl; + + crow::response res; + if (notifyResult) + { + res.body = crow::json::wvalue({ + {"success", true}, + {"message", key + ":" + var} + }).dump(); + } + else + { + res.body = crow::json::wvalue({ + {"success", false}, + {"message", key + ":" + var}, + }).dump(); + } + res.set_header("Content-Type", "application/json"); + return res; }); // 启动服务器,监听端口 18080 diff --git a/src/pPowerManger/PowerManger.cpp b/src/pPowerManger/PowerManger.cpp index f6a5990..8b24f96 100644 --- a/src/pPowerManger/PowerManger.cpp +++ b/src/pPowerManger/PowerManger.cpp @@ -123,7 +123,7 @@ bool PowerManger::Iterate() else m_FsmThread.Stop(); // 数据库测试 - + //3. 输出报告 buildPowerSysReport(); //4. 打印错误信息