-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathMessageBuilder.cpp
More file actions
179 lines (155 loc) · 6.03 KB
/
MessageBuilder.cpp
File metadata and controls
179 lines (155 loc) · 6.03 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* MessageBuilder.cpp
* Copyright (C) 2013 Simon Newton
*
* A class to simplify some of the E1.33 packet building operations.
*/
#include <string>
#include "ola/acn/ACNVectors.h"
#include "ola/acn/CID.h"
#include "ola/e133/MessageBuilder.h"
#include "ola/io/IOStack.h"
#include "ola/rdm/RDMCommandSerializer.h"
#include "ola/rdm/UID.h"
#include "libs/acn/BrokerPDU.h"
#include "libs/acn/E133PDU.h"
#include "libs/acn/RDMPDU.h"
#include "libs/acn/RootPDU.h"
#include "libs/acn/RPTPDU.h"
#include "libs/acn/RPTRequestPDU.h"
#include "libs/acn/E133StatusPDU.h"
#include "libs/acn/PreamblePacker.h"
namespace ola {
namespace e133 {
using ola::acn::CID;
using ola::io::IOStack;
using ola::acn::BrokerPDU;
using ola::acn::E133PDU;
using ola::acn::PreamblePacker;
using ola::acn::RootPDU;
using ola::acn::RPTPDU;
using ola::rdm::UID;
MessageBuilder::MessageBuilder(const CID &cid, const string &source_name)
: m_cid(cid),
m_source_name(source_name),
// The Max sized RDM packet is 256 bytes, E1.33 adds 118 bytes of
// headers.
m_memory_pool(400) {
}
/**
* Append a RDM PDU Header onto this packet
*/
void MessageBuilder::PrependRDMHeader(IOStack *packet) {
ola::acn::RDMPDU::PrependPDU(packet);
}
/**
* Build a TCP E1.33 RDM Command PDU response.
*/
void MessageBuilder::BuildTCPRDMCommandPDU(IOStack *packet,
const ola::rdm::RDMRequest *request,
const UID *rpt_destination_uid,
uint16_t source_endpoint_id,
uint16_t destination_endpoint_id,
uint32_t sequence_number) {
ola::rdm::RDMCommandSerializer::Write(*request, packet);
ola::acn::RDMPDU::PrependPDU(packet);
ola::acn::RPTRequestPDU::PrependPDU(packet);
RPTPDU::PrependPDU(packet, ola::acn::VECTOR_RPT_REQUEST,
request->SourceUID(), source_endpoint_id,
*rpt_destination_uid, destination_endpoint_id,
sequence_number);
RootPDU::PrependPDU(packet, ola::acn::VECTOR_ROOT_RPT, m_cid, true);
PreamblePacker::AddTCPPreamble(packet);
}
/**
* Build a NULL TCP packet. These packets can be used for heartbeats.
*/
void MessageBuilder::BuildNullTCPPacket(IOStack *packet) {
RootPDU::PrependPDU(packet, ola::acn::VECTOR_ROOT_NULL, m_cid);
PreamblePacker::AddTCPPreamble(packet);
}
/**
* Build a Broker Fetch Client List TCP packet.
*/
void MessageBuilder::BuildBrokerFetchClientListTCPPacket(IOStack *packet) {
BrokerPDU::PrependPDU(packet, ola::acn::VECTOR_BROKER_FETCH_CLIENT_LIST);
RootPDU::PrependPDU(packet, ola::acn::VECTOR_ROOT_BROKER, m_cid, true);
PreamblePacker::AddTCPPreamble(packet);
}
/**
* Build a Broker NULL TCP packet. These packets can be used for broker heartbeats.
*/
void MessageBuilder::BuildBrokerNullTCPPacket(IOStack *packet) {
BrokerPDU::PrependPDU(packet, ola::acn::VECTOR_BROKER_NULL);
RootPDU::PrependPDU(packet, ola::acn::VECTOR_ROOT_BROKER, m_cid, true);
PreamblePacker::AddTCPPreamble(packet);
}
/**
* Build a TCP E1.33 Status PDU response. This should really only be used with
* SC_E133_ACK.
*/
void MessageBuilder::BuildTCPE133StatusPDU(ola::io::IOStack *packet,
uint32_t sequence_number,
uint16_t endpoint_id,
E133StatusCode status_code,
const string &description) {
ola::acn::E133StatusPDU::PrependPDU(
packet, status_code, description);
BuildTCPRootE133(
packet, ola::acn::VECTOR_FRAMING_STATUS,
sequence_number, endpoint_id);
}
/**
* Build an E1.33 Status PDU response
*/
void MessageBuilder::BuildUDPE133StatusPDU(ola::io::IOStack *packet,
uint32_t sequence_number,
uint16_t endpoint_id,
E133StatusCode status_code,
const string &description) {
ola::acn::E133StatusPDU::PrependPDU(
packet, status_code, description);
BuildUDPRootE133(
packet, ola::acn::VECTOR_FRAMING_STATUS,
sequence_number, endpoint_id);
}
/**
* Append an E133PDU, a RootPDU and the TCP preamble to a packet.
*/
void MessageBuilder::BuildTCPRootE133(IOStack *packet,
uint32_t vector,
uint32_t sequence_number,
uint16_t endpoint_id) {
E133PDU::PrependPDU(packet, vector, m_source_name, sequence_number,
endpoint_id);
RootPDU::PrependPDU(packet, ola::acn::VECTOR_ROOT_RPT, m_cid);
PreamblePacker::AddTCPPreamble(packet);
}
/**
* Append an E133PDU, a RootPDU and the UDP preamble to a packet.
*/
void MessageBuilder::BuildUDPRootE133(IOStack *packet,
uint32_t vector,
uint32_t sequence_number,
uint16_t endpoint_id) {
E133PDU::PrependPDU(packet, vector, m_source_name, sequence_number,
endpoint_id);
RootPDU::PrependPDU(packet, ola::acn::VECTOR_ROOT_RPT, m_cid);
PreamblePacker::AddUDPPreamble(packet);
}
} // namespace e133
} // namespace ola