OpenLCP/acn/sdt.cpp
2021-07-29 19:27:13 -04:00

242 lines
4.7 KiB
C++

/*
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 {
/**
* @brief params_t::iStream
* @param stream
*/
void params_t::iStream(PDU::Stream stream)
{
*stream >> Expiry;
uint8_t packed;
*stream >> packed;
NAK_Outbound = packed >> 7;
reserved = packed & 0xef;
*stream >> NAKholdoff;
*stream >> NAKmodulus;
*stream >> NAKmaxwait;
}
/**
* @brief join_data_t::iStream
* @param stream
*/
void join_data_t::iStream(PDU::Stream stream)
{
*stream >> mid;
*stream >> number;
*stream >> reciprocal;
*stream >> sequence;
*stream >> reliable;
destination.iStream(stream);
parameters.iStream(stream);
*stream >> expiry;
}
/**
* @brief join_accept_data_t::iStream
* @param stream
*/
void join_accept_data_t::iStream(PDU::Stream stream)
{
uint8_t buf[16];
stream->read(buf, sizeof(buf));
leader = UUID::uuid(buf);
*stream >> number;
*stream >> mid;
*stream >> reliable;
*stream >> reciprocal;
}
/**
* @brief join_refuse_data_t::iStream
* @param stream
*/
void join_refuse_data_t::iStream(PDU::Stream stream)
{
uint8_t buf[16];
stream->read(buf, sizeof(buf));
leader = UUID::uuid(buf);
*stream >> number;
*stream >> mid;
*stream >> reliable;
*stream >> code;
}
/**
* @brief nak_data_t::iStream
* @param stream
*/
void nak_data_t::iStream(PDU::Stream stream)
{
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;
}
/**
* @brief wrapper_data_t::iStream
* @param stream
*/
void wrapper_data_t::iStream(PDU::Stream stream)
{
*stream >> number;
}
/**
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;
}
/**
* @brief Pdu::Pdu
*/
Pdu::Pdu()
: PDU::Pdu(1) // vectors are 1 octet
{
}
/**
* @brief Pdu::iStream
* @param stream
*/
void Pdu::iStream(PDU::Stream stream)
{
PDU::Pdu::iStream(stream); //! do base class first
if (stream->fail()) return;
if (!stream_->good()) return;
}
/**
* @brief client_pdu_header_t::iStream
* @param stream
*/
void client_pdu_header_t::iStream(PDU::Stream stream)
{
*stream >> protocol;
*stream >> association;
}
/**
* @brief ClientPdu::ClientPdu
* @param stream
*/
ClientPdu::ClientPdu()
: PDU::Pdu(2) // vectors are 2 octets (MID)
{
}
/**
* @brief ClientPdu::iStream
* @param stream
*/
void ClientPdu::iStream(PDU::Stream stream)
{
PDU::Pdu::iStream(stream); //! do base class first
if (stream->fail()) return;
if (!stream_->good()) return;
if (flags_.hasHeader)
{
header_ = new client_pdu_header_t();
header_->iStream(stream_);
}
}
}; // SDT
}; // ACN