Skip to content

Commit b93b8e0

Browse files
authored
Merge pull request #1950 from peternewman/e1.33-cherry-pick
E1.33 cherry pick part 4
2 parents f87e79d + 10d264a commit b93b8e0

29 files changed

+1664
-16
lines changed

include/ola/e133/MessageBuilder.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <ola/e133/E133Enums.h>
2828
#include <ola/io/IOStack.h>
2929
#include <ola/io/MemoryBlockPool.h>
30+
#include <ola/rdm/RDMCommand.h>
3031
#include <string>
3132

3233
namespace ola {
@@ -46,8 +47,18 @@ class MessageBuilder {
4647

4748
void PrependRDMHeader(IOStack *packet);
4849

50+
void BuildTCPRDMCommandPDU(IOStack *packet,
51+
ola::rdm::RDMRequest *request,
52+
uint16_t source_endpoint_id,
53+
uint16_t destination_endpoint_id,
54+
uint32_t sequence_number);
55+
4956
void BuildNullTCPPacket(IOStack *packet);
5057

58+
void BuildBrokerFetchClientListTCPPacket(IOStack *packet);
59+
60+
void BuildBrokerNullTCPPacket(IOStack *packet);
61+
5162
void BuildTCPE133StatusPDU(IOStack *packet,
5263
uint32_t sequence_number, uint16_t endpoint_id,
5364
ola::e133::E133StatusCode status_code,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This program is free software; you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License as published by
4+
* the Free Software Foundation; either version 2 of the License, or
5+
* (at your option) any later version.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU Library General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program; if not, write to the Free Software
14+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
*
16+
* BrokerFetchClientListPDU.cpp
17+
* The BrokerFetchClientListPDU
18+
* Copyright (C) 2023 Peter Newman
19+
*/
20+
21+
#include "libs/acn/BrokerFetchClientListPDU.h"
22+
23+
#include <ola/network/NetworkUtils.h>
24+
#include <ola/acn/ACNVectors.h>
25+
26+
namespace ola {
27+
namespace acn {
28+
29+
using ola::network::HostToNetwork;
30+
31+
void BrokerFetchClientListPDU::PrependPDU(ola::io::IOStack *stack) {
32+
uint16_t vector = HostToNetwork(static_cast<uint16_t>(
33+
VECTOR_BROKER_FETCH_CLIENT_LIST));
34+
stack->Write(reinterpret_cast<uint8_t*>(&vector), sizeof(vector));
35+
PrependFlagsAndLength(stack, VFLAG_MASK | HFLAG_MASK | DFLAG_MASK, true);
36+
}
37+
} // namespace acn
38+
} // namespace ola
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This program is free software; you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License as published by
4+
* the Free Software Foundation; either version 2 of the License, or
5+
* (at your option) any later version.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU Library General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program; if not, write to the Free Software
14+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
*
16+
* BrokerFetchClientListPDU.h
17+
* The BrokerFetchClientListPDU class
18+
* Copyright (C) 2023 Peter Newman
19+
*/
20+
21+
#ifndef LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_
22+
#define LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_
23+
24+
#include <ola/io/IOStack.h>
25+
26+
#include "libs/acn/PDU.h"
27+
28+
namespace ola {
29+
namespace acn {
30+
31+
class BrokerFetchClientListPDU : public PDU {
32+
public:
33+
explicit BrokerFetchClientListPDU(unsigned int vector):
34+
PDU(vector, TWO_BYTES, true) {}
35+
36+
unsigned int HeaderSize() const { return 0; }
37+
bool PackHeader(OLA_UNUSED uint8_t *data,
38+
unsigned int *length) const {
39+
*length = 0;
40+
return true;
41+
}
42+
void PackHeader(OLA_UNUSED ola::io::OutputStream *stream) const {}
43+
44+
unsigned int DataSize() const { return 0; }
45+
bool PackData(OLA_UNUSED uint8_t *data,
46+
unsigned int *length) const {
47+
*length = 0;
48+
return true;
49+
}
50+
void PackData(OLA_UNUSED ola::io::OutputStream *stream) const {}
51+
52+
static void PrependPDU(ola::io::IOStack *stack);
53+
};
54+
} // namespace acn
55+
} // namespace ola
56+
#endif // LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* This program is free software; you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License as published by
4+
* the Free Software Foundation; either version 2 of the License, or
5+
* (at your option) any later version.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU Library General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program; if not, write to the Free Software
14+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
*
16+
* BrokerFetchClientListPDUTest.cpp
17+
* Test fixture for the BrokerFetchClientListPDU class
18+
* Copyright (C) 2023 Peter Newman
19+
*/
20+
21+
#include <cppunit/extensions/HelperMacros.h>
22+
23+
#include "ola/Logging.h"
24+
#include "ola/io/IOQueue.h"
25+
#include "ola/io/IOStack.h"
26+
#include "ola/io/OutputStream.h"
27+
#include "ola/network/NetworkUtils.h"
28+
#include "ola/testing/TestUtils.h"
29+
#include "libs/acn/PDUTestCommon.h"
30+
#include "libs/acn/BrokerFetchClientListPDU.h"
31+
32+
namespace ola {
33+
namespace acn {
34+
35+
using ola::acn::BrokerFetchClientListPDU;
36+
using ola::io::IOQueue;
37+
using ola::io::IOStack;
38+
using ola::io::OutputStream;
39+
using ola::network::HostToNetwork;
40+
41+
class BrokerFetchClientListPDUTest: public CppUnit::TestFixture {
42+
CPPUNIT_TEST_SUITE(BrokerFetchClientListPDUTest);
43+
CPPUNIT_TEST(testSimpleBrokerFetchClientListPDU);
44+
CPPUNIT_TEST(testSimpleBrokerFetchClientListPDUToOutputStream);
45+
CPPUNIT_TEST(testPrepend);
46+
CPPUNIT_TEST_SUITE_END();
47+
48+
public:
49+
void testSimpleBrokerFetchClientListPDU();
50+
void testSimpleBrokerFetchClientListPDUToOutputStream();
51+
void testPrepend();
52+
53+
void setUp() {
54+
ola::InitLogging(ola::OLA_LOG_DEBUG, ola::OLA_LOG_STDERR);
55+
}
56+
57+
private:
58+
static const uint16_t TEST_VECTOR;
59+
};
60+
61+
CPPUNIT_TEST_SUITE_REGISTRATION(BrokerFetchClientListPDUTest);
62+
63+
const uint16_t BrokerFetchClientListPDUTest::TEST_VECTOR = 39;
64+
65+
66+
/*
67+
* Test that packing a BrokerFetchClientListPDU works.
68+
*/
69+
void BrokerFetchClientListPDUTest::testSimpleBrokerFetchClientListPDU() {
70+
BrokerFetchClientListPDU pdu(TEST_VECTOR);
71+
72+
OLA_ASSERT_EQ(0u, pdu.HeaderSize());
73+
OLA_ASSERT_EQ(0u, pdu.DataSize());
74+
OLA_ASSERT_EQ(5u, pdu.Size());
75+
76+
unsigned int size = pdu.Size();
77+
uint8_t *data = new uint8_t[size];
78+
unsigned int bytes_used = size;
79+
OLA_ASSERT(pdu.Pack(data, &bytes_used));
80+
OLA_ASSERT_EQ(size, bytes_used);
81+
82+
// spot check the data
83+
OLA_ASSERT_EQ((uint8_t) 0xf0, data[0]);
84+
// bytes_used is technically data[1] and data[2] if > 255
85+
OLA_ASSERT_EQ((uint8_t) bytes_used, data[2]);
86+
uint16_t actual_value;
87+
memcpy(&actual_value, data + 3, sizeof(actual_value));
88+
OLA_ASSERT_EQ(HostToNetwork(TEST_VECTOR), actual_value);
89+
90+
// test undersized buffer
91+
bytes_used = size - 1;
92+
OLA_ASSERT_FALSE(pdu.Pack(data, &bytes_used));
93+
OLA_ASSERT_EQ(0u, bytes_used);
94+
95+
// test oversized buffer
96+
bytes_used = size + 1;
97+
OLA_ASSERT(pdu.Pack(data, &bytes_used));
98+
OLA_ASSERT_EQ(size, bytes_used);
99+
delete[] data;
100+
}
101+
102+
/*
103+
* Test that writing to an output stream works.
104+
*/
105+
void BrokerFetchClientListPDUTest::
106+
testSimpleBrokerFetchClientListPDUToOutputStream() {
107+
BrokerFetchClientListPDU pdu(TEST_VECTOR);
108+
109+
OLA_ASSERT_EQ(0u, pdu.HeaderSize());
110+
OLA_ASSERT_EQ(0u, pdu.DataSize());
111+
OLA_ASSERT_EQ(5u, pdu.Size());
112+
113+
IOQueue output;
114+
OutputStream stream(&output);
115+
pdu.Write(&stream);
116+
OLA_ASSERT_EQ(5u, output.Size());
117+
118+
uint8_t *pdu_data = new uint8_t[output.Size()];
119+
unsigned int pdu_size = output.Peek(pdu_data, output.Size());
120+
OLA_ASSERT_EQ(output.Size(), pdu_size);
121+
122+
uint8_t EXPECTED[] = {
123+
0xf0, 0x00, 0x05,
124+
0, 39
125+
};
126+
OLA_ASSERT_DATA_EQUALS(EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size);
127+
output.Pop(output.Size());
128+
delete[] pdu_data;
129+
}
130+
131+
132+
void BrokerFetchClientListPDUTest::testPrepend() {
133+
IOStack stack;
134+
BrokerFetchClientListPDU::PrependPDU(&stack);
135+
136+
unsigned int length = stack.Size();
137+
uint8_t *buffer = new uint8_t[length];
138+
OLA_ASSERT(stack.Read(buffer, length));
139+
140+
const uint8_t expected_data[] = {
141+
0xf0, 0x00, 0x05,
142+
0, 0x06
143+
};
144+
OLA_ASSERT_DATA_EQUALS(expected_data, sizeof(expected_data), buffer, length);
145+
delete[] buffer;
146+
}
147+
} // namespace acn
148+
} // namespace ola

libs/acn/HeaderSet.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "libs/acn/E133Header.h"
2929
#include "libs/acn/LLRPHeader.h"
3030
#include "libs/acn/RootHeader.h"
31+
#include "libs/acn/RPTHeader.h"
3132
#include "libs/acn/TransportHeader.h"
3233

3334
namespace ola {
@@ -60,14 +61,18 @@ class HeaderSet {
6061
const LLRPHeader &GetLLRPHeader() const { return m_llrp_header; }
6162
void SetLLRPHeader(const LLRPHeader &header) { m_llrp_header = header; }
6263

64+
const RPTHeader &GetRPTHeader() const { return m_rpt_header; }
65+
void SetRPTHeader(const RPTHeader &header) { m_rpt_header = header; }
66+
6367
bool operator==(const HeaderSet &other) const {
6468
return (
6569
m_transport_header == other.m_transport_header &&
6670
m_root_header == other.m_root_header &&
6771
m_e131_header == other.m_e131_header &&
6872
m_e133_header == other.m_e133_header &&
6973
m_dmp_header == other.m_dmp_header &&
70-
m_llrp_header == other.m_llrp_header);
74+
m_llrp_header == other.m_llrp_header &&
75+
m_rpt_header == other.m_rpt_header);
7176
}
7277

7378
private:
@@ -77,6 +82,7 @@ class HeaderSet {
7782
E133Header m_e133_header;
7883
DMPHeader m_dmp_header;
7984
LLRPHeader m_llrp_header;
85+
RPTHeader m_rpt_header;
8086
};
8187
} // namespace acn
8288
} // namespace ola

0 commit comments

Comments
 (0)