2021-05-27 10:59:22 -04:00
|
|
|
/*
|
|
|
|
data.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2021-08-24 18:10:20 -04:00
|
|
|
#include "dmp/dmp.h"
|
2021-05-27 10:59:22 -04:00
|
|
|
#include "data.h"
|
2022-11-28 15:06:48 -05:00
|
|
|
#include "sacn.h"
|
2021-05-27 10:59:22 -04:00
|
|
|
|
2021-08-28 09:01:33 -04:00
|
|
|
namespace sACN {
|
2021-05-27 10:59:22 -04:00
|
|
|
namespace DATA {
|
|
|
|
|
2021-07-29 11:20:03 -04:00
|
|
|
/**
|
|
|
|
* @brief frame_header::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
2021-08-15 23:36:29 -04:00
|
|
|
void data_header::iStream(ACN::PDU::Stream stream)
|
2021-07-29 11:20:03 -04:00
|
|
|
{
|
2021-08-20 11:41:20 -04:00
|
|
|
stream->readString(source_name, 64);
|
2021-08-28 12:54:26 -04:00
|
|
|
/// > \cite sACN 6.2.3 E1.31 Data Packet: Priority
|
|
|
|
/// >
|
|
|
|
/// > No priority outside the range of 0 to 200 shall be transmitted
|
|
|
|
/// > on the network.
|
2021-08-15 23:36:29 -04:00
|
|
|
*stream >> priority;
|
2021-09-01 12:24:02 -04:00
|
|
|
if (priority > 200)
|
2021-08-28 09:08:40 -04:00
|
|
|
stream->setstate(std::ios_base::failbit);
|
2021-08-15 23:36:29 -04:00
|
|
|
*stream >> sync_address;
|
|
|
|
*stream >> sequence_number;
|
|
|
|
*stream >> options;
|
2021-08-28 12:54:26 -04:00
|
|
|
/// > \cite sACN 6.2.7 E1.31 Data Packet: Universe
|
|
|
|
/// >
|
|
|
|
/// > Universe values shall be limited to the range 1 to 63999.
|
2021-08-15 23:36:29 -04:00
|
|
|
*stream >> universe;
|
2021-08-28 10:27:13 -04:00
|
|
|
if ((universe == 0) ||
|
|
|
|
(universe >= 64000 && universe != E131_DISCOVERY_UNIVERSE))
|
|
|
|
stream->setstate(std::ios_base::failbit);
|
2021-07-26 13:34:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 22:48:48 -04:00
|
|
|
/**
|
2021-08-25 17:20:33 -04:00
|
|
|
* @brief data_header::oStream
|
|
|
|
* @param stream
|
2021-07-26 22:48:48 -04:00
|
|
|
*/
|
2021-08-15 23:36:29 -04:00
|
|
|
void data_header::oStream(ACN::PDU::Stream stream) const
|
2021-07-26 22:48:48 -04:00
|
|
|
{
|
2021-08-20 11:41:20 -04:00
|
|
|
stream->writeString(source_name, 64);
|
2021-08-28 12:54:26 -04:00
|
|
|
/// > \cite sACN 6.2.3 E1.31 Data Packet: Priority
|
|
|
|
/// >
|
|
|
|
/// > No priority outside the range of 0 to 200 shall be transmitted on
|
|
|
|
/// > the network.
|
2021-09-01 12:24:02 -04:00
|
|
|
*stream << (uint8_t)(priority <= 200 ? priority : 200);
|
2021-08-15 23:36:29 -04:00
|
|
|
*stream << sync_address;
|
|
|
|
*stream << sequence_number;
|
|
|
|
*stream << options;
|
|
|
|
*stream << universe;
|
2021-07-26 22:48:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-28 14:47:30 -04:00
|
|
|
/**
|
|
|
|
* @brief Headers are unquely defined by the combination of description,
|
|
|
|
* priority, and universe.
|
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
bool operator== (const data_header& a, const data_header& b)
|
|
|
|
{
|
|
|
|
return (a.source_name == b.source_name &&
|
|
|
|
a.universe == b.universe &&
|
|
|
|
a.priority == b.priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-09-11 10:01:18 -04:00
|
|
|
* @brief operator <
|
2021-08-28 14:47:30 -04:00
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
bool operator< (const data_header& a, const data_header& b)
|
|
|
|
{
|
2021-09-11 10:01:18 -04:00
|
|
|
if (a == b)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a.universe != b.universe)
|
|
|
|
return a.universe < b.universe;
|
|
|
|
|
|
|
|
if (a.priority != b.priority)
|
|
|
|
return a.priority < b.priority;
|
|
|
|
|
|
|
|
if (a.source_name != b.source_name)
|
|
|
|
return a.source_name < b.source_name;
|
|
|
|
|
|
|
|
return false;
|
2021-08-28 14:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-09-11 10:01:18 -04:00
|
|
|
* @brief operator >
|
2021-08-28 14:47:30 -04:00
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
bool operator> (const data_header& a, const data_header& b)
|
|
|
|
{
|
2021-09-11 10:01:18 -04:00
|
|
|
if (a == b)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !(a < b);
|
2021-08-28 14:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-28 09:10:28 -04:00
|
|
|
/**
|
|
|
|
* @brief data_options::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void data_options::iStream(ACN::PDU::Stream stream)
|
|
|
|
{
|
|
|
|
*stream >> byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief data_options::oStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void data_options::oStream(ACN::PDU::Stream stream) const
|
|
|
|
{
|
|
|
|
*stream << byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 13:34:11 -04:00
|
|
|
/**
|
|
|
|
* @brief Pdu::Pdu
|
|
|
|
*/
|
2021-07-29 19:26:49 -04:00
|
|
|
Pdu::Pdu()
|
2021-08-15 23:36:29 -04:00
|
|
|
: ACN::PDU::Pdu(4) // vectors are 4 octets
|
2021-05-27 10:59:22 -04:00
|
|
|
{
|
2021-07-29 19:26:49 -04:00
|
|
|
}
|
|
|
|
|
2021-05-27 10:59:22 -04:00
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
/**
|
|
|
|
* @brief Pdu::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
2021-08-15 23:36:29 -04:00
|
|
|
void Pdu::iStream(ACN::PDU::Stream stream)
|
2021-07-29 19:26:49 -04:00
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
ACN::PDU::Pdu::iStream(stream); // flags, length, and vector
|
|
|
|
createHeader<data_header>(); // header
|
|
|
|
createDataBlock<ACN::DMP::Pdu>(); // data
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // DATA
|
|
|
|
} // SACN
|