Browse Source

update

storage-in-realtime
zhaohe 12 months ago
parent
commit
7ba75ed9e7
  1. 72
      A.json
  2. 4
      appsrc/baseservice/front_msg_processer/front_msg_processer.cpp
  3. 1
      appsrc/baseservice/front_msg_processer/front_msg_processer.hpp
  4. 3
      appsrc/service/main_control_service.cpp
  5. 4
      appsrc/service/os_mgr_service.cpp
  6. 10
      appsrc/service/setting_mgr_service.cpp
  7. 96
      appsrc/service/test_page_mgr_service.cpp
  8. 33
      appsrc/service/test_page_mgr_service.hpp
  9. 20
      appsrc/service/user_mgr_service.cpp

72
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"
]
}
]
}

4
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<MsgProcessContext> 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);

1
appsrc/baseservice/front_msg_processer/front_msg_processer.hpp

@ -61,6 +61,7 @@ class FrontMsgProcesser : public enable_shared_from_this<FrontMsgProcesser> {
void initialize();
void processMsg(shared_ptr<MsgProcessContext> cxt);
void registerMsgProcesser(const string& className, const string fnName, MsgProcesserFn_t fn);
};
static inline void getJsonValFromJson(json j, int& val) {

3
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> webSocket, json& cmd, json& receipt) {

4
appsrc/service/os_mgr_service.cpp

@ -23,7 +23,7 @@ void OsMgrService::shutdown(shared_ptr<MsgProcessContext> cxt) {
void OsMgrService::updateDate(shared_ptr<MsgProcessContext> cxt) {
logger->info("updateDate");
// sleep
auto& param = cxt->cmd["param"];
auto& param = cxt->cmd["params"];
int32_t year = jsonGet<int>(param["year"]);
int32_t month = jsonGet<int>(param["month"]);
@ -34,7 +34,7 @@ void OsMgrService::updateDate(shared_ptr<MsgProcessContext> cxt) {
dosystem(fmt::format("hwclock -w").c_str());
}
void OsMgrService::updateTime(shared_ptr<MsgProcessContext> cxt) {
auto& param = cxt->cmd["param"];
auto& param = cxt->cmd["params"];
int32_t hour = jsonGet<int>(param["hour"]);
int32_t min = jsonGet<int>(param["min"]);

10
appsrc/service/setting_mgr_service.cpp

@ -21,8 +21,8 @@ void SettingMgrService::initialize() {
void SettingMgrService::getAllSetting(shared_ptr<MsgProcessContext> cxt) { cxt->receipt["content"] = m_db->getAllSettingJson(); }
void SettingMgrService::setSettingVal(shared_ptr<MsgProcessContext> 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<MsgProcessContext> cxt) {
cxt->content = m_db->getAllFormulaJson();
}
void SettingMgrService::delFormula(shared_ptr<MsgProcessContext> cxt) { m_db->delFormula(jsonGet<int>(cxt->cmd["param"]["id"])); }
void SettingMgrService::delFormula(shared_ptr<MsgProcessContext> cxt) { m_db->delFormula(jsonGet<int>(cxt->cmd["params"]["id"])); }
void SettingMgrService::updateFormula(shared_ptr<MsgProcessContext> 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<MsgProcessContext> cxt) {
return;
}
void SettingMgrService::updateFormulaIterm(shared_ptr<MsgProcessContext> cxt) {
auto param = cxt->cmd["param"];
auto param = cxt->cmd["params"];
int id = jsonGet<int>(param["id"]);
string formula_id = param["formula_id"];

96
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<MsgProcessContext> 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<MsgProcessContext> 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<MsgProcessContext> 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";
}
}

33
appsrc/service/test_page_mgr_service.hpp

@ -0,0 +1,33 @@
#pragma once
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
//
#include "baseservice/baseservice.hpp"
namespace iflytop {
class TestPageMgrService : public enable_shared_from_this<TestPageMgrService> {
ENABLE_LOGGER(TestPageMgrService);
shared_ptr<DBService> m_db;
shared_ptr<DeviceStateService> m_ds;
unique_ptr<Thread> m_thread;
public:
void initialize();
private:
void getTestPageCfgInfo(shared_ptr<MsgProcessContext> cxt);
void onButton(shared_ptr<MsgProcessContext> cxt);
void readState(shared_ptr<MsgProcessContext> cxt);
private:
};
} // namespace iflytop

20
appsrc/service/user_mgr_service.cpp

@ -18,8 +18,8 @@ void UserMgrService::initialize() {
};
void UserMgrService::login(shared_ptr<MsgProcessContext> 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<MsgProcessContext> cxt) {
return;
}
void UserMgrService::chpasswd(shared_ptr<MsgProcessContext> 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<MsgProcessContext> cxt) {
auto user = m_db->changePasswd(uid, newpasswd);
}
void UserMgrService::addUser(shared_ptr<MsgProcessContext> 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<MsgProcessContext> cxt) {
int id = jsonGet<int>(cxt->cmd["param"]["id"]);
int id = jsonGet<int>(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<MsgProcessContext> cxt) {
int id = jsonGet<int>(cxt->cmd["param"]["id"]);
string uid = cxt->cmd["param"]["uid"];
int id = jsonGet<int>(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));

Loading…
Cancel
Save