93 lines
2.5 KiB
C++
93 lines
2.5 KiB
C++
/*
|
|
message.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 "message.h"
|
|
|
|
namespace RDM {
|
|
|
|
/**
|
|
* @brief Message::Message
|
|
*/
|
|
Message::Message()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Message::Message
|
|
* @param obj
|
|
*/
|
|
Message::Message(const Message &obj)
|
|
: source(obj.source)
|
|
, destination(obj.destination)
|
|
, transaction(obj.transaction)
|
|
, portID(obj.portID)
|
|
, messageCount(obj.messageCount)
|
|
, subDevice(obj.subDevice)
|
|
, propertyID(obj.propertyID)
|
|
{
|
|
data_.insert(data_.end(), obj.data()->begin(), obj.data()->end());
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Message::~Message
|
|
*/
|
|
Message::~Message()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Message::checksum
|
|
* @return
|
|
*/
|
|
uint16_t Message::checksum()
|
|
{
|
|
uint16_t sum = 0;
|
|
|
|
sum = addSum_<uint8_t> (sum, SC_RDM);
|
|
sum = addSum_<uint8_t> (sum, SC_SUB_MESSAGE);
|
|
sum = addSum_<uint8_t> (sum, 24 + length());
|
|
sum = addSum_<uint16_t>(sum, source.manufacturer);
|
|
sum = addSum_<uint32_t>(sum, source.device);
|
|
sum = addSum_<uint16_t>(sum, destination.manufacturer);
|
|
sum = addSum_<uint32_t>(sum, destination.device);
|
|
sum = addSum_<uint8_t> (sum, transaction);
|
|
sum = addSum_<uint8_t> (sum, portID);
|
|
sum = addSum_<uint8_t> (sum, messageCount);
|
|
sum = addSum_<uint16_t>(sum, subDevice);
|
|
sum = addSum_<uint8_t> (sum, commandClass);
|
|
sum = addSum_<uint16_t>(sum, propertyID);
|
|
sum = addSum_<uint8_t> (sum, length());
|
|
for (uint8_t val : data_)
|
|
sum = addSum_<uint8_t>(sum, val);
|
|
|
|
return sum;
|
|
}
|
|
|
|
} // namespace RDM
|