2021-05-27 10:59:22 -04:00
|
|
|
/*
|
|
|
|
sdt.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2021 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sdt.h"
|
|
|
|
|
|
|
|
namespace ACN {
|
|
|
|
namespace SDT {
|
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
/**
|
|
|
|
* @brief params_t::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void params_t::iStream(PDU::Stream stream)
|
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
if (!stream->good())
|
|
|
|
return;
|
2021-08-15 23:36:29 -04:00
|
|
|
*stream >> Expiry;
|
|
|
|
uint8_t packed;
|
|
|
|
*stream >> packed;
|
|
|
|
NAK_Outbound = packed >> 7;
|
|
|
|
reserved = packed & 0xef;
|
|
|
|
*stream >> NAKholdoff;
|
|
|
|
*stream >> NAKmodulus;
|
|
|
|
*stream >> NAKmaxwait;
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
/**
|
|
|
|
* @brief join_data_t::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void join_data_t::iStream(PDU::Stream stream)
|
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
if (!stream->good())
|
|
|
|
return;
|
2021-08-15 23:36:29 -04:00
|
|
|
*stream >> mid;
|
|
|
|
*stream >> number;
|
|
|
|
*stream >> reciprocal;
|
|
|
|
*stream >> sequence;
|
|
|
|
*stream >> reliable;
|
|
|
|
destination.iStream(stream);
|
|
|
|
parameters.iStream(stream);
|
|
|
|
*stream >> expiry;
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief join_accept_data_t::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void join_accept_data_t::iStream(PDU::Stream stream)
|
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
if (!stream->good())
|
|
|
|
return;
|
2021-08-15 23:36:29 -04:00
|
|
|
uint8_t buf[16];
|
|
|
|
stream->read(buf, sizeof(buf));
|
|
|
|
leader = UUID::uuid(buf);
|
|
|
|
*stream >> number;
|
|
|
|
*stream >> mid;
|
|
|
|
*stream >> reliable;
|
|
|
|
*stream >> reciprocal;
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief join_refuse_data_t::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void join_refuse_data_t::iStream(PDU::Stream stream)
|
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
if (!stream->good())
|
|
|
|
return;
|
2021-05-27 10:59:22 -04:00
|
|
|
uint8_t buf[16];
|
|
|
|
stream->read(buf, sizeof(buf));
|
|
|
|
leader = UUID::uuid(buf);
|
2021-07-29 19:26:49 -04:00
|
|
|
*stream >> number;
|
|
|
|
*stream >> mid;
|
|
|
|
*stream >> reliable;
|
|
|
|
*stream >> code;
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief nak_data_t::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void nak_data_t::iStream(PDU::Stream stream)
|
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
if (!stream->good())
|
|
|
|
return;
|
2021-08-15 23:36:29 -04:00
|
|
|
uint8_t buf[16];
|
|
|
|
stream->read(buf, sizeof(buf));
|
|
|
|
leader = UUID::uuid(buf);
|
|
|
|
*stream >> number;
|
|
|
|
*stream >> mid;
|
|
|
|
*stream >> reliable;
|
|
|
|
*stream >> missed_first;
|
|
|
|
*stream >> missed_last;
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief wrapper_data_t::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void wrapper_data_t::iStream(PDU::Stream stream)
|
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
if (!stream->good())
|
|
|
|
return;
|
2021-08-15 23:36:29 -04:00
|
|
|
*stream >> number;
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
compare to another sessionID
|
|
|
|
*/
|
|
|
|
bool SessionId::operator== (const SessionId & other) const {
|
|
|
|
return ((other.cid == cid) &
|
|
|
|
(other.number == number) &
|
|
|
|
(other.protocol == protocol));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constuct a sequenced channel with an owner and a direction.
|
|
|
|
|
|
|
|
@param owner the owner of the channel
|
|
|
|
@param direction the direction of channel communication
|
|
|
|
*/
|
|
|
|
Channel::Channel(std::shared_ptr<Component> owner, Direction direction) {
|
|
|
|
owner_ = owner;
|
|
|
|
direction_ = direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
deconstructor that closes the channel cleanly.
|
|
|
|
*/
|
|
|
|
Channel::~Channel() {
|
|
|
|
// TODO: close the channel.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Construct a new session.
|
|
|
|
*/
|
|
|
|
Session::Session() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
deconstructor that leaves the session gracefully.
|
|
|
|
*/
|
|
|
|
Session::~Session() {
|
|
|
|
// TODO: Disconnect the session.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
get the ID of the session
|
|
|
|
*/
|
|
|
|
SessionId Session::id() {
|
|
|
|
SessionId ret;
|
|
|
|
ret.cid = leader->cid();
|
|
|
|
ret.number = number_;
|
|
|
|
ret.protocol = protocol_;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Pdu::Pdu
|
|
|
|
*/
|
|
|
|
Pdu::Pdu()
|
|
|
|
: PDU::Pdu(1) // vectors are 1 octet
|
2021-05-27 10:59:22 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-07-29 19:26:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Pdu::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void Pdu::iStream(PDU::Stream stream)
|
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
PDU::Pdu::iStream(stream); // flags, length, and vector
|
|
|
|
// TODO: header segment // header
|
|
|
|
// TODO: data segment // data
|
2021-07-29 19:26:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief client_pdu_header_t::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
2021-08-15 23:36:29 -04:00
|
|
|
void client_pdu_header::iStream(PDU::Stream stream)
|
2021-07-29 19:26:49 -04:00
|
|
|
{
|
2021-08-15 23:36:29 -04:00
|
|
|
*stream >> protocol;
|
|
|
|
*stream >> association;
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
2021-07-29 11:20:03 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ClientPdu::ClientPdu
|
|
|
|
* @param stream
|
|
|
|
*/
|
2021-07-29 19:26:49 -04:00
|
|
|
ClientPdu::ClientPdu()
|
|
|
|
: PDU::Pdu(2) // vectors are 2 octets (MID)
|
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 ClientPdu::iStream
|
|
|
|
* @param stream
|
|
|
|
*/
|
|
|
|
void ClientPdu::iStream(PDU::Stream stream)
|
|
|
|
{
|
2021-08-16 10:14:39 -04:00
|
|
|
PDU::Pdu::iStream(stream); // flags, length, and vector
|
|
|
|
createHeader<client_pdu_header>(); // header
|
|
|
|
// TODO: data segment // data
|
2021-05-27 10:59:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // SDT
|
|
|
|
}; // ACN
|