-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget_bluetooth.cpp
46 lines (35 loc) · 1019 Bytes
/
target_bluetooth.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
#include <BluetoothSerial.h>
#include "kiss.h"
#include "target_bluetooth.h"
BluetoothSerial SerialBT;
target_bluetooth::target_bluetooth(QueueHandle_t out, Print *const p, const int id, const std::string & pin, const std::string & callsign) :
target(out, p, id)
{
SerialBT.setPin(pin.c_str());
SerialBT.enableSSP();
has_device = SerialBT.begin(("ArdrinoAX.25 " + callsign).c_str());
if (has_device)
p->println(F("BT enabled"));
else
p->println(F("BT device missing"));
}
target_bluetooth::~target_bluetooth()
{
}
std::optional<target_msg_t> target_bluetooth::wait_for_receive_packet()
{
if (!has_device)
return { };
auto msg = wait_for_kiss(SerialBT);
auto unwrapped = unwrap_kiss(msg);
if (unwrapped.has_value() == false)
return { };
return { { id, new std::vector<uint8_t>(unwrapped.value()) } };
}
void target_bluetooth::send_message(const target_msg_t & msg)
{
if (!has_device)
return;
auto wrapped = wrap_kiss(*msg.data);
SerialBT.write(wrapped.data(), wrapped.size());
}