-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathcp_app.cpp
More file actions
89 lines (71 loc) · 1.61 KB
/
cp_app.cpp
File metadata and controls
89 lines (71 loc) · 1.61 KB
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
/*
* Copyright (c) 2019-2026 Siddharth Chandrasekaran <sidcha.dev@gmail.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <iostream>
#include <chrono>
#include <thread>
#include <osdp.hpp>
int sample_cp_send_func(void *data, uint8_t *buf, int len)
{
(void)(data);
(void)(buf);
// TODO (user): send buf of len bytes, over the UART channel.
return len;
}
int sample_cp_recv_func(void *data, uint8_t *buf, int len)
{
(void)(data);
(void)(buf);
(void)(len);
// TODO (user): read from UART channel into buf, for upto len bytes.
return 0;
}
osdp_pd_info_t pd_info[] = {
{
.name = "pd[101]",
.baud_rate = 115200,
.address = 101,
.flags = 0,
.id = {},
.cap = nullptr,
.scbk = nullptr,
}
};
static struct osdp_channel cp_channel = {
.data = nullptr,
.recv = sample_cp_recv_func,
.send = sample_cp_send_func,
.flush = nullptr,
.close = nullptr,
};
class EventHandler : public OSDP::ControlPanelEventHandler
{
private:
const char* _message;
public:
explicit EventHandler(const char* message) : _message{message} {}
int event_handler(const OSDP::ControlPanel& cp,
int pd, struct osdp_event *event) override
{
(void)(cp);
std::cout << "PD " << pd << " EVENT: " << event->type << std::endl;
std::cout << _message << std::endl;
return 0;
}
};
int main()
{
OSDP::ControlPanel cp;
cp.logger_init("osdp::cp", OSDP_LOG_DEBUG, NULL);
cp.setup(&cp_channel, 1, pd_info);
EventHandler handler { "Hello world!" };
cp.set_event_callback(&handler);
while (1) {
// your application code.
cp.refresh();
std::this_thread::sleep_for(std::chrono::microseconds(10 * 1000));
}
return 0;
}