18 changed files with 18684 additions and 13786 deletions
-
15TESTCMD.md
-
3app_protocols/apperrorcode/apperrorcode.hpp
-
31736appdep/iflytop/core/basic/nlohmann/json.hpp
-
2appsrc/appbase/appbean/disinfection_record_csv_header.cpp
-
27appsrc/appbase/appbean/disinfection_record_csv_header.hpp
-
2appsrc/appbase/appbean/disinfection_state.hpp
-
1appsrc/appbase/appbean/setting_id.hpp
-
3appsrc/appbase/appbean/test_page_iterm.cpp
-
13appsrc/appbase/appbean/test_page_iterm.hpp
-
10appsrc/appbase/utils/zdictionary.hpp
-
17appsrc/baseservice/iflytop_front_end_service/iflytop_front_end_service.cpp
-
4appsrc/baseservice/iflytop_front_end_service/iflytop_front_end_service.hpp
-
106appsrc/service/disinfection_logs_service.cpp
-
171appsrc/service/test_page_mgr_service.cpp
-
10appsrc/service/test_page_mgr_service.hpp
-
86appsrc/service/testpage/test_page_item.hpp
-
204appsrc/service/testpage/test_page_processer.cpp
-
60appsrc/service/testpage/test_page_processer.hpp
@ -0,0 +1,15 @@ |
|||
# 测试指令 |
|||
|
|||
## 测试页面 |
|||
|
|||
### 读取配置 |
|||
```json |
|||
{ |
|||
"messageType": "Command", |
|||
"fnName": "getTestPageCfgInfo", |
|||
"className": "TestPageMgrService", |
|||
"messageId":"1234", |
|||
"timeStamp": 1234 |
|||
} |
|||
|
|||
``` |
31736
appdep/iflytop/core/basic/nlohmann/json.hpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,2 @@ |
|||
#include "disinfection_record_csv_header.hpp"
|
|||
DisinfectionRecordCSVHeader_ZENUM_IMPL; |
@ -0,0 +1,27 @@ |
|||
#pragma once
|
|||
#include "iflytop/core/components/zenum_template/zenum_template.hpp"
|
|||
|
|||
#define DisinfectionRecordCSVHeader_ZENUM_IMPL ZENUM_IMPL(DisinfectionRecordCSVHeader, DisinfectionRecordCSVHeader_LIST)
|
|||
#define DisinfectionRecordCSVHeader_LIST(type, marco) /**/ \
|
|||
marco(type, time) /**/ \ |
|||
marco(type, state) /**/ \ |
|||
marco(type, ho2o2_0) /**/ \ |
|||
marco(type, ho2o2_1) /**/ \ |
|||
marco(type, ho2o2_2) /**/ \ |
|||
marco(type, temp_0) /**/ \ |
|||
marco(type, temp_1) /**/ \ |
|||
marco(type, temp_2) /**/ \ |
|||
marco(type, rh_0) /**/ \ |
|||
marco(type, rh_1) /**/ \ |
|||
marco(type, rh_2) /**/ \ |
|||
marco(type, rs_0) /**/ \ |
|||
marco(type, rs_1) /**/ \ |
|||
marco(type, rs_2) /**/ \ |
|||
marco(type, dval) /**/ \ |
|||
marco(type, nlog) /**/ \ |
|||
marco(type, tlog) /**/ \ |
|||
marco(type, remaindisinfectant) /**/ \ |
|||
marco(type, pumpvel) /**/ \ |
|||
marco(type, reamintime) /**/ |
|||
|
|||
ZENUM_DECLAR(DisinfectionRecordCSVHeader, DisinfectionRecordCSVHeader_LIST); |
@ -0,0 +1,3 @@ |
|||
#include "test_page_iterm.hpp"
|
|||
|
|||
TestPageItermType_ZENUM_IMPL |
@ -0,0 +1,13 @@ |
|||
#pragma once
|
|||
|
|||
#include "iflytop/core/components/zenum_template/zenum_template.hpp"
|
|||
|
|||
#define TestPageItermType_ZENUM_IMPL ZENUM_IMPL(TestPageItermType, TestPageItermType_LIST)
|
|||
#define TestPageItermType_LIST(type, marco) /**/ \
|
|||
marco(type, button) /**/ \ |
|||
marco(type, buttons) /**/ \ |
|||
marco(type, state) /**/ \ |
|||
marco(type, states) /**/ \ |
|||
marco(type, placeHolder) /**/ |
|||
|
|||
ZENUM_DECLAR(TestPageItermType, TestPageItermType_LIST); |
@ -0,0 +1,86 @@ |
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
//
|
|||
#include "appbase/appbean/test_page_iterm.hpp"
|
|||
#include "baseservice/baseservice.hpp"
|
|||
namespace iflytop { |
|||
namespace testpage { |
|||
|
|||
typedef function<void(string buttonName, vector<string>)> onButton_t; |
|||
typedef function<string(string stateName)> readState_t; |
|||
|
|||
class TestPageItem { |
|||
public: |
|||
TestPageItermType type; |
|||
string displayName; |
|||
string name; |
|||
TestPageItem(TestPageItermType t) : type(t) {} |
|||
virtual ~TestPageItem() {} |
|||
}; |
|||
|
|||
class Parameter { |
|||
public: |
|||
string name; |
|||
string displayName; |
|||
string uint; |
|||
vector<string> enums; |
|||
vector<string> enumDisplayNames; |
|||
|
|||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Parameter, name, displayName, uint, enums, enumDisplayNames); |
|||
}; |
|||
|
|||
class Buttons : public TestPageItem { |
|||
public: |
|||
vector<Parameter> params; |
|||
|
|||
vector<string> buttons; |
|||
vector<string> buttonDisplayNames; |
|||
|
|||
onButton_t onButton; |
|||
Buttons() : TestPageItem(TestPageItermType::buttons) {} |
|||
|
|||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Buttons, type, displayName, name, params, buttons, buttonDisplayNames); |
|||
}; |
|||
|
|||
// class Button : public TestPageItem {
|
|||
// public:
|
|||
// vector<Parameter> params;
|
|||
|
|||
// onButton_t onButton;
|
|||
// Button() : TestPageItem(TestPageItermType::button) {}
|
|||
// NLOHMANN_DEFINE_TYPE_INTRUSIVE(Button, type, displayName, name, params);
|
|||
// };
|
|||
|
|||
class State : public TestPageItem { |
|||
public: |
|||
readState_t readState; |
|||
State() : TestPageItem(TestPageItermType::state) {} |
|||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(State, type, displayName, name); |
|||
}; |
|||
|
|||
class States : public TestPageItem { |
|||
public: |
|||
vector<string> states; |
|||
vector<string> stateDisplayNames; |
|||
readState_t readState; |
|||
States() : TestPageItem(TestPageItermType::states) {} |
|||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(States, type, displayName, name, states, stateDisplayNames); |
|||
}; |
|||
|
|||
// 换行
|
|||
class PlaceHolder : public TestPageItem { |
|||
public: |
|||
PlaceHolder() : TestPageItem(TestPageItermType::placeHolder) {} |
|||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(PlaceHolder, type, displayName, name); |
|||
}; |
|||
|
|||
} // namespace testpage
|
|||
} // namespace iflytop
|
@ -0,0 +1,204 @@ |
|||
#include "test_page_processer.hpp"
|
|||
using namespace iflytop; |
|||
using namespace testpage; |
|||
#define TOJSON(typeClass, val) dynamic_pointer_cast<typeClass>(val) ? json(*dynamic_pointer_cast<typeClass>(val)) : json()
|
|||
|
|||
void TestPageItemMgr::initialize() {} |
|||
|
|||
void TestPageItemMgr::installDict(shared_ptr<ZDictionary> dict) { this->dict = dict; } |
|||
void TestPageItemMgr::installParamType(string name, string uint, vector<string> enumItems, vector<string> displayNames) { |
|||
Parameter param; |
|||
param.name = name; |
|||
param.displayName = getDisplayVal(name); |
|||
param.uint = uint; |
|||
|
|||
for (int i = 0; i < enumItems.size(); i++) { |
|||
param.enums.push_back(enumItems[i]); |
|||
if (displayNames.size() == 0) { |
|||
param.enumDisplayNames.push_back(getDisplayVal(enumItems[i])); |
|||
} else { |
|||
param.enumDisplayNames.push_back(displayNames[i]); |
|||
} |
|||
} |
|||
m_paramTypes[name] = param; |
|||
} |
|||
|
|||
void TestPageItemMgr::insertButtons(string name, vector<string> params, vector<string> buttons, onButton_t onButton) { |
|||
shared_ptr<Buttons> item = make_shared<Buttons>(); |
|||
item->name = name; |
|||
item->displayName = getDisplayVal(name); |
|||
item->buttons = buttons; |
|||
for (auto& p : params) { |
|||
Parameter para = getParamType(p); |
|||
item->params.push_back(para); |
|||
} |
|||
for (auto& b : buttons) { |
|||
item->buttonDisplayNames.push_back(getDisplayVal(b)); |
|||
} |
|||
item->onButton = onButton; |
|||
insert(item); |
|||
} |
|||
|
|||
// void TestPageItemMgr::insertButton(string name, vector<string> params, onButton_t onButton) {
|
|||
// shared_ptr<Button> item = make_shared<Button>();
|
|||
// item->name = name;
|
|||
// for (auto& p : params) {
|
|||
// Parameter para = getParamType(p);
|
|||
// item->params.push_back(para);
|
|||
// }
|
|||
// item->onButton = onButton;
|
|||
// insert(item);
|
|||
// }
|
|||
void TestPageItemMgr::insertState(string name, readState_t readState) { |
|||
shared_ptr<State> item = make_shared<State>(); |
|||
item->name = name; |
|||
item->displayName = getDisplayVal(name); |
|||
item->readState = readState; |
|||
insert(item); |
|||
} |
|||
void TestPageItemMgr::insertStates(string name, vector<string> states, readState_t readStates) { |
|||
shared_ptr<States> item = make_shared<States>(); |
|||
item->name = name; |
|||
item->displayName = getDisplayVal(name); |
|||
item->states = states; |
|||
item->readState = readStates; |
|||
// stateDisplayNames
|
|||
for (auto& s : states) { |
|||
item->stateDisplayNames.push_back(getDisplayVal(s)); |
|||
} |
|||
insert(item); |
|||
} |
|||
void TestPageItemMgr::insertPlaceHolder() { |
|||
shared_ptr<PlaceHolder> item = make_shared<PlaceHolder>(); |
|||
item->name = "PlaceHolder"; |
|||
insert(item); |
|||
} |
|||
|
|||
string TestPageItemMgr::getDisplayVal(string name) { |
|||
if (!dict) return name; |
|||
string it = dict->getChName(name); |
|||
return it.empty() ? name : it; |
|||
} |
|||
Parameter TestPageItemMgr::getParamType(string name) { |
|||
auto it = m_paramTypes.find(name); |
|||
if (it == m_paramTypes.end()) { |
|||
THROW_APP_EXCEPTION(err::kappe_missing_param, "missing parameter %s", name.c_str()); |
|||
} |
|||
return it->second; |
|||
} |
|||
|
|||
void TestPageItemMgr::insert(shared_ptr<TestPageItem> item) { m_itemList.push_back(item); } |
|||
|
|||
void TestPageItemMgr::processOnButton(json cmd) { |
|||
string itermName = cmd["itermName"]; |
|||
string buttonName = cmd["buttonName"]; |
|||
|
|||
for (auto& it : m_itemList) { |
|||
shared_ptr<TestPageItem> item = it; |
|||
if (item->name != itermName) continue; |
|||
|
|||
//
|
|||
// if (item->type == TestPageItermType::button) {
|
|||
// auto button = dynamic_pointer_cast<Button>(item);
|
|||
// ZASSERT(button);
|
|||
// ZASSERT(button->onButton);
|
|||
// //
|
|||
// if (button->name == buttonName) {
|
|||
// button->onButton(buttonName, params);
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// else
|
|||
if (item->type == TestPageItermType::buttons) { |
|||
auto buttons = dynamic_pointer_cast<Buttons>(item); |
|||
ZASSERT(buttons); |
|||
ZASSERT(buttons->onButton); |
|||
|
|||
vector<string> params; |
|||
for (auto& p : buttons->params) { |
|||
auto it = cmd.find(p.name); |
|||
if (it == cmd.end()) { |
|||
THROW_APP_EXCEPTION(err::kappe_missing_param, "missing parameter %s", p.name.c_str()); |
|||
} |
|||
params.push_back(it->get<string>()); |
|||
} |
|||
|
|||
for (uint32_t i = 0; i < buttons->buttons.size(); i++) { |
|||
if (buttons->buttons[i] == buttonName) { |
|||
buttons->onButton(buttonName, params); |
|||
} |
|||
} |
|||
} |
|||
|
|||
//
|
|||
} |
|||
} |
|||
void TestPageItemMgr::startReportState(int interval) { |
|||
if (m_thread) m_thread->wake(); |
|||
|
|||
m_thread.reset(new Thread("TestPageItemMgr", [this, interval]() { |
|||
while (!m_thread->getExitFlag()) { |
|||
json state = readState(); |
|||
onState(state); |
|||
m_thread->sleepForMs(interval * 1000); |
|||
} |
|||
})); |
|||
} |
|||
void TestPageItemMgr::stopReportState() { |
|||
if (m_thread) { |
|||
m_thread->wake(); |
|||
m_thread->join(); |
|||
} |
|||
} |
|||
json TestPageItemMgr::readState() { |
|||
json state; |
|||
for (auto& it : m_itemList) { |
|||
shared_ptr<TestPageItem> item = it; |
|||
|
|||
// process state
|
|||
if (item->type == TestPageItermType::state) { |
|||
//
|
|||
shared_ptr<State> stateItem = dynamic_pointer_cast<State>(item); |
|||
ZASSERT(stateItem); |
|||
ZASSERT(stateItem->readState); |
|||
|
|||
// read state
|
|||
state[item->name][item->name] = stateItem->readState(item->name); |
|||
} |
|||
|
|||
// process states
|
|||
else if (item->type == TestPageItermType::states) { |
|||
//
|
|||
shared_ptr<States> states = dynamic_pointer_cast<States>(item); |
|||
ZASSERT(states); |
|||
ZASSERT(states->readState); |
|||
|
|||
// read state
|
|||
for (uint32_t i = 0; i < states->states.size(); i++) { |
|||
state[item->name][states->states[i]] = states->readState(states->states[i]); |
|||
} |
|||
} |
|||
} |
|||
return state; |
|||
} |
|||
|
|||
json TestPageItemMgr::getPageCfgInfo() { |
|||
json cfg; |
|||
for (auto& it : m_itemList) { |
|||
shared_ptr<TestPageItem> item = it; |
|||
json itemCfg; |
|||
if (item->type == TestPageItermType::button) { |
|||
// itemCfg = TOJSON(Button, item);
|
|||
} else if (item->type == TestPageItermType::buttons) { |
|||
itemCfg = TOJSON(Buttons, item); |
|||
} else if (item->type == TestPageItermType::state) { |
|||
itemCfg = TOJSON(State, item); |
|||
} else if (item->type == TestPageItermType::states) { |
|||
itemCfg = TOJSON(States, item); |
|||
} else if (item->type == TestPageItermType::placeHolder) { |
|||
itemCfg = TOJSON(PlaceHolder, item); |
|||
} |
|||
cfg.push_back(itemCfg); |
|||
} |
|||
return cfg; |
|||
} |
@ -0,0 +1,60 @@ |
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
//
|
|||
#include "appbase/appbean/test_page_iterm.hpp"
|
|||
#include "appbase/utils/zdictionary.hpp"
|
|||
#include "baseservice/baseservice.hpp"
|
|||
#include "test_page_item.hpp"
|
|||
namespace iflytop { |
|||
namespace testpage { |
|||
|
|||
class TestPageItemMgr { |
|||
THISCLASS(TestPageItemMgr); |
|||
|
|||
private: |
|||
shared_ptr<ZDictionary> dict; |
|||
map<string, Parameter> m_paramTypes; |
|||
|
|||
list<shared_ptr<TestPageItem>> m_itemList; |
|||
unique_ptr<Thread> m_thread; |
|||
|
|||
public: |
|||
nod::signal<void(json state)> onState; |
|||
|
|||
public: |
|||
void initialize(); |
|||
void installDict(shared_ptr<ZDictionary> dict); |
|||
void installParamType(string name, string uint, vector<string> enumItems, vector<string> displayNames); |
|||
void installParamType(string name, string uint, vector<string> enumItems) { installParamType(name, uint, enumItems, {}); } |
|||
|
|||
void insertButtons(string name, vector<string> buttons, vector<string> params, onButton_t onButton); |
|||
// void insertButton(string name, vector<string> params, onButton_t onButton);
|
|||
void insertState(string name, readState_t readState); |
|||
void insertStates(string name, vector<string> states, readState_t readStates); |
|||
void insertPlaceHolder(); |
|||
|
|||
// ZDictionaryIterm
|
|||
public: |
|||
void processOnButton(json cmd); |
|||
void startReportState(int interval); |
|||
void stopReportState(); |
|||
json getPageCfgInfo(); |
|||
json readState(); |
|||
|
|||
private: |
|||
void insert(shared_ptr<TestPageItem> item); |
|||
string getDisplayVal(string name); |
|||
Parameter getParamType(string name); |
|||
}; |
|||
|
|||
} // namespace testpage
|
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue