Browse Source

update

storage-in-realtime
zhaohe 12 months ago
parent
commit
13ddd122f0
  1. 3
      appsrc/baseservice/front_msg_processer/front_msg_processer.cpp
  2. 82
      appsrc/baseservice/front_msg_processer/front_msg_processer.hpp
  3. 8
      appsrc/service/app/pipeline_pressure_control.cpp
  4. 2
      appsrc/service/app/pipeline_pressure_control.hpp
  5. 2
      appsrc/service/app_core.cpp
  6. 75
      appsrc/service/hardware/device_io_ctrl_service.cpp

3
appsrc/baseservice/front_msg_processer/front_msg_processer.cpp

@ -58,7 +58,8 @@ void FrontMsgProcesser::processMsg(shared_ptr<MsgProcessContext> cxt) {
logger->info("call: {}->({})", fn, param); logger->info("call: {}->({})", fn, param);
if (fn == "FNScheduler.geFnList") { if (fn == "FNScheduler.geFnList") {
cxt->content = geFnList();
cxt->receipt["ackcode"] = 0;
cxt->receipt["content"] = geFnList();
return; return;
} }

82
appsrc/baseservice/front_msg_processer/front_msg_processer.hpp

@ -98,48 +98,32 @@ class FrontMsgProcesser {
}; };
template <typename T> template <typename T>
string getTypeName(const T& val) {
string getTypeName(const string& className, const string fnName) {
if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) { if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) {
return typeInfoMap[type_index(typeid(T))].typeName; return typeInfoMap[type_index(typeid(T))].typeName;
} }
throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name()));
};
template <typename T>
string getTypeName(const shared_ptr<T>& val) {
if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) {
return typeInfoMap[type_index(typeid(T))].typeName;
}
throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name()));
}
template <typename T>
string getTypeName() {
if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) {
return typeInfoMap[type_index(typeid(T))].typeName;
}
throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name()));
return typeid(T).name();
// throw std::runtime_error(fmt::format("reg {}:{} fail,getTypeName error:{}", className, fnName, typeid(T).name()));
}; };
//
// ref https://blog.csdn.net/Veritaz/article/details/113820764
//
template <typename R, typename... Args> template <typename R, typename... Args>
void regProcesser(const string& className, const string fnName, vector<string> params, MsgProcesserFn_t fn) { void regProcesser(const string& className, const string fnName, vector<string> params, MsgProcesserFn_t fn) {
vector<string> paramsTypeInfo; vector<string> paramsTypeInfo;
string ret = getTypeName<R>();
(paramsTypeInfo.push_back(getTypeName<Args>()), ...);
string ret = getTypeName<R>(className, fnName);
(paramsTypeInfo.push_back(getTypeName<Args>(className, fnName)), ...);
string key = className + "." + fnName; string key = className + "." + fnName;
shared_ptr<MsgProcesser> processer = nullptr;
if (m_msgProcesserMap.find(key) != m_msgProcesserMap.end()) {
processer = m_msgProcesserMap[key];
}
ZASSERT(processer);
processer->className = className;
processer->fnName = fnName;
processer->paramsTypeInfo = paramsTypeInfo;
processer->params = params;
processer->retTypeInfo = ret;
processer->fn = fn;
m_msgProcesserMap[key] = processer;
shared_ptr<MsgProcesser> processer = make_shared<MsgProcesser>();
processer->className = className;
processer->fnName = fnName;
processer->paramsTypeInfo = paramsTypeInfo;
processer->params = params;
processer->retTypeInfo = ret;
processer->fn = fn;
m_msgProcesserMap[key] = processer;
m_msgProcesserList.push_back(processer); m_msgProcesserList.push_back(processer);
} }
}; };
@ -183,37 +167,3 @@ static inline T jsonGet(json j) {
fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \
}); });
#define REG_EXTFN_VOID(fn, type) FrontMsgProcesser::ins().regProcesser<type>(thisClass.className, #fn, {}, [this](shared_ptr<MsgProcessContext> cxt) { fn(cxt); }); #define REG_EXTFN_VOID(fn, type) FrontMsgProcesser::ins().regProcesser<type>(thisClass.className, #fn, {}, [this](shared_ptr<MsgProcessContext> cxt) { fn(cxt); });
#if 0
#define REG_FN(fn, type, ...) \
{ \
type __fn_type; \
FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, /**/ \
{MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, /**/ \
__fn_type, /**/ \
[this](shared_ptr<MsgProcessContext> cxt) { \
json& params = cxt->params; \
cxt->content = fn(MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \
}); \
}
#define REG_FN_VOID(fn, type) \
{ \
type __fn_type; \
FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {}, __fn_type, [this](shared_ptr<MsgProcessContext> cxt) { cxt->content = fn(); }); \
}
#define REG_EXTFN(fn, type, ...) \
{ \
type __fn_type; \
FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, __fn_type, [this](shared_ptr<MsgProcessContext> cxt) { \
json& params = cxt->params; \
fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \
}); \
}
#define REG_EXTFN_VOID(fn, type) \
{ \
type __fn_type; \
FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {}, __fn_type, [this](shared_ptr<MsgProcessContext> cxt) { fn(cxt); }); \
}
#endif

8
appsrc/service/app/pipeline_pressure_control.cpp

@ -19,10 +19,10 @@ void PipelinePressureControl::initialize() {
GET_TO_SERVICE(m_dics); GET_TO_SERVICE(m_dics);
GET_TO_SERVICE(m_gConfig); GET_TO_SERVICE(m_gConfig);
REG_EXTFN_VOID(setType, void());
REG_EXTFN_VOID(setIntensity, void());
REG_EXTFN_VOID(getState, void());
REG_EXTFN_VOID(getConfig, void());
REG_EXTFN_VOID(setType, void(void));
REG_EXTFN_VOID(setIntensity, void(void));
REG_EXTFN_VOID(getState, void(void));
REG_EXTFN_VOID(getConfig, void(void));

2
appsrc/service/app/pipeline_pressure_control.hpp

@ -13,7 +13,7 @@
#include "service/hardware/device_io_ctrl_service.hpp" #include "service/hardware/device_io_ctrl_service.hpp"
namespace iflytop { namespace iflytop {
class PipelinePressureControl : public enable_shared_from_this<PipelinePressureControl> { class PipelinePressureControl : public enable_shared_from_this<PipelinePressureControl> {
THISCLASS(AddLiquidService);
THISCLASS(PipelinePressureControl);
typedef enum { typedef enum {
kpositivePressure, // 正压 kpositivePressure, // 正压
knegativePressure, // 负压 knegativePressure, // 负压

2
appsrc/service/app_core.cpp

@ -32,7 +32,9 @@ void AppCore::dosystem(string order, bool dump) {
void AppCore::initialize() { void AppCore::initialize() {
REG_TYPE(string); REG_TYPE(string);
REG_TYPE(void(void));
REG_TYPE(int); REG_TYPE(int);
REG_TYPE(int32_t);
REG_TYPE(float); REG_TYPE(float);
REG_TYPE(double); REG_TYPE(double);
REG_TYPE(void); REG_TYPE(void);

75
appsrc/service/hardware/device_io_ctrl_service.cpp

@ -36,42 +36,6 @@ static bool isInTestMode() {
void DeviceIoControlService::initialize() { void DeviceIoControlService::initialize() {
GET_TO_SERVICE(m_config); GET_TO_SERVICE(m_config);
if (isInTestMode()) {
logger->warn("run in pc, skip initialize device io control service");
return;
} else {
}
TransmitDisinfectionCanMaster::ins()->initialize(m_config->get_canIF().c_str(), m_config->get_canBitrate(), false);
TransmitDisinfectionCanMaster::ins()->getCanProtocolCom()->regOnRawData( //
[this](packet_type_t type, uint8_t from, uint8_t to, uint8_t *hex, uint32_t hexlen) {
if (type == kreport) {
processReportMsg(from, hex, hexlen);
}
});
// REGFNV2(DeviceIoControlService, test);
/**
* @brief
*/
try {
if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) {
AddLiquidPump_stop();
SprayPump_stop();
Blower_close();
AC_close();
Heater_close();
WarningLight_setState(0, 0, 0, 0);
if (PORT.isPipeDM()) {
PosiPressureProp_setValve(0);
NegaPressureProp_setValve(0);
AirLeakDetectTestModeCtrl_setMode(0);
}
}
} catch (const appexception &e) {
logger->error("initialize hardware error:{}", e.what());
DS->setAppExceptionFlag(e);
}
REG_FN_VOID(AddLiquidPump_addLiquid, void()); REG_FN_VOID(AddLiquidPump_addLiquid, void());
REG_FN(AddLiquidPump_run, void(int), rpm); REG_FN(AddLiquidPump_run, void(int), rpm);
@ -90,7 +54,7 @@ void DeviceIoControlService::initialize() {
REG_FN_VOID(Heater_close, void()); REG_FN_VOID(Heater_close, void());
REG_FN_VOID(Heater_readEI, void()); REG_FN_VOID(Heater_readEI, void());
REG_FN_VOID(Heater_readTemperature, void()); REG_FN_VOID(Heater_readTemperature, void());
REG_FN(WarningLight_setState,void(int, int, int, int), r, g, b, warning);
REG_FN(WarningLight_setState, void(int, int, int, int), r, g, b, warning);
REG_FN(PosiPressureProp_setValve, void(int), val); REG_FN(PosiPressureProp_setValve, void(int), val);
REG_FN_VOID(PosiPressureProp_readPos, void()); REG_FN_VOID(PosiPressureProp_readPos, void());
REG_FN_VOID(PosiPressureProp_isBusy, void()); REG_FN_VOID(PosiPressureProp_isBusy, void());
@ -109,6 +73,43 @@ void DeviceIoControlService::initialize() {
REG_FN_VOID(LiquidWeightPS_readPa, void()); REG_FN_VOID(LiquidWeightPS_readPa, void());
REG_FN_VOID(SprayPumpPostPS_readPa, void()); REG_FN_VOID(SprayPumpPostPS_readPa, void());
REG_FN_VOID(AddLiquidPumpPostPS_readPa, void()); REG_FN_VOID(AddLiquidPumpPostPS_readPa, void());
if (isInTestMode()) {
logger->warn("run in pc, skip initialize device io control service");
return;
} else {
}
TransmitDisinfectionCanMaster::ins()->initialize(m_config->get_canIF().c_str(), m_config->get_canBitrate(), false);
TransmitDisinfectionCanMaster::ins()->getCanProtocolCom()->regOnRawData( //
[this](packet_type_t type, uint8_t from, uint8_t to, uint8_t *hex, uint32_t hexlen) {
if (type == kreport) {
processReportMsg(from, hex, hexlen);
}
});
// REGFNV2(DeviceIoControlService, test);
/**
* @brief
*/
try {
if (PORT.isLageSpaceDM() || PORT.isSmallSpaceDM() || PORT.isPipeDM()) {
AddLiquidPump_stop();
SprayPump_stop();
Blower_close();
AC_close();
Heater_close();
WarningLight_setState(0, 0, 0, 0);
if (PORT.isPipeDM()) {
PosiPressureProp_setValve(0);
NegaPressureProp_setValve(0);
AirLeakDetectTestModeCtrl_setMode(0);
}
}
} catch (const appexception &e) {
logger->error("initialize hardware error:{}", e.what());
DS->setAppExceptionFlag(e);
}
} }
#define TRY_DO(func) \ #define TRY_DO(func) \

Loading…
Cancel
Save