forked from ifm/ifm3d-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-pcicclient_async_messages.cpp
92 lines (80 loc) · 2.46 KB
/
ex-pcicclient_async_messages.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
// -*- c++ -*-
/*
* Copyright (C) 2017 Kuhn & Völkel GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distribted on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// ex-pcicclient_async_messages.cpp
//
// Shows how to use the PCICClient module to receive asynchronous
// notification (and error) messages from the camera.
//
#include <iostream>
#include <string>
#include <thread>
#include <ifm3d/camera.h>
#include <ifm3d/pcicclient.h>
// Camera configuration string:
// * Create two applications with indices 1 and 2
// and activate application with index 2
const char *config = R"CONFIG(
{
"ifm3d":
{
"Device":
{
"ActiveApplication": "2"
},
"Apps":
[
{
"Name": "PCICClient Example 2a",
"Description": "First application",
"Index" : "1"
},
{
"Name": "PCICClient Example 2b",
"Description": "Second application",
"Index" : "2"
}
]
}
}
)CONFIG";
int main(int argc, char** argv)
{
// Create camera
ifm3d::Camera::Ptr cam = std::make_shared<ifm3d::Camera>();
// Configure two applications on the camera
// cam->FromJSONStr(config);
// Create pcic interface
ifm3d::PCICClient::Ptr pcic = std::make_shared<ifm3d::PCICClient>(cam);
// Set notification (and error) callbacks, which simply print received messages
pcic->SetNotificationCallback([](const std::string& notification)
{
std::cout << "Notification: " << notification << std::endl;
});
pcic->SetErrorCallback([](const std::string& error)
{
std::cout << "Error: " << error << std::endl;
});
// Switch between applications (and receive notification 000500000)
std::cout << "Switch to application 1" << std::endl;
pcic->Call("a01");
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "Switch to application 2" << std::endl;
pcic->Call("a02");
std::this_thread::sleep_for(std::chrono::seconds(1));
return 0;
}