Browse Source

添加异常检测

storage-in-realtime
zhaohe 12 months ago
parent
commit
b05d6fdd73
  1. 3
      appsrc/appbase/appbean/disinfection_state.hpp
  2. 11
      appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp
  3. 26
      appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp
  4. 4
      appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.hpp
  5. 73
      appsrc/service/app_core.cpp
  6. 32
      appsrc/service/app_core.hpp

3
appsrc/appbase/appbean/disinfection_state.hpp

@ -12,6 +12,7 @@
marco(type, dehumidificationBeforeDisinfection) /**/ \
marco(type, dehumidificationAfterDisinfection) /**/ \
marco(type, emptyLiquidFromTheLine) /**/ \
marco(type, finished) /**/
marco(type, finished) /**/ \
marco(type, error) /**/
ZENUM_DECLAR(DisinfectionState, DisinfectionState_LIST);

11
appsrc/appbase/appevent/app_disinfection_snapshot_event.hpp

@ -13,12 +13,13 @@ class DisinfectionStateSnapshot {
shared_ptr<H2O2SensorDataSnapshot> h2o2Snapshot;
float dval;
float nlog;
float tlog;
float dval = 0;
float nlog = 0;
float tlog = 0;
int remainDisinfectant;
int remainTime;
int remainDisinfectant = 0;
int remainTime = 0;
int ecode = 0;
};
class AppDisinfectionSnapshotEvent : public IAppEvent {

26
appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.cpp

@ -186,7 +186,7 @@ void DisinfectionCtrlService::checkBeforeStart() {
THROW_APP_EXCEPTION(err::kappe_sensor_is_pre_hearting, "");
}
if (m_thread&&!m_thread->isWaitingForJoin()) {
if (m_thread && !m_thread->isWaitingForJoin()) {
THROW_APP_EXCEPTION(err::kappe_disinfection_state_is_wrong, "");
}
@ -264,7 +264,7 @@ void DisinfectionCtrlService::logState() {
snapshot->remainTime = s_remaintime;
snapshot->remainDisinfectant = dwus->getWeight();
snapshot->h2o2Snapshot = s_h2o2Snapshot;
snapshot->ecode = s_error;
AppEventBus::ins()->push(make_shared<AppDisinfectionSnapshotEvent>(snapshot));
}
void DisinfectionCtrlService::traceState() {
@ -391,6 +391,7 @@ void DisinfectionCtrlService::processStateInit(DisinfectionEvent* event) {
s_start_steady_tp = zsteady_clock().now();
s_afterDisinfectantVolume_g = 0;
s_beforeDisinfectantVolume_g = dwus->getWeight();
s_error = 0;
AppEventBus::ins()->push(make_shared<AppDisinfectionStartEvent>(s_sessionId));
GET_SERVICE(WarningLightControler)->setworkFlag(true);
@ -530,6 +531,19 @@ void DisinfectionCtrlService::processStateDisinfection(DisinfectionEvent* event)
*/
changeToNextState();
}
if (dics->WaterSensor_readDeviceBottom()) {
logger->error("kappe_the_bottom_of_the_device_has_water");
s_error = err::kappe_the_bottom_of_the_device_has_water;
sm.changeState(DisinfectionState::error);
}
if (dics->WaterSensor_readEvaporationBin()) {
logger->error("kappe_the_evaporation_bin_has_water");
s_error = err::kappe_the_evaporation_bin_has_water;
sm.changeState(DisinfectionState::error);
}
// AppEventBus
if (PORT.isHasDisinfectantBucket()) {
if (dwus->getWeight() < 10) {
@ -647,3 +661,11 @@ void DisinfectionCtrlService::processStateFinished(DisinfectionEvent* event) {
}
}
}
void DisinfectionCtrlService::processStateError(DisinfectionEvent* event) {
if (event->event == kevent_enter_state) {
tryLogState(true);
logger->error("error state {}", s_error);
AppEventBus::ins()->push(make_shared<AppWarningPromoptEvent>(s_error));
sm.changeState(DisinfectionState::finished);
}
}

4
appsrc/service/app/disinfection_ctrl/disinfection_ctrl_service.hpp

@ -48,7 +48,7 @@ class DisinfectionCtrlService : public enable_shared_from_this<DisinfectionCtrlS
string s_sessionId = {};
zsystem_tp s_start_tp = {};
zsystem_tp s_complete_tp = {};
zsteady_tp s_start_steady_tp = {};
zsteady_tp s_start_steady_tp = {};
zsteady_tp s_lastTakeSnapt = {}; // 上次日志时间
zsteady_tp s_lastComputeDvalueTp = {}; // 上次计算dvalue时间
bool s_isDisinfectionTakeBreak = false;
@ -58,6 +58,7 @@ class DisinfectionCtrlService : public enable_shared_from_this<DisinfectionCtrlS
float s_nlog = {};
int s_beforeDisinfectantVolume_g = {}; // 消毒前消毒剂量
int s_afterDisinfectantVolume_g = {}; // 消毒后消毒剂量
int s_error = 0;
public:
void initialize();
@ -103,6 +104,7 @@ class DisinfectionCtrlService : public enable_shared_from_this<DisinfectionCtrlS
void processStateDehumidificationBeforeDisinfection(DisinfectionEvent* event);
void processStateDehumidificationAfterDisinfection(DisinfectionEvent* event);
void processStateEmpytLiquidFromTheLine(DisinfectionEvent* event);
void processStateError(DisinfectionEvent* event);
void changeToNextState();

73
appsrc/service/app_core.cpp

@ -88,25 +88,43 @@ void AppCore::initialize() {
static string _emessage;
static tp_steady lasttime;
if (_ecode == ecode && _emessage== emessage && tu_steady().elapsedTimeS(lasttime) < 5) {
if (_ecode == ecode && _emessage == emessage && tu_steady().elapsedTimeS(lasttime) < 5) {
return;
}
_ecode = ecode;
_emessage = emessage;
lasttime = steady_clock::now();
// SEND_PROMPT(emessage);
lasttime = steady_clock::now();
wq->enQueue([this]() { //
sleep(5);
logger->warn("AppCore::onException:{},force stop device", DS->getAppExceptionMessage());
GET_SERVICE(DeviceIoControlService)->forceStopDeviceWithoutExc();
});
insertPrompt(Prompt::createWarning(ecode2str(ecode)));
onDeviceStateChange();
});
// shared_ptr<IAppEvent>
AppEventBus::ins()->onEvent.connect([this](shared_ptr<IAppEvent> event) {
auto appWarningPromoptEvent = dynamic_pointer_cast<AppWarningPromoptEvent>(event);
if (appWarningPromoptEvent) {
insertPrompt(Prompt::createWarning(ecode2str(appWarningPromoptEvent->getEcode())));
onDeviceStateChange();
return;
}
auto appPromoptEvent = dynamic_pointer_cast<AppPromoptEvent>(event);
if (appPromoptEvent) {
insertPrompt(Prompt::createInfo(appPromoptEvent->getMessage()));
onDeviceStateChange();
return;
}
});
};
void AppCore::getState(shared_ptr<MsgProcessContext> cxt) {
//
auto& content = cxt->content;
lock_guard<recursive_mutex> lock(warningPromptListMutex);
auto& content = cxt->content;
content["state"] = DS->getDeviceState();
@ -117,10 +135,47 @@ void AppCore::getState(shared_ptr<MsgProcessContext> cxt) {
content["estate"]["ecode"] = DS->getAppExceptionCode();
content["estate"]["state"] = DS->getAppExceptionFlag();
content["estate"]["emessage"] = DS->getAppExceptionMessage();
content["promptNum"] = warningPromptList.size();
}
void AppCore::loop() {
/**
* @brief
*/
void AppCore::promptConfirm(shared_ptr<MsgProcessContext> cxt) {
lock_guard<recursive_mutex> lock(warningPromptListMutex);
string promptId = cxt->params["promptId"];
for (auto it = warningPromptList.begin(); it != warningPromptList.end(); it++) {
if ((*it)->promptId == promptId) {
warningPromptList.erase(it);
break;
}
}
GET_SERVICE(WarningLightControler)->setwarningFlag(false);
}
void AppCore::promptGetAll(shared_ptr<MsgProcessContext> cxt) {
lock_guard<recursive_mutex> lock(warningPromptListMutex);
auto content = cxt->content;
content["prompts"] = json::array();
for (auto& p : warningPromptList) {
content["warningPromptList"].push_back(*p);
}
}
void AppCore::promptGetNext(shared_ptr<MsgProcessContext> cxt) {
lock_guard<recursive_mutex> lock(warningPromptListMutex);
auto content = cxt->content;
if (warningPromptList.size() > 0) {
content["warningPrompt"] = *warningPromptList.front();
}
}
void AppCore::loop() {}
void AppCore::onDeviceStateChange() {
json content;
SEND_CLASS_REPORT("AppCore", "onDeviceStateChange", content);
}
void AppCore::insertPrompt(shared_ptr<Prompt> prompt) {
lock_guard<recursive_mutex> lock(warningPromptListMutex);
warningPromptList.push_back(prompt);
if (prompt->isWarning) GET_SERVICE(WarningLightControler)->setwarningFlag(true);
}

32
appsrc/service/app_core.hpp

@ -33,18 +33,30 @@ namespace iflytop {
using namespace std;
using namespace core;
class WarningPrompt {
class Prompt {
public:
string promptId;
string message;
bool confirmedByUser;
string promptId = UUID().toString();
bool isWarning = false;
string message = "";
string extMessage = "";
bool confirmedByUser = false;
Prompt(bool isWarning, string message) : isWarning(isWarning), message(message) {}
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Prompt, promptId, message, extMessage, confirmedByUser, isWarning);
static shared_ptr<Prompt> createWarning(string message) { return make_shared<Prompt>(true, message); }
static shared_ptr<Prompt> createInfo(string message) { return make_shared<Prompt>(false, message); }
};
class AppCore : public enable_shared_from_this<AppCore> {
THISCLASS(AppCore);
unique_ptr<WorkQueue> wq;
list<shared_ptr<WarningPrompt>> warningPromptList;
unique_ptr<WorkQueue> wq;
list<shared_ptr<Prompt>> warningPromptList;
recursive_mutex warningPromptListMutex;
steady_clock::time_point lastUsrConfirmTime;
public:
AppCore() {};
@ -53,8 +65,16 @@ class AppCore : public enable_shared_from_this<AppCore> {
private:
void getState(shared_ptr<MsgProcessContext> cxt);
void promptConfirm(shared_ptr<MsgProcessContext> cxt);
void promptGetAll(shared_ptr<MsgProcessContext> cxt);
void promptGetNext(shared_ptr<MsgProcessContext> cxt);
// void warningPro();
void dosystem(string order, bool dump);
void loop();
private:
void onDeviceStateChange();
void insertPrompt(shared_ptr<Prompt> prompt);
};
} // namespace iflytop
Loading…
Cancel
Save