-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample-tx.cpp
71 lines (55 loc) · 1.95 KB
/
sample-tx.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
#include <iostream>
#include <array>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/udp.hpp>
#include <boost/asio/placeholders.hpp>
#include <boost/bind/bind.hpp>
#include "nfiniity_cube_radio.pb.h"
using namespace std;
namespace
{
string cube_ip = "127.0.0.1";
}
class CubeEvk
{
private:
boost::asio::io_service &io;
boost::asio::ip::udp::socket tx_socket;
public:
CubeEvk(boost::asio::io_service& io);
void send_data(string payload);
};
CubeEvk::CubeEvk(boost::asio::io_service& io)
: io(io), tx_socket(io)
{
static constexpr unsigned int cube_evk_radio_port_tx = 33210;
boost::asio::ip::address radio_ip = boost::asio::ip::address::from_string(cube_ip);
const boost::asio::ip::udp::endpoint radio_endpoint_tx(radio_ip, cube_evk_radio_port_tx);
tx_socket.connect(radio_endpoint_tx);
}
void CubeEvk::send_data(string payload)
{
unique_ptr<LinkLayerTransmission> transmission{new LinkLayerTransmission()};
array<uint8_t, 6> source_addr = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
array<uint8_t, 6> destination_addr = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
transmission->set_source(source_addr.data(), source_addr.size());
transmission->set_destination(destination_addr.data(), destination_addr.size());
transmission->set_priority(LinkLayerPriority::BEST_EFFORT);
transmission->set_payload(payload);
CommandRequest command;
command.set_allocated_linklayer_tx(transmission.release());
std::string serializedTransmission;
command.SerializeToString(&serializedTransmission);
tx_socket.send(boost::asio::buffer(serializedTransmission));
}
int main(int argc, char* argv[])
{
boost::asio::io_service io;
CubeEvk cube(io);
string data = ">>"; // we need minimum data of 2 bytes
for(int idx = 1; idx < argc; ++idx)
data += string(argv[idx]) + " ";
cout << "Sending: " << data << endl;
cube.send_data(data);
return 0;
}