make SACN::Receiver a subclass of ACN::Appliance

This commit is contained in:
Kevin Matz 2021-02-02 14:20:08 -05:00
parent 63e2aeca41
commit fc6cac583d
4 changed files with 47 additions and 31 deletions

View File

@ -31,10 +31,10 @@ static const char* TAG = "EspReceiver";
namespace SACN {
EspReceiver::EspReceiver()
: Receiver()
EspReceiver::EspReceiver(UUID::uuid cid)
: Receiver(cid)
{
udp.onPacket(std::bind(&EspReceiver::udpHandler, this,
udp.onPacket(std::bind(&EspReceiver::UdpStreamHandler, this,
std::placeholders::_1));
}
@ -56,13 +56,15 @@ void EspReceiver::unsubscribe(const uint16_t num) {
// AsyncUDP has no way to unsubscribe IGMP?
}
void EspReceiver::udpHandler(AsyncUDPPacket udp) {
void EspReceiver::UdpStreamHandler(AsyncUDPPacket udp_packet) {
// Expecting IANA registered Session Data Transport traffic
if (!udp.localPort() == ACN_SDT_MULTICAST_PORT)
if (!udp_packet.localPort() == ACN_SDT_MULTICAST_PORT)
return;
PDU::Stream packet(new PDU::pdu_stream(udp.data(), udp.available()));
packetHandler(packet); // from base class, SACN::Receiver
// wrap a PDU io stream around the AsyncUDPPacket data buffer
PDU::Stream stream(new PDU::pdu_stream(udp_packet.data(),
udp_packet.available()));
Receiver::UdpStreamHandler(stream);
}
} // SACN

View File

@ -54,14 +54,13 @@ class EspReceiver
: public SACN::Receiver
{
public:
EspReceiver();
EspReceiver(UUID::uuid = UUID::uuid());
virtual void subscribe(const uint16_t universe = 1);
virtual void unsubscribe(const uint16_t);
private:
AsyncUDP udp; // AsyncUDP
void udpHandler(AsyncUDPPacket); // UDP packet parser callback
void UdpStreamHandler(AsyncUDPPacket); // UDP packet parser callback
};
} // SACN

View File

@ -27,6 +27,19 @@
namespace SACN {
/**
Constructor. Register RLP vector callbacks.
*/
Receiver::Receiver(UUID::uuid cid)
: Appliance(cid)
{
registerRlpVectorHandler(VECTOR_ROOT_E131_DATA,
std::bind(&Receiver::rootDataHandler, this, std::placeholders::_1));
registerRlpVectorHandler(VECTOR_ROOT_E131_EXTENDED,
std::bind(&Receiver::rootExtendedHandler, this, std::placeholders::_1));
}
void Receiver::subscribe(const uint16_t num) {
if (!universes_.count(num))
universes_.emplace(num, new SACN::Universe());
@ -45,53 +58,49 @@ SACN::Universe * Receiver::universe(uint16_t universe) {
/**
Parse the received UDP data.
Parse the received UDP data, overrideing base class implimentation of EPI17.
Layer 4 only. Verificiton of layer 3 (UDP port) must be handled prior to calling.
@param packet is a shared pointer to the UDP data buffer.
*/
void Receiver::packetHandler(PDU::Stream packet) {
void Receiver::UdpStreamHandler(PDU::Stream stream) {
// verify the UDP preamble
RLP::UDP::preamble_t preamble(packet);
RLP::UDP::preamble_t preamble(stream);
// 5.1 Preamble Size
// Sources shall set the Preamble Size to 0x0010. Receivers of UDP-based
// E1.31 shall discard the packet if the Preamble Size is not 0x0010.
if (preamble.length != 0x0010)
packet->setstate(packet->rdstate() | std::ios_base::failbit);
stream->setstate(stream->rdstate() | std::ios_base::failbit);
// 5.2 Post-amble Size
// Receivers of UDP based E1.31 shall discard the packet if the
// Post-amble Size is not 0x0000.
if (preamble.postamble_size != 0x0000)
packet->setstate(packet->rdstate() | std::ios_base::failbit);
stream->setstate(stream->rdstate() | std::ios_base::failbit);
// 5.3 ACN Packet Identifier
// Receivers shall discard the packet if the ACN Packet Identifier is
// not valid.
if (!preamble)
packet->setstate(packet->rdstate() | std::ios_base::failbit);
stream->setstate(stream->rdstate() | std::ios_base::failbit);
if (!packet->good())
if (!stream->good())
return;
auto block = PDU::readBlock<RLP::Pdu>(stream);
if (stream->fail())
return;
auto block = PDU::readBlock<RLP::Pdu>(packet);
if (packet->fail())
return;
for(auto root : *block) {
// 5.5 Vector
// Receivers shall discard the packet if the received value is not
// VECTOR_ROOT_E131_DATA or VECTOR_ROOT_E131_EXTENDED.
switch (root->vector()) {
case VECTOR_ROOT_E131_DATA:
rootDataHandler(root);
break;
case VECTOR_ROOT_E131_EXTENDED:
break;
default:
break;
}
if (root->vector() != VECTOR_ROOT_E131_DATA &&
root->vector() != VECTOR_ROOT_E131_EXTENDED)
return;
RlpReceiver(root);
}
}

View File

@ -31,19 +31,25 @@
namespace SACN {
class Receiver
: public Appliance
{
public:
Receiver() {};
Receiver(UUID::uuid = UUID::uuid());
virtual void subscribe(const uint16_t);
virtual void unsubscribe(const uint16_t);
SACN::Universe * universe(uint16_t universe);
protected:
void packetHandler(PDU::Stream);
// override base class implimentation of EPI 17
virtual void UdpStreamHandler(PDU::Stream);
// process data frames
void rootDataHandler(std::shared_ptr<RLP::Pdu>);
void dataPacketHandler(std::shared_ptr<DATA::Pdu>);
// process extended frames
void rootExtendedHandler(std::shared_ptr<RLP::Pdu>) {};
private:
std::unordered_map <uint16_t, SACN::Universe *> universes_;
};