diff --git a/A.json b/A.json new file mode 100644 index 0000000..2dcd157 --- /dev/null +++ b/A.json @@ -0,0 +1,72 @@ +{ + "item": [ + { + "name": "addLiquidPumpCtrl", + "displayName": "加液泵", + "type": "button", + "params": [ + { + "name": "vel", + "displayName": "转速", + "enumDisplayNames": [ + "100", + "200" + ], + "enum": [ + "100", + "200" + ], + "uint": "g/min", + "default": "100" + }, + { + "name": "direction", + "displayName": "方向", + "enumDisplayNames": [ + "加液", + "排液" + ], + "enum": [ + "add", + "remove" + ], + "default": "add" + } + ] + }, + { + "name": "acCtrl", + "displayName": "空压机", + "type": "buttons", + "buttons": [ + "open", + "close" + ], + "buttonDisplayNames": [ + "打开", + "关闭" + ] + }, + { + "name": "acCurrent", + "displayName": "空压机电流", + "type": "state", + "stateName": "acCurrent" + }, + { + "name": "pressureSensor", + "displayName": "压力传感器", + "type": "states", + "displayNames": [ + "压力计1", + "压力计2", + "压力计3" + ], + "stateNames": [ + "pressure1", + "pressure2", + "pressure3" + ] + } + ] +} \ No newline at end of file diff --git a/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp b/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp index 81cee4d..d66b737 100644 --- a/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp +++ b/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp @@ -11,7 +11,7 @@ using namespace iflytop; // "messageType":"Command", // "className":"UserMgrService", // "fnName":"readAll", -// "param":{ +// "params":{ // } // } @@ -23,7 +23,7 @@ void FrontMsgProcesser::processMsg(shared_ptr cxt) { string key = className + "." + fnName; string fn = className + "." + fnName; - string param = cxt->cmd["param"].dump(); + string param = cxt->cmd["params"].dump(); logger->info("call: {}->({})", fn, param); diff --git a/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp b/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp index 226e80a..cfcff9d 100644 --- a/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp +++ b/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp @@ -61,6 +61,7 @@ class FrontMsgProcesser : public enable_shared_from_this { void initialize(); void processMsg(shared_ptr cxt); void registerMsgProcesser(const string& className, const string fnName, MsgProcesserFn_t fn); + }; static inline void getJsonValFromJson(json j, int& val) { diff --git a/appsrc/service/main_control_service.cpp b/appsrc/service/main_control_service.cpp index 557b0de..d0b9005 100644 --- a/appsrc/service/main_control_service.cpp +++ b/appsrc/service/main_control_service.cpp @@ -5,6 +5,7 @@ #include "service/user_mgr_service.hpp" #include "service/device_info_mgr_service.hpp" #include "service/os_mgr_service.hpp" +#include "service/test_page_mgr_service.hpp" using namespace iflytop; using namespace core; @@ -30,6 +31,8 @@ void MainControlService::initialize() { BUILD_AND_REG_SERRVICE(SettingMgrService); BUILD_AND_REG_SERRVICE(DeviceInfoMgrService); BUILD_AND_REG_SERRVICE(OsMgrService); + BUILD_AND_REG_SERRVICE(TestPageMgrService); + // GET_SERVICE(IflytopFrontEndService)->startListen(); GET_SERVICE(IflytopFrontEndService)->onMessage.connect([this](weak_ptr webSocket, json& cmd, json& receipt) { diff --git a/appsrc/service/os_mgr_service.cpp b/appsrc/service/os_mgr_service.cpp index 1494ccc..8aaecb6 100644 --- a/appsrc/service/os_mgr_service.cpp +++ b/appsrc/service/os_mgr_service.cpp @@ -23,7 +23,7 @@ void OsMgrService::shutdown(shared_ptr cxt) { void OsMgrService::updateDate(shared_ptr cxt) { logger->info("updateDate"); // sleep - auto& param = cxt->cmd["param"]; + auto& param = cxt->cmd["params"]; int32_t year = jsonGet(param["year"]); int32_t month = jsonGet(param["month"]); @@ -34,7 +34,7 @@ void OsMgrService::updateDate(shared_ptr cxt) { dosystem(fmt::format("hwclock -w").c_str()); } void OsMgrService::updateTime(shared_ptr cxt) { - auto& param = cxt->cmd["param"]; + auto& param = cxt->cmd["params"]; int32_t hour = jsonGet(param["hour"]); int32_t min = jsonGet(param["min"]); diff --git a/appsrc/service/setting_mgr_service.cpp b/appsrc/service/setting_mgr_service.cpp index 21cee9b..4a3c2b1 100644 --- a/appsrc/service/setting_mgr_service.cpp +++ b/appsrc/service/setting_mgr_service.cpp @@ -21,8 +21,8 @@ void SettingMgrService::initialize() { void SettingMgrService::getAllSetting(shared_ptr cxt) { cxt->receipt["content"] = m_db->getAllSettingJson(); } void SettingMgrService::setSettingVal(shared_ptr cxt) { - string settingName = cxt->cmd["param"]["settingName"]; - string settingVal = cxt->cmd["param"]["settingVal"]; + string settingName = cxt->cmd["params"]["settingName"]; + string settingVal = cxt->cmd["params"]["settingVal"]; bool suc = m_db->setSettingVal(settingName, settingVal); APPCHECK(suc, err::kappe_db_operate_error, "setSettingVal failed"); } @@ -43,9 +43,9 @@ void SettingMgrService::addNewFormula(shared_ptr cxt) { cxt->content = m_db->getAllFormulaJson(); } -void SettingMgrService::delFormula(shared_ptr cxt) { m_db->delFormula(jsonGet(cxt->cmd["param"]["id"])); } +void SettingMgrService::delFormula(shared_ptr cxt) { m_db->delFormula(jsonGet(cxt->cmd["params"]["id"])); } void SettingMgrService::updateFormula(shared_ptr cxt) { - auto param = cxt->cmd["param"]; + auto param = cxt->cmd["params"]; string val_str; if (param["val"].is_string()) { val_str = param["val"]; @@ -56,7 +56,7 @@ void SettingMgrService::updateFormula(shared_ptr cxt) { return; } void SettingMgrService::updateFormulaIterm(shared_ptr cxt) { - auto param = cxt->cmd["param"]; + auto param = cxt->cmd["params"]; int id = jsonGet(param["id"]); string formula_id = param["formula_id"]; diff --git a/appsrc/service/test_page_mgr_service.cpp b/appsrc/service/test_page_mgr_service.cpp new file mode 100644 index 0000000..8ab08a5 --- /dev/null +++ b/appsrc/service/test_page_mgr_service.cpp @@ -0,0 +1,96 @@ +#include "test_page_mgr_service.hpp" +using namespace iflytop; + +void TestPageMgrService::initialize() { + GET_TO_SERVICE(m_db); + GET_TO_SERVICE(m_ds); + + REGFN(TestPageMgrService, getTestPageCfgInfo); + REGFN(TestPageMgrService, onButton); + REGFN(TestPageMgrService, readState); +} + +void TestPageMgrService::getTestPageCfgInfo(shared_ptr cxt) { + json content; + content["stateUpdatePeriod"] = 1000; + + content["items"][0]["name"] = "addLiquidPumpCtrl"; + content["items"][0]["displayName"] = "加液泵"; + content["items"][0]["type"] = "button"; + content["items"][0]["params"][0]["name"] = "vel"; + content["items"][0]["params"][0]["displayName"] = "转速"; + content["items"][0]["params"][0]["enumDisplayNames"][0] = "100"; + content["items"][0]["params"][0]["enumDisplayNames"][1] = "200"; + content["items"][0]["params"][0]["enum"][0] = "100"; + content["items"][0]["params"][0]["enum"][1] = "200"; + content["items"][0]["params"][0]["uint"] = "g/min"; + content["items"][0]["params"][0]["default"] = "100"; + + content["items"][0]["params"][1]["name"] = "direction"; + content["items"][0]["params"][1]["displayName"] = "方向"; + content["items"][0]["params"][1]["enumDisplayNames"][0] = "加液"; + content["items"][0]["params"][1]["enumDisplayNames"][1] = "排液"; + content["items"][0]["params"][1]["enum"][0] = "add"; + content["items"][0]["params"][1]["enum"][1] = "remove"; + content["items"][0]["params"][1]["default"] = "add"; + + content["items"][1]["name"] = "acCtrl"; + content["items"][1]["displayName"] = "空压机"; + content["items"][1]["type"] = "buttons"; + content["items"][1]["buttons"][0] = "open"; + content["items"][1]["buttons"][1] = "close"; + content["items"][1]["buttonDisplayNames"][0] = "打开"; + content["items"][1]["buttonDisplayNames"][1] = "关闭"; + + content["items"][2]["name"] = "acCurrent"; + content["items"][2]["displayName"] = "空压机电流"; + content["items"][2]["type"] = "state"; + content["items"][2]["stateName"] = "acCurrent"; + + content["items"][3]["name"] = "pressureSensor"; + content["items"][3]["displayName"] = "压力传感器"; + content["items"][3]["type"] = "states"; + content["items"][3]["displayNames"][0] = "压力计1"; + content["items"][3]["displayNames"][1] = "压力计2"; + content["items"][3]["displayNames"][2] = "压力计3"; + content["items"][3]["stateNames"][0] = "pressure1"; + content["items"][3]["stateNames"][1] = "pressure2"; + content["items"][3]["stateNames"][2] = "pressure3"; + + content["items"][3]["stateNames"][2] = "pressure3"; + + cxt->content = content; +} +void TestPageMgrService::onButton(shared_ptr cxt) { + /** + * @brief + * + * type name + * button itermName + * buttons itermName.button + */ + logger->info("onButton {}", cxt->cmd.dump(2)); + string buttonName = cxt->cmd["params"]["buttonName"]; + if (buttonName == "addLiquidPumpCtrl") { + string vel = cxt->cmd["params"]["vel"]; + string direction = cxt->cmd["params"]["direction"]; + logger->info("on addLiquidPumpCtrl vel:{} direction:{}", vel, direction); + } else if (buttonName == "acCtrl") { + string acCtrl = cxt->cmd["params"]["acCtrl"]; + logger->info("on acCtrl:{}", acCtrl); + } +} + +void TestPageMgrService::readState(shared_ptr cxt) { + logger->info("readTestState {}", cxt->cmd.dump(2)); + string stateName = cxt->cmd["params"]["stateName"]; + if (stateName == "pressureSensor.pressure1") { + cxt->content["value"] = "100"; + } else if (stateName == "pressureSensor.pressure2") { + cxt->content["value"] = "200"; + } else if (stateName == "pressureSensor.pressure3") { + cxt->content["value"] = "300"; + } else if (stateName == "acCurrent") { + cxt->content["value"] = "10"; + } +} \ No newline at end of file diff --git a/appsrc/service/test_page_mgr_service.hpp b/appsrc/service/test_page_mgr_service.hpp new file mode 100644 index 0000000..7d1f0f2 --- /dev/null +++ b/appsrc/service/test_page_mgr_service.hpp @@ -0,0 +1,33 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include "baseservice/baseservice.hpp" +namespace iflytop { +class TestPageMgrService : public enable_shared_from_this { + ENABLE_LOGGER(TestPageMgrService); + + shared_ptr m_db; + shared_ptr m_ds; + + unique_ptr m_thread; + + public: + void initialize(); + + private: + void getTestPageCfgInfo(shared_ptr cxt); + void onButton(shared_ptr cxt); + void readState(shared_ptr cxt); + + private: +}; + +} // namespace iflytop diff --git a/appsrc/service/user_mgr_service.cpp b/appsrc/service/user_mgr_service.cpp index cb50a21..8998583 100644 --- a/appsrc/service/user_mgr_service.cpp +++ b/appsrc/service/user_mgr_service.cpp @@ -18,8 +18,8 @@ void UserMgrService::initialize() { }; void UserMgrService::login(shared_ptr cxt) { - string uid = cxt->cmd["param"]["uid"]; - string pwd = cxt->cmd["param"]["passwd"]; + string uid = cxt->cmd["params"]["uid"]; + string pwd = cxt->cmd["params"]["passwd"]; // 超超级用户 if (uid == "admin" && pwd == "iflytop9973") { @@ -46,9 +46,9 @@ void UserMgrService::unlogin(shared_ptr cxt) { return; } void UserMgrService::chpasswd(shared_ptr cxt) { - string uid = cxt->cmd["param"]["uid"]; - string newpasswd = cxt->cmd["param"]["newpasswd"]; - string passwd = cxt->cmd["param"]["passwd"]; + string uid = cxt->cmd["params"]["uid"]; + string newpasswd = cxt->cmd["params"]["newpasswd"]; + string passwd = cxt->cmd["params"]["passwd"]; if (!m_deviceStateService->isLoginAdmin()) { APPCHECK(!m_db->ispasswdCorrect(uid, passwd), err::kappe_passwd_error, fmt::format("user {} passwd error", uid)); @@ -58,19 +58,19 @@ void UserMgrService::chpasswd(shared_ptr cxt) { auto user = m_db->changePasswd(uid, newpasswd); } void UserMgrService::addUser(shared_ptr cxt) { - string uid = cxt->cmd["param"]["uid"]; - string passwd = cxt->cmd["param"]["passwd"]; + string uid = cxt->cmd["params"]["uid"]; + string passwd = cxt->cmd["params"]["passwd"]; m_db->addUser(uid, passwd); } void UserMgrService::delUser(shared_ptr cxt) { - int id = jsonGet(cxt->cmd["param"]["id"]); + int id = jsonGet(cxt->cmd["params"]["id"]); auto user = m_db->delUser(id); APPCHECK(!user, err::kappe_user_not_exist, fmt::format("user {} not exist", id)); } void UserMgrService::updateUserUid(shared_ptr cxt) { - int id = jsonGet(cxt->cmd["param"]["id"]); - string uid = cxt->cmd["param"]["uid"]; + int id = jsonGet(cxt->cmd["params"]["id"]); + string uid = cxt->cmd["params"]["uid"]; string olduid; auto user = m_db->updateUserUid(id, uid, olduid); APPCHECK(!user, err::kappe_user_not_exist, fmt::format("user {} not exist", id));