Skip to content

Commit

Permalink
Add some RPT UID functionality and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewman committed Mar 30, 2024
1 parent e1e94e3 commit d976466
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
58 changes: 58 additions & 0 deletions common/rdm/UIDTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using ola::rdm::UIDSet;
class UIDTest: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(UIDTest);
CPPUNIT_TEST(testUID);
CPPUNIT_TEST(testRPTUID);
CPPUNIT_TEST(testUIDInequalities);
CPPUNIT_TEST(testUIDSet);
CPPUNIT_TEST(testUIDSetUnion);
Expand All @@ -43,6 +44,7 @@ class UIDTest: public CppUnit::TestFixture {

public:
void testUID();
void testRPTUID();
void testUIDInequalities();
void testUIDSet();
void testUIDSetUnion();
Expand All @@ -58,6 +60,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(UIDTest);
*/
void UIDTest::testUID() {
UID uid(1, 2);
OLA_ASSERT_FALSE(uid.IsBroadcast());
OLA_ASSERT_FALSE(uid.IsVendorcast());
UID uid2 = uid;
OLA_ASSERT_EQ(uid, uid2);
OLA_ASSERT_FALSE(uid != uid2);
Expand All @@ -84,9 +88,12 @@ void UIDTest::testUID() {

UID all_devices = UID::AllDevices();
UID manufacturer_devices = UID::VendorcastAddress(0x52);
UID manufacturer_devices2 = UID::VendorcastAddress(uid);
OLA_ASSERT_EQ(string("ffff:ffffffff"), all_devices.ToString());
OLA_ASSERT_EQ(string("0052:ffffffff"),
manufacturer_devices.ToString());
OLA_ASSERT_EQ(string("0001:ffffffff"),
manufacturer_devices2.ToString());
OLA_ASSERT_EQ(all_devices.ManufacturerId(),
static_cast<uint16_t>(0xffff));
OLA_ASSERT_EQ(all_devices.DeviceId(),
Expand All @@ -95,8 +102,16 @@ void UIDTest::testUID() {
static_cast<uint16_t>(0x0052));
OLA_ASSERT_EQ(manufacturer_devices.DeviceId(),
static_cast<uint32_t>(0xffffffff));
OLA_ASSERT_EQ(manufacturer_devices2.ManufacturerId(),
static_cast<uint16_t>(0x0001));
OLA_ASSERT_EQ(manufacturer_devices2.DeviceId(),
static_cast<uint32_t>(0xffffffff));
OLA_ASSERT_TRUE(all_devices.IsBroadcast());
OLA_ASSERT_FALSE(all_devices.IsVendorcast());
OLA_ASSERT_TRUE(manufacturer_devices.IsBroadcast());
OLA_ASSERT_TRUE(manufacturer_devices.IsVendorcast());
OLA_ASSERT_TRUE(manufacturer_devices2.IsBroadcast());
OLA_ASSERT_TRUE(manufacturer_devices2.IsVendorcast());

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


/*
* Test the RPT UIDs work.
*/
void UIDTest::testRPTUID() {
UID uid(1, 2);
UID rpt_all_controllers = UID::RPTAllControllers();
UID rpt_all_devices = UID::RPTAllDevices();
UID rpt_manufacturer_devices = UID::RPTVendorcastAddressDevices(0x52);
UID rpt_manufacturer_devices2 = UID::RPTVendorcastAddressDevices(uid);
OLA_ASSERT_EQ(string("fffc:ffffffff"), rpt_all_controllers.ToString());
OLA_ASSERT_EQ(string("fffd:ffffffff"), rpt_all_devices.ToString());
OLA_ASSERT_EQ(string("fffd:0052ffff"),
rpt_manufacturer_devices.ToString());
OLA_ASSERT_EQ(string("fffd:0001ffff"),
rpt_manufacturer_devices2.ToString());
OLA_ASSERT_EQ(rpt_all_controllers.ManufacturerId(),
static_cast<uint16_t>(0xfffc));
OLA_ASSERT_EQ(rpt_all_controllers.DeviceId(),
static_cast<uint32_t>(0xffffffff));
OLA_ASSERT_EQ(rpt_all_devices.ManufacturerId(),
static_cast<uint16_t>(0xfffd));
OLA_ASSERT_EQ(rpt_all_devices.DeviceId(),
static_cast<uint32_t>(0xffffffff));
OLA_ASSERT_EQ(rpt_manufacturer_devices.ManufacturerId(),
static_cast<uint16_t>(0xfffd));
OLA_ASSERT_EQ(rpt_manufacturer_devices.DeviceId(),
static_cast<uint32_t>(0x0052ffff));
OLA_ASSERT_EQ(rpt_manufacturer_devices2.ManufacturerId(),
static_cast<uint16_t>(0xfffd));
OLA_ASSERT_EQ(rpt_manufacturer_devices2.DeviceId(),
static_cast<uint32_t>(0x0001ffff));
OLA_ASSERT_TRUE(rpt_all_controllers.IsBroadcast());
OLA_ASSERT_FALSE(rpt_all_controllers.IsVendorcast());
OLA_ASSERT_TRUE(rpt_all_devices.IsBroadcast());
OLA_ASSERT_FALSE(rpt_all_devices.IsVendorcast());
// TODO(Peter): Handle the more complicated RPT vendorcast tests
// OLA_ASSERT_TRUE(rpt_manufacturer_devices.IsBroadcast());
// OLA_ASSERT_TRUE(rpt_manufacturer_devices.IsVendorcast());
// OLA_ASSERT_TRUE(rpt_manufacturer_devices2.IsBroadcast());
// OLA_ASSERT_TRUE(rpt_manufacturer_devices2.IsVendorcast());
}


/*
* Test the UIDs inequalities work
*/
Expand Down
66 changes: 65 additions & 1 deletion include/ola/rdm/UID.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ class UID {
*/
bool IsBroadcast() const { return m_uid.device_id == ALL_DEVICES; }

/**
* @brief Check if this UID is a vendorcast UID.
* @returns true if the manufacturer id is not 0xffff and the device id is
* 0xffffffff.
*/
bool IsVendorcast() const {
return ((m_uid.esta_id != ALL_MANUFACTURERS) &&
(m_uid.device_id == ALL_DEVICES));
}

/**
* @brief Check if this UID matches against another.
* @param uid the UID to check against
Expand Down Expand Up @@ -260,7 +270,7 @@ class UID {

/**
* @brief Returns a UID that matches all devices for a particular
* manufacturer.
* manufacturer.
* @param esta_id the manufacturer id of the devices to match.
* @returns a UID(X, 0xffffffff).
*/
Expand All @@ -278,6 +288,44 @@ class UID {
return UID(uid.ManufacturerId(), ALL_DEVICES);
}

/**
* @brief Returns a UID that matches all RPT controllers (fffc:ffffffff).
* @returns a UID(0xfffc, 0xffffffff).
*/
static UID RPTAllControllers() {
return UID(RPT_ALL_CONTROLLERS_MANUFACTURER, ALL_DEVICES);
}

/**
* @brief Returns a UID that matches all RPT devices (fffd:ffffffff).
* @returns a UID(0xfffd, 0xffffffff).
*/
static UID RPTAllDevices() {
return UID(RPT_ALL_DEVICES_MANUFACTURER, ALL_DEVICES);
}

/**
* @brief Returns a UID that matches all RPT devices for a particular
* manufacturer.
* @param esta_id the manufacturer id of the devices to match.
* @returns a UID(0xfffd, 0xXXXXffff).
*/
static UID RPTVendorcastAddressDevices(uint16_t esta_id) {
return UID(RPT_ALL_DEVICES_MANUFACTURER,
RPTVendorcastDevicesDeviceId(esta_id));
}

/**
* @brief Returns a UID that matches all RPT devices for a particular
* manufacturer.
* @param uid a UID whose manufacturer id you want to match.
* @returns a UID(0xfffd, 0xXXXXffff).
*/
static UID RPTVendorcastAddressDevices(UID uid) {
return UID(RPT_ALL_DEVICES_MANUFACTURER,
RPTVendorcastDevicesDeviceId(uid.ManufacturerId()));
}

/**
* @brief Return a new UID from a string.
* @param uid the UID as a string i.e. XXXX:YYYYYYYY.
Expand All @@ -300,9 +348,21 @@ class UID {

/**
* @brief The value for the 'all devices' id.
*
* This is also the value for RPT all controllers and all devices.
*/
static const uint32_t ALL_DEVICES = 0xffffffff;

/**
* @brief The value for the RPT 'all controllers' manufacturer.
*/
static const uint16_t RPT_ALL_CONTROLLERS_MANUFACTURER = 0xfffc;

/**
* @brief The value for the RPT 'all devices' manufacturer.
*/
static const uint16_t RPT_ALL_DEVICES_MANUFACTURER = 0xfffd;

private:
struct rdm_uid {
uint16_t esta_id;
Expand All @@ -324,6 +384,10 @@ class UID {
}
return a < b ? -1 : 1;
}

static uint32_t RPTVendorcastDevicesDeviceId(uint16_t esta_id) {
return ((static_cast<uint32_t>(esta_id) << 16) | 0xffff);
}
};
} // namespace rdm
} // namespace ola
Expand Down

0 comments on commit d976466

Please sign in to comment.