提交 d420627b authored 作者: blu's avatar blu

big refacting of communitation architect

上级 149e2b3f
...@@ -55,7 +55,16 @@ class EvDaemon{ ...@@ -55,7 +55,16 @@ class EvDaemon{
/// tracking sub-systems: evmgr, evpuller, evpusher, evml*, evslicer etc. /// tracking sub-systems: evmgr, evpuller, evpusher, evml*, evslicer etc.
json mapSubSystems; json mapSubSystems;
int reloadCfg() { int reloadCfg(string subModGid) {
int bootType = 0;
if(subModGid == "ALL") {
bootType = 1;
}else if(subModGid.empty()){
bootType = 2;
}else{
bootType = 3;
}
int ret = LVDB::getSn(this->info); int ret = LVDB::getSn(this->info);
if(ret < 0) { if(ret < 0) {
spdlog::error("evdaemon {} failed to get info", this->devSn); spdlog::error("evdaemon {} failed to get info", this->devSn);
...@@ -92,7 +101,7 @@ class EvDaemon{ ...@@ -92,7 +101,7 @@ class EvDaemon{
this->peerData["config"][peerId] = v; this->peerData["config"][peerId] = v;
if(this->peerData["status"].count(peerId) == 0||this->peerData["status"][peerId] == 0) { if(this->peerData["status"].count(peerId) == 0||this->peerData["status"][peerId] == 0) {
this->peerData["status"][peerId] = 0; this->peerData["status"][peerId] = 0;
if(bBootstrap) { if(bootType == 1 || (bootType == 3 && subModGid == peerId)) {
ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid); ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid);
if(ret != 0) { if(ret != 0) {
spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId); spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId);
...@@ -108,7 +117,6 @@ class EvDaemon{ ...@@ -108,7 +117,6 @@ class EvDaemon{
} }
// startup other submodules // startup other submodules
json &ipcs = v["ipcs"]; json &ipcs = v["ipcs"];
for(auto &ipc : ipcs) { for(auto &ipc : ipcs) {
json &modules = ipc["modules"]; json &modules = ipc["modules"];
...@@ -130,7 +138,7 @@ class EvDaemon{ ...@@ -130,7 +138,7 @@ class EvDaemon{
if(this->peerData["status"].count(peerId) == 0||this->peerData["status"][peerId] == 0) { if(this->peerData["status"].count(peerId) == 0||this->peerData["status"][peerId] == 0) {
this->peerData["status"][peerId] = 0; this->peerData["status"][peerId] = 0;
if(bBootstrap) { if(bootType == 1 || (bootType == 3 && subModGid == peerId)){
ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid); ret = zmqhelper::forkSubsystem(devSn, peerId, portRouter, pid);
if(ret != 0) { if(ret != 0) {
spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId); spdlog::error("evdaemon {} failed to fork subsystem: {}", devSn, peerId);
...@@ -182,7 +190,13 @@ class EvDaemon{ ...@@ -182,7 +190,13 @@ class EvDaemon{
while(true) { while(true) {
if(this->bReload) { if(this->bReload) {
cleanupSubSystems(); cleanupSubSystems();
int ret = reloadCfg(); int ret;
if(bBootstrap){
ret = reloadCfg("ALL");
}else{
ret = reloadCfg("");
}
if(ret != 0) { if(ret != 0) {
cleanupSubSystems(); cleanupSubSystems();
}else{ }else{
...@@ -197,7 +211,7 @@ class EvDaemon{ ...@@ -197,7 +211,7 @@ class EvDaemon{
thMon.detach(); thMon.detach();
} }
int startSubModule(string peerId){ int startSubModule(string peerId) {
int ret = 0; int ret = 0;
if(peerData["status"].count(peerId) == 0 || peerData["status"][peerId] == 0) { if(peerData["status"].count(peerId) == 0 || peerData["status"][peerId] == 0) {
// //
...@@ -239,7 +253,6 @@ class EvDaemon{ ...@@ -239,7 +253,6 @@ class EvDaemon{
} }
return 0; return 0;
} }
int handleMsg(vector<vector<uint8_t> > &body) int handleMsg(vector<vector<uint8_t> > &body)
...@@ -275,15 +288,19 @@ class EvDaemon{ ...@@ -275,15 +288,19 @@ class EvDaemon{
if(peerData["pids"].count(selfId) != 0) { if(peerData["pids"].count(selfId) != 0) {
peerData["pids"].erase(selfId); peerData["pids"].erase(selfId);
} }
// if(peerData["config"].count(selfId) != 0) {
// peerData["config"].erase(selfId);
// }
spdlog::warn("evdaemon {} peer disconnected: {}", devSn, selfId); spdlog::warn("evdaemon {} peer disconnected: {}", devSn, selfId);
// restart this module
if(bBootstrap) { if(bBootstrap){
startSubModule(selfId); ret = reloadCfg(selfId);
}else{
ret = reloadCfg("");
}
if(ret != 0) {
cleanupSubSystems();
} }
} }
if(ret < 0) { if(ret < 0) {
......
...@@ -179,6 +179,8 @@ private: ...@@ -179,6 +179,8 @@ private:
detPara.entropy = evmlmotion["entropy"]; detPara.entropy = evmlmotion["entropy"];
} }
spdlog::info("evmlmotion {} detection params: entropy {}, area {}, thresh {}", selfId, detPara.entropy, detPara.area, detPara.thre);
// setup sub // setup sub
pSubCtx = zmq_ctx_new(); pSubCtx = zmq_ctx_new();
pSub = zmq_socket(pSubCtx, ZMQ_SUB); pSub = zmq_socket(pSubCtx, ZMQ_SUB);
...@@ -411,22 +413,23 @@ private: ...@@ -411,22 +413,23 @@ private:
first = false; first = false;
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
matShow3 = gray.clone(); matShow3 = gray.clone();
matShow2 = origin; matShow2 = origin;
#endif #endif
evtStartTm = chrono::system_clock::now(); evtStartTm = chrono::system_clock::now();
// TODO: AVG // TODO: AVG
// cv::accumulateWeighted(gray, avg, 0.5); // cv::accumulateWeighted(gray, avg, 0.5);
cv::absdiff(gray, avg, thresh); cv::absdiff(gray, avg, thresh);
#ifdef DEBUG
avg = gray.clone(); avg = gray.clone();
#endif
if(!detect || fent < detPara.entropy){ if(!detect || fent < detPara.entropy){
return; return;
} }
// TODO:
cv::threshold(thresh, gray, detPara.thre, 255, cv::THRESH_BINARY); cv::threshold(thresh, gray, detPara.thre, 255, cv::THRESH_BINARY);
cv::dilate(gray, thresh, cv::Mat(), cv::Point(-1,-1), 2); cv::dilate(gray, thresh, cv::Mat(), cv::Point(-1,-1), 2);
...@@ -445,14 +448,16 @@ private: ...@@ -445,14 +448,16 @@ private:
else { else {
hasEvent = true; hasEvent = true;
evtCnt++; evtCnt++;
#ifdef DEBUG #ifdef DEBUG
cv::putText(origin, "motion detected", cv::Point(10, 20), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(0,0,255),2); cv::putText(origin, "motion detected", cv::Point(10, 20), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(0,0,255),2);
#endif #endif
break; break;
} }
} //end for } //end for
spdlog::info("evmlmotion {} contours {} size {} hasEvent {}", selfId, cnts.size(), cv::contourArea(cnts[i]), hasEvent); spdlog::info("evmlmotion {} contours {} area {}, thresh {} hasEvent {}", selfId, cnts.size(), cnts.size() == 0? 0:cv::contourArea(cnts[i]), detPara.area, hasEvent);
// business logic for event // business logic for event
auto dura = chrono::duration_cast<chrono::seconds>(evtStartTm - evtStartTmLast).count(); auto dura = chrono::duration_cast<chrono::seconds>(evtStartTm - evtStartTmLast).count();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论