Skip to content

Commit 0fff671

Browse files
authored
Merge pull request #1957 from peternewman/e1.33-cherry-pick
E1.33 cherry pick v
2 parents b93b8e0 + edb1d1a commit 0fff671

32 files changed

+1679
-46
lines changed

common/rdm/UIDTest.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ using ola::rdm::UIDSet;
3434
class UIDTest: public CppUnit::TestFixture {
3535
CPPUNIT_TEST_SUITE(UIDTest);
3636
CPPUNIT_TEST(testUID);
37+
CPPUNIT_TEST(testRPTUID);
3738
CPPUNIT_TEST(testUIDInequalities);
3839
CPPUNIT_TEST(testUIDSet);
3940
CPPUNIT_TEST(testUIDSetUnion);
@@ -43,6 +44,7 @@ class UIDTest: public CppUnit::TestFixture {
4344

4445
public:
4546
void testUID();
47+
void testRPTUID();
4648
void testUIDInequalities();
4749
void testUIDSet();
4850
void testUIDSetUnion();
@@ -58,6 +60,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(UIDTest);
5860
*/
5961
void UIDTest::testUID() {
6062
UID uid(1, 2);
63+
OLA_ASSERT_FALSE(uid.IsBroadcast());
64+
OLA_ASSERT_FALSE(uid.IsVendorcast());
6165
UID uid2 = uid;
6266
OLA_ASSERT_EQ(uid, uid2);
6367
OLA_ASSERT_FALSE(uid != uid2);
@@ -84,9 +88,12 @@ void UIDTest::testUID() {
8488

8589
UID all_devices = UID::AllDevices();
8690
UID manufacturer_devices = UID::VendorcastAddress(0x52);
91+
UID manufacturer_devices2 = UID::VendorcastAddress(uid);
8792
OLA_ASSERT_EQ(string("ffff:ffffffff"), all_devices.ToString());
8893
OLA_ASSERT_EQ(string("0052:ffffffff"),
8994
manufacturer_devices.ToString());
95+
OLA_ASSERT_EQ(string("0001:ffffffff"),
96+
manufacturer_devices2.ToString());
9097
OLA_ASSERT_EQ(all_devices.ManufacturerId(),
9198
static_cast<uint16_t>(0xffff));
9299
OLA_ASSERT_EQ(all_devices.DeviceId(),
@@ -95,8 +102,16 @@ void UIDTest::testUID() {
95102
static_cast<uint16_t>(0x0052));
96103
OLA_ASSERT_EQ(manufacturer_devices.DeviceId(),
97104
static_cast<uint32_t>(0xffffffff));
105+
OLA_ASSERT_EQ(manufacturer_devices2.ManufacturerId(),
106+
static_cast<uint16_t>(0x0001));
107+
OLA_ASSERT_EQ(manufacturer_devices2.DeviceId(),
108+
static_cast<uint32_t>(0xffffffff));
98109
OLA_ASSERT_TRUE(all_devices.IsBroadcast());
110+
OLA_ASSERT_FALSE(all_devices.IsVendorcast());
99111
OLA_ASSERT_TRUE(manufacturer_devices.IsBroadcast());
112+
OLA_ASSERT_TRUE(manufacturer_devices.IsVendorcast());
113+
OLA_ASSERT_TRUE(manufacturer_devices2.IsBroadcast());
114+
OLA_ASSERT_TRUE(manufacturer_devices2.IsVendorcast());
100115

101116
// now test the packing & unpacking
102117
unsigned int buffer_size = UID::UID_SIZE;
@@ -118,6 +133,49 @@ void UIDTest::testUID() {
118133
}
119134

120135

136+
/*
137+
* Test the RPT UIDs work.
138+
*/
139+
void UIDTest::testRPTUID() {
140+
UID uid(1, 2);
141+
UID rpt_all_controllers = UID::RPTAllControllers();
142+
UID rpt_all_devices = UID::RPTAllDevices();
143+
UID rpt_manufacturer_devices = UID::RPTVendorcastAddressDevices(0x52);
144+
UID rpt_manufacturer_devices2 = UID::RPTVendorcastAddressDevices(uid);
145+
OLA_ASSERT_EQ(string("fffc:ffffffff"), rpt_all_controllers.ToString());
146+
OLA_ASSERT_EQ(string("fffd:ffffffff"), rpt_all_devices.ToString());
147+
OLA_ASSERT_EQ(string("fffd:0052ffff"),
148+
rpt_manufacturer_devices.ToString());
149+
OLA_ASSERT_EQ(string("fffd:0001ffff"),
150+
rpt_manufacturer_devices2.ToString());
151+
OLA_ASSERT_EQ(rpt_all_controllers.ManufacturerId(),
152+
static_cast<uint16_t>(0xfffc));
153+
OLA_ASSERT_EQ(rpt_all_controllers.DeviceId(),
154+
static_cast<uint32_t>(0xffffffff));
155+
OLA_ASSERT_EQ(rpt_all_devices.ManufacturerId(),
156+
static_cast<uint16_t>(0xfffd));
157+
OLA_ASSERT_EQ(rpt_all_devices.DeviceId(),
158+
static_cast<uint32_t>(0xffffffff));
159+
OLA_ASSERT_EQ(rpt_manufacturer_devices.ManufacturerId(),
160+
static_cast<uint16_t>(0xfffd));
161+
OLA_ASSERT_EQ(rpt_manufacturer_devices.DeviceId(),
162+
static_cast<uint32_t>(0x0052ffff));
163+
OLA_ASSERT_EQ(rpt_manufacturer_devices2.ManufacturerId(),
164+
static_cast<uint16_t>(0xfffd));
165+
OLA_ASSERT_EQ(rpt_manufacturer_devices2.DeviceId(),
166+
static_cast<uint32_t>(0x0001ffff));
167+
// TODO(Peter): Handle the more complicated RPT vendorcast tests
168+
OLA_ASSERT_TRUE(rpt_all_controllers.IsBroadcast());
169+
// OLA_ASSERT_FALSE(rpt_all_controllers.IsVendorcast());
170+
OLA_ASSERT_TRUE(rpt_all_devices.IsBroadcast());
171+
// OLA_ASSERT_FALSE(rpt_all_devices.IsVendorcast());
172+
// OLA_ASSERT_TRUE(rpt_manufacturer_devices.IsBroadcast());
173+
// OLA_ASSERT_TRUE(rpt_manufacturer_devices.IsVendorcast());
174+
// OLA_ASSERT_TRUE(rpt_manufacturer_devices2.IsBroadcast());
175+
// OLA_ASSERT_TRUE(rpt_manufacturer_devices2.IsVendorcast());
176+
}
177+
178+
121179
/*
122180
* Test the UIDs inequalities work
123181
*/

include/ola/e133/E133Enums.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@
2121
#ifndef INCLUDE_OLA_E133_E133ENUMS_H_
2222
#define INCLUDE_OLA_E133_E133ENUMS_H_
2323

24+
#include <stdint.h>
25+
2426
namespace ola {
2527
namespace e133 {
2628

29+
// Appendix A - Endpoints and Table 3-1: Endpoint ID Allocation
30+
static const uint16_t NULL_ENDPOINT = 0x0000;
31+
static const uint16_t MIN_DEVICE_ENDPOINT = 0x0001;
32+
static const uint16_t MAX_DEVICE_ENDPOINT = 0xF9FF;
33+
static const uint16_t BROADCAST_ENDPOINT = 0xFFFF;
34+
2735
// Table A-6, Discovery Stats
2836
enum DiscoveryState {
2937
DISCOVERY_INCOMPLETE = 0,

include/ola/e133/E133StatusHelper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,32 @@
2222
#define INCLUDE_OLA_E133_E133STATUSHELPER_H_
2323

2424
#include <stdint.h>
25+
#include <ola/acn/ACNVectors.h>
2526
#include <ola/e133/E133Enums.h>
27+
#include <ola/rdm/RDMResponseCodes.h>
2628
#include <string>
2729

2830
namespace ola {
2931
namespace e133 {
3032

3133
using std::string;
34+
using ola::acn::RPTStatusVector;
3235
using ola::e133::E133StatusCode;
3336
using ola::e133::E133ConnectStatusCode;
37+
using ola::rdm::RDMStatusCode;
3438

3539
bool IntToStatusCode(uint16_t input, E133StatusCode *status_code);
3640
string StatusCodeToString(E133StatusCode status_code);
3741

3842
bool IntToConnectStatusCode(uint16_t input,
3943
E133ConnectStatusCode *connect_status_code);
4044
string ConnectStatusCodeToString(E133ConnectStatusCode connect_status_code);
45+
46+
bool IntToRPTStatusCode(uint16_t input,
47+
RPTStatusVector *rpt_status_code);
48+
string RPTStatusCodeToString(RPTStatusVector rpt_status_code);
49+
bool RPTStatusCodeToRDMStatusCode(RPTStatusVector rpt_status_code,
50+
RDMStatusCode *rdm_status_code);
4151
} // namespace e133
4252
} // namespace ola
4353
#endif // INCLUDE_OLA_E133_E133STATUSHELPER_H_

include/ola/rdm/UID.h

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ class UID {
174174
*/
175175
bool IsBroadcast() const { return m_uid.device_id == ALL_DEVICES; }
176176

177+
/**
178+
* @brief Check if this UID is a vendorcast UID.
179+
* @returns true if the manufacturer id is not 0xffff and the device id is
180+
* 0xffffffff.
181+
*/
182+
bool IsVendorcast() const {
183+
return ((m_uid.esta_id != ALL_MANUFACTURERS) &&
184+
(m_uid.device_id == ALL_DEVICES));
185+
}
186+
177187
/**
178188
* @brief Check if this UID matches against another.
179189
* @param uid the UID to check against
@@ -260,7 +270,7 @@ class UID {
260270

261271
/**
262272
* @brief Returns a UID that matches all devices for a particular
263-
* manufacturer.
273+
* manufacturer.
264274
* @param esta_id the manufacturer id of the devices to match.
265275
* @returns a UID(X, 0xffffffff).
266276
*/
@@ -278,6 +288,44 @@ class UID {
278288
return UID(uid.ManufacturerId(), ALL_DEVICES);
279289
}
280290

291+
/**
292+
* @brief Returns a UID that matches all RPT controllers (fffc:ffffffff).
293+
* @returns a UID(0xfffc, 0xffffffff).
294+
*/
295+
static UID RPTAllControllers() {
296+
return UID(RPT_ALL_CONTROLLERS_MANUFACTURER, ALL_DEVICES);
297+
}
298+
299+
/**
300+
* @brief Returns a UID that matches all RPT devices (fffd:ffffffff).
301+
* @returns a UID(0xfffd, 0xffffffff).
302+
*/
303+
static UID RPTAllDevices() {
304+
return UID(RPT_ALL_DEVICES_MANUFACTURER, ALL_DEVICES);
305+
}
306+
307+
/**
308+
* @brief Returns a UID that matches all RPT devices for a particular
309+
* manufacturer.
310+
* @param esta_id the manufacturer id of the devices to match.
311+
* @returns a UID(0xfffd, 0xXXXXffff).
312+
*/
313+
static UID RPTVendorcastAddressDevices(uint16_t esta_id) {
314+
return UID(RPT_ALL_DEVICES_MANUFACTURER,
315+
RPTVendorcastDevicesDeviceId(esta_id));
316+
}
317+
318+
/**
319+
* @brief Returns a UID that matches all RPT devices for a particular
320+
* manufacturer.
321+
* @param uid a UID whose manufacturer id you want to match.
322+
* @returns a UID(0xfffd, 0xXXXXffff).
323+
*/
324+
static UID RPTVendorcastAddressDevices(UID uid) {
325+
return UID(RPT_ALL_DEVICES_MANUFACTURER,
326+
RPTVendorcastDevicesDeviceId(uid.ManufacturerId()));
327+
}
328+
281329
/**
282330
* @brief Return a new UID from a string.
283331
* @param uid the UID as a string i.e. XXXX:YYYYYYYY.
@@ -300,9 +348,21 @@ class UID {
300348

301349
/**
302350
* @brief The value for the 'all devices' id.
351+
*
352+
* This is also the value for RPT all controllers and all devices.
303353
*/
304354
static const uint32_t ALL_DEVICES = 0xffffffff;
305355

356+
/**
357+
* @brief The value for the RPT 'all controllers' manufacturer.
358+
*/
359+
static const uint16_t RPT_ALL_CONTROLLERS_MANUFACTURER = 0xfffc;
360+
361+
/**
362+
* @brief The value for the RPT 'all devices' manufacturer.
363+
*/
364+
static const uint16_t RPT_ALL_DEVICES_MANUFACTURER = 0xfffd;
365+
306366
private:
307367
struct rdm_uid {
308368
uint16_t esta_id;
@@ -324,6 +384,10 @@ class UID {
324384
}
325385
return a < b ? -1 : 1;
326386
}
387+
388+
static uint32_t RPTVendorcastDevicesDeviceId(uint16_t esta_id) {
389+
return ((static_cast<uint32_t>(esta_id) << 16) | 0xffff);
390+
}
327391
};
328392
} // namespace rdm
329393
} // namespace ola
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
* BrokerClientEntryRPTInflator.cpp
17+
* The Inflator for BrokerClientEntryRPT PDU
18+
* Copyright (C) 2023 Peter Newman
19+
*/
20+
21+
#include <iostream>
22+
#include <memory>
23+
24+
#include "ola/Logging.h"
25+
#include "ola/acn/CID.h"
26+
#include "ola/e133/E133Helper.h"
27+
#include "ola/network/NetworkUtils.h"
28+
#include "ola/rdm/UID.h"
29+
#include "include/ola/strings/Format.h"
30+
#include "libs/acn/BrokerClientEntryRPTInflator.h"
31+
32+
namespace ola {
33+
namespace acn {
34+
35+
using ola::acn::CID;
36+
using ola::network::NetworkToHost;
37+
using ola::rdm::UID;
38+
using ola::strings::IntToString;
39+
40+
/**
41+
* Set a BrokerClientEntryRPTHandler to run when receiving a Broker Client
42+
* Entry RPT message.
43+
* @param handler the callback to invoke when there is a Broker Client Entry
44+
* RPT.
45+
*/
46+
void BrokerClientEntryRPTInflator::SetBrokerClientEntryRPTHandler(
47+
BrokerClientEntryRPTHandler *handler) {
48+
m_broker_client_entry_rpt_handler.reset(handler);
49+
}
50+
51+
52+
unsigned int BrokerClientEntryRPTInflator::InflatePDUBlock(
53+
OLA_UNUSED HeaderSet *headers,
54+
const uint8_t *data,
55+
unsigned int len) {
56+
broker_client_entry_rpt_pdu_data pdu_data;
57+
if (len > sizeof(pdu_data)) {
58+
OLA_WARN << "Got too much data, received " << len << " only expecting "
59+
<< sizeof(pdu_data);
60+
return 0;
61+
}
62+
63+
memcpy(reinterpret_cast<uint8_t*>(&pdu_data), data, sizeof(pdu_data));
64+
65+
OLA_DEBUG << "Client Entry RPT from " << CID::FromData(pdu_data.client_cid)
66+
<< " (" << UID(pdu_data.client_uid) << ") of RPT Client Type "
67+
<< IntToString(pdu_data.rpt_client_type);
68+
69+
ola::e133::E133RPTClientTypeCode client_type;
70+
if (!ola::e133::IntToRPTClientType(pdu_data.rpt_client_type, &client_type)) {
71+
OLA_WARN << "Unknown E1.33 RPT Client Type code "
72+
<< IntToString(pdu_data.rpt_client_type);
73+
}
74+
75+
BrokerClientEntryRPT client_entry(CID::FromData(pdu_data.client_cid),
76+
UID(pdu_data.client_uid),
77+
client_type,
78+
CID::FromData(pdu_data.binding_cid));
79+
80+
if (m_broker_client_entry_rpt_handler.get()) {
81+
m_broker_client_entry_rpt_handler->Run(headers,
82+
client_entry);
83+
} else {
84+
OLA_WARN << "No Broker Client Entry RPT handler defined!";
85+
}
86+
return sizeof(pdu_data);
87+
}
88+
} // namespace acn
89+
} // namespace ola

0 commit comments

Comments
 (0)