@@ -15,7 +15,7 @@ class BootupMonitor{
15
15
const std::string IP;
16
16
const int wait_time; // in seconds
17
17
18
- BootupMonitor (ifm3d::O3R::Ptr o3r_, int timeout_ = 25 , int wait_time_ = 0.5 ) :
18
+ BootupMonitor (ifm3d::O3R::Ptr o3r_, int timeout_ = 25 , int wait_time_ = 1 ) :
19
19
o3r (o3r_),
20
20
timeout (timeout_),
21
21
IP (o3r->IP ()),
@@ -29,64 +29,39 @@ class BootupMonitor{
29
29
auto start = std::chrono::steady_clock::now ();
30
30
ifm3d::json config;
31
31
do {
32
- // This "ping" function will only work on linux-based systems.
33
- // Since this is simply an example on how to monitor the proper
34
- // bootup of an O3R, Windows users can skip this step.
35
- if (! Ping_ () ){
36
- std::clog << " Awaiting successful 'ping' from VPU" << std::endl;
32
+ try {
33
+ config = o3r-> Get ();
34
+ std::clog << " Connected. " << std::endl;
35
+ } catch (ifm3d::Error& e ){
36
+ std::clog << " Awaiting data from VPU... " << std::endl;
37
37
}
38
- else {
39
- try {
40
- config = o3r->Get ();
41
- std::clog << " Connected." << std::endl;
42
- }catch (ifm3d::Error& e){
43
- std::clog << " Awaiting data from VPU..." << std::endl;
44
- }
45
- if (!config.empty ()){
46
- std::clog << " Checking the init stages." << std::endl;
47
- auto conf_init_stages = config[" /device/diagnostic/confInitStages" _json_pointer];
48
- std::clog << conf_init_stages << std::endl;
49
- for (auto it : conf_init_stages)
38
+ if (!config.empty ()){
39
+ std::clog << " Checking the init stages." << std::endl;
40
+ auto conf_init_stages = config[" /device/diagnostic/confInitStages" _json_pointer];
41
+ std::clog << conf_init_stages << std::endl;
42
+ for (auto it : conf_init_stages)
43
+ {
44
+ if (it == " applications" ){
45
+ std::clog << " VPU fully booted." << std::endl;
46
+ RetrieveBootDiagnostic_ ();
47
+ return true ;
48
+ }
49
+ if (it == " ports" ){
50
+ std::clog << " Ports recognized." << std::endl;
51
+ }
52
+ else if (it == " device" )
50
53
{
51
- if (it == " applications" ){
52
- std::clog << " VPU fully booted." << std::endl;
53
- RetrieveBootDiagnostic_ ();
54
- return true ;
55
- }
56
- if (it == " ports" ){
57
- std::clog << " Ports recognized." << std::endl;
58
- }
59
- else if (it == " device" )
60
- {
61
- std::clog << " Device recognized." << std::endl;
62
- }
54
+ std::clog << " Device recognized." << std::endl;
63
55
}
64
- std::this_thread::sleep_for (std::chrono::seconds (wait_time));
65
56
}
66
-
67
57
}
58
+ std::this_thread::sleep_for (std::chrono::seconds (wait_time));
59
+
68
60
}while (std::chrono::steady_clock::now () - start < std::chrono::seconds (timeout));
69
61
throw std::runtime_error (" Process timed out waiting for the VPU to boot." );
70
62
}
71
63
72
64
private:
73
- // Linux-only pinging.
74
- bool Ping_ ()
75
- {
76
- char ip[IP.length () + 1 ];
77
- strcpy (ip, IP.c_str ());
78
- char ping[100 ] = " ping -c1 -s1 " ;
79
- char * command = std::strcat (ping, std::strcat (ip, " > /dev/null 2>&1" ));
80
-
81
- int x = std::system (command);
82
- if (x==0 ){
83
- std::clog << " Ping successful" << std::endl;
84
- return true ;
85
- }else {
86
- std::clog <<" Ping failed" << std::endl;
87
- return false ;
88
- }
89
- }
90
65
void RetrieveBootDiagnostic_ ()
91
66
{
92
67
auto active_diag = o3r->GetDiagnosticFiltered (ifm3d::json::parse (R"( {"state": "active"})" ))[" /events" _json_pointer];
0 commit comments