MMDVMHost-Private/DMRLC.cpp

217 lines
3.9 KiB
C++
Raw Permalink Normal View History

2016-01-14 18:45:04 +00:00
/*
2019-10-11 17:24:25 +00:00
* Copyright (C) 2015,2016,2019 by Jonathan Naylor G4KLX
2016-01-14 18:45:04 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
2016-02-15 18:45:57 +00:00
#include "DMRLC.h"
2016-01-14 18:45:04 +00:00
#include "Utils.h"
#include <cstdio>
#include <cassert>
2016-02-15 18:45:57 +00:00
CDMRLC::CDMRLC(FLCO flco, unsigned int srcId, unsigned int dstId) :
2016-01-14 18:45:04 +00:00
m_PF(false),
m_R(false),
2016-01-14 18:45:04 +00:00
m_FLCO(flco),
m_FID(0U),
m_options(0U),
2016-01-14 18:45:04 +00:00
m_srcId(srcId),
m_dstId(dstId)
{
}
2016-02-15 18:45:57 +00:00
CDMRLC::CDMRLC(const unsigned char* bytes) :
2016-01-14 18:45:04 +00:00
m_PF(false),
m_R(false),
2016-01-14 18:45:04 +00:00
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
2016-01-14 18:45:04 +00:00
m_srcId(0U),
m_dstId(0U)
{
assert(bytes != NULL);
m_PF = (bytes[0U] & 0x80U) == 0x80U;
m_R = (bytes[0U] & 0x40U) == 0x40U;
2016-01-14 18:45:04 +00:00
m_FLCO = FLCO(bytes[0U] & 0x3FU);
m_FID = bytes[1U];
m_options = bytes[2U];
2016-01-14 18:45:04 +00:00
m_dstId = bytes[3U] << 16 | bytes[4U] << 8 | bytes[5U];
m_srcId = bytes[6U] << 16 | bytes[7U] << 8 | bytes[8U];
}
2016-02-15 18:45:57 +00:00
CDMRLC::CDMRLC(const bool* bits) :
2016-01-14 18:45:04 +00:00
m_PF(false),
m_R(false),
2016-01-14 18:45:04 +00:00
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
2016-01-14 18:45:04 +00:00
m_srcId(0U),
m_dstId(0U)
{
assert(bits != NULL);
m_PF = bits[0U];
m_R = bits[1U];
2016-01-14 18:45:04 +00:00
unsigned char temp1, temp2, temp3;
2016-01-14 18:45:04 +00:00
CUtils::bitsToByteBE(bits + 0U, temp1);
m_FLCO = FLCO(temp1 & 0x3FU);
CUtils::bitsToByteBE(bits + 8U, temp2);
m_FID = temp2;
CUtils::bitsToByteBE(bits + 16U, temp3);
m_options = temp3;
2016-01-14 18:45:04 +00:00
unsigned char d1, d2, d3;
CUtils::bitsToByteBE(bits + 24U, d1);
CUtils::bitsToByteBE(bits + 32U, d2);
CUtils::bitsToByteBE(bits + 40U, d3);
unsigned char s1, s2, s3;
CUtils::bitsToByteBE(bits + 48U, s1);
CUtils::bitsToByteBE(bits + 56U, s2);
CUtils::bitsToByteBE(bits + 64U, s3);
m_srcId = s1 << 16 | s2 << 8 | s3;
m_dstId = d1 << 16 | d2 << 8 | d3;
}
2016-02-15 18:45:57 +00:00
CDMRLC::CDMRLC() :
2016-01-14 18:45:04 +00:00
m_PF(false),
m_R(false),
2016-01-14 18:45:04 +00:00
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
2016-01-14 18:45:04 +00:00
m_srcId(0U),
m_dstId(0U)
{
}
2016-02-15 18:45:57 +00:00
CDMRLC::~CDMRLC()
2016-01-14 18:45:04 +00:00
{
}
2016-02-15 18:45:57 +00:00
void CDMRLC::getData(unsigned char* bytes) const
2016-01-14 18:45:04 +00:00
{
assert(bytes != NULL);
bytes[0U] = (unsigned char)m_FLCO;
if (m_PF)
bytes[0U] |= 0x80U;
if (m_R)
bytes[0U] |= 0x40U;
2016-01-14 18:45:04 +00:00
bytes[1U] = m_FID;
bytes[2U] = m_options;
2016-01-14 18:45:04 +00:00
bytes[3U] = m_dstId >> 16;
bytes[4U] = m_dstId >> 8;
bytes[5U] = m_dstId >> 0;
bytes[6U] = m_srcId >> 16;
bytes[7U] = m_srcId >> 8;
bytes[8U] = m_srcId >> 0;
}
2016-02-15 18:45:57 +00:00
void CDMRLC::getData(bool* bits) const
2016-01-14 18:45:04 +00:00
{
2016-03-07 20:21:55 +00:00
assert(bits != NULL);
2016-01-14 18:45:04 +00:00
unsigned char bytes[9U];
getData(bytes);
CUtils::byteToBitsBE(bytes[0U], bits + 0U);
CUtils::byteToBitsBE(bytes[1U], bits + 8U);
CUtils::byteToBitsBE(bytes[2U], bits + 16U);
CUtils::byteToBitsBE(bytes[3U], bits + 24U);
CUtils::byteToBitsBE(bytes[4U], bits + 32U);
CUtils::byteToBitsBE(bytes[5U], bits + 40U);
CUtils::byteToBitsBE(bytes[6U], bits + 48U);
CUtils::byteToBitsBE(bytes[7U], bits + 56U);
CUtils::byteToBitsBE(bytes[8U], bits + 64U);
}
2016-02-15 18:45:57 +00:00
bool CDMRLC::getPF() const
2016-01-14 18:45:04 +00:00
{
return m_PF;
}
2016-02-15 18:45:57 +00:00
void CDMRLC::setPF(bool pf)
2016-01-14 18:45:04 +00:00
{
m_PF = pf;
}
2016-02-15 18:45:57 +00:00
FLCO CDMRLC::getFLCO() const
2016-01-14 18:45:04 +00:00
{
return m_FLCO;
}
2016-02-15 18:45:57 +00:00
void CDMRLC::setFLCO(FLCO flco)
2016-01-14 18:45:04 +00:00
{
m_FLCO = flco;
}
2016-02-15 18:45:57 +00:00
unsigned char CDMRLC::getFID() const
2016-01-14 18:45:04 +00:00
{
return m_FID;
}
2016-02-15 18:45:57 +00:00
void CDMRLC::setFID(unsigned char fid)
2016-01-14 18:45:04 +00:00
{
m_FID = fid;
}
2019-10-11 17:24:25 +00:00
bool CDMRLC::getOVCM() const
{
return (m_options & 0x04U) == 0x04U;
2019-10-11 17:24:25 +00:00
}
void CDMRLC::setOVCM(bool ovcm)
{
if (ovcm)
m_options |= 0x04U;
2019-10-11 17:24:25 +00:00
}
2016-02-15 18:45:57 +00:00
unsigned int CDMRLC::getSrcId() const
2016-01-14 18:45:04 +00:00
{
return m_srcId;
}
2016-02-15 18:45:57 +00:00
void CDMRLC::setSrcId(unsigned int id)
2016-01-14 18:45:04 +00:00
{
m_srcId = id;
}
2016-02-15 18:45:57 +00:00
unsigned int CDMRLC::getDstId() const
2016-01-14 18:45:04 +00:00
{
return m_dstId;
}
2016-02-15 18:45:57 +00:00
void CDMRLC::setDstId(unsigned int id)
2016-01-14 18:45:04 +00:00
{
m_dstId = id;
}