1
0
Fork 0

add a field to Packet to track unicast reply destination

This commit is contained in:
Kevin Matz 2023-05-22 09:01:47 -04:00
parent f92bed2a8a
commit f49250a610
3 changed files with 19 additions and 16 deletions

View File

@ -50,16 +50,22 @@ Device::Device(Style style)
/**
* @brief Device::receive
* @param buffer
* @param origin
*/
void Device::receive(ACN::PDU::Stream buffer)
void Device::receive(ACN::PDU::Stream buffer, ipAddress &origin)
{
if (origin.port != UDP_PORT || origin.type != 1) // ACN::SDT::SDT_ADDR_IPV4
return buffer->setstate(std::ios_base::badbit);
auto packet = std::make_shared<Packet>();
packet->iStream(buffer);
if (buffer->fail() || buffer->bad())
{
_report_code = RcParseFail;
_report_text = "unable to read packet";
return;
}
packet->originAddress = origin.address.ipv4.value;
receive(packet);
}

View File

@ -42,7 +42,7 @@ public:
const Style styleCode; //!< \cite ARTNET The Style code defines the equipment style of the device.
void receive(ACN::PDU::Stream);
void receive(ACN::PDU::Stream, ipAddress&);
void receive(std::shared_ptr<Packet>);
std::shared_ptr<void> setSender(const std::function<void(std::shared_ptr<bufferstream>,

View File

@ -534,31 +534,28 @@ struct rdmsub_data
struct Packet
: public streamable
{
/**
* @brief Packet
* @param opcode
* @param data
*/
/// @brief Packet
/// @param opcode
/// @param data
Packet(OpCode opcode = OpNull, std::shared_ptr<packet_data> data = nullptr)
: _opcode(opcode)
, _data(data)
{}
/**
* @brief opcode
* @return
*/
/// @brief opcode
/// @return
OpCode opcode() const { return _opcode; }
/**
* @brief data
* @return
*/
/// @brief IP address where unicast replies will be sent.
uint32_t originAddress;
/// @brief data
/// @return
template<class T>
auto data() const
{
static_assert(std::is_base_of<packet_data, T>::value,
"type parameter of data must derive from ARTNET::packet_data");
"type must inherit ARTNET::packet_data");
return _data ? std::optional<std::shared_ptr<T>>{std::static_pointer_cast<T>(_data)}
: std::nullopt;
}