-
Notifications
You must be signed in to change notification settings - Fork 3
/
smart_main.cpp
113 lines (96 loc) · 3.05 KB
/
smart_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*!
* -------------------------------------------
* Copyright (c) 2019, Horizon Robotics, Inc.
* All rights reserved.
* \File sample_plugin.cpp
* \Author Songshan Gong
* \Mail songshan.gong@horizon.ai
* \Version 1.0.0.0
* \Date 2019-07-30
* \Brief Sample custom plugin
* \DO NOT MODIFY THIS COMMENT, \
* \WHICH IS AUTO GENERATED BY EDITOR
* -------------------------------------------
*/
#include <signal.h>
#include <unistd.h>
#include <iostream>
#include <sstream>
#include "hbipcplugin/hbipcplugin.h"
#include "hobotlog/hobotlog.hpp"
#include "smartplugin/smartplugin.h"
#include "vioplugin/vioplugin.h"
using horizon::vision::xpluginflow::XPluginAsync;
using horizon::vision::xpluginflow::XPluginFlowMessage;
using horizon::vision::xpluginflow::XPluginFlowMessagePtr;
using std::chrono::milliseconds;
using horizon::vision::xpluginflow::hbipcplugin::HbipcPlugin;
using horizon::vision::xpluginflow::smartplugin::SmartPlugin;
using horizon::vision::xpluginflow::vioplugin::VioPlugin;
struct SmartContext {
std::vector<std::shared_ptr<XPluginAsync> > plugins;
bool exit;
SmartContext() : exit(false) { plugins.clear(); }
};
SmartContext g_ctx;
static void signal_handle(int param) {
std::cout << "recv signal " << param << ", stop" << std::endl;
if (param == SIGINT) {
g_ctx.exit = true;
}
}
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "Usage: smart_main [-i/-d/-w/-f] xroc_config_file"
<< std::endl;
return 0;
}
std::string config_file;
if (argc == 2) {
config_file = std::string(argv[1]);
} else {
std::string log_level(argv[1]);
if (log_level == "-i") {
SetLogLevel(HOBOT_LOG_INFO);
} else if (log_level == "-d") {
SetLogLevel(HOBOT_LOG_DEBUG);
} else if (log_level == "-w") {
SetLogLevel(HOBOT_LOG_WARN);
} else if (log_level == "-e") {
SetLogLevel(HOBOT_LOG_ERROR);
} else if (log_level == "-f") {
SetLogLevel(HOBOT_LOG_FATAL);
} else {
std::cout << "Usage: smart_main [-i/-d/-w/-f] xroc_config_file"
<< std::endl;
return 0;
}
config_file = std::string(argv[2]);
}
signal(SIGINT, signal_handle);
signal(SIGSEGV, signal_handle);
// for 96board: 需要ap侧先从/dev/video3拉去视频流,
// 然后cp vio再启动mipi bypass,暂时可以利用hbipc初始化
// 需要握手(会阻塞)来实现,这里要求hbipcplugin先于vioplugin
// 完成初始化。
// auto hbipc_plg =
// std::make_shared<HbipcPlugin>("./configs/hbipc_config.json");
auto vio_plg = std::make_shared<VioPlugin>("./configs/vio_config.json");
auto smart_plg = std::make_shared<SmartPlugin>(config_file);
// hbipc_plg->Init();
vio_plg->Init();
smart_plg->Init();
// g_ctx.plugins.push_back(hbipc_plg);
g_ctx.plugins.push_back(vio_plg);
g_ctx.plugins.push_back(smart_plg);
for (auto& plugin : g_ctx.plugins) {
plugin->Start();
}
while (!g_ctx.exit) {
std::this_thread::sleep_for(milliseconds(40));
}
for (auto& plugin : g_ctx.plugins) {
plugin->Stop();
}
return 0;
}