MMDVMHost-Private/CSBK.cpp

120 lines
2.7 KiB
C++
Raw Normal View History

2016-01-14 18:45:04 +00:00
/*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
*
* 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.
*/
#include "CSBK.h"
#include "BPTC19696.h"
#include "Utils.h"
#include "CRC.h"
2016-01-14 18:45:04 +00:00
#include <cstdio>
#include <cassert>
CCSBK::CCSBK(const unsigned char* bytes) :
m_CSBKO(CSBKO_NONE),
m_FID(0x00U),
m_bsId(0U),
m_srcId(0U),
m_dstId(0U),
2016-01-14 18:45:04 +00:00
m_valid(false)
{
assert(bytes != NULL);
CBPTC19696 bptc;
unsigned char data[12U];
bptc.decode(bytes, data);
2016-01-26 18:06:31 +00:00
data[10U] ^= CSBK_CRC_MASK[0U];
data[11U] ^= CSBK_CRC_MASK[1U];
m_valid = CCRC::checkCCITT16(data, 12U);
2016-01-14 18:45:04 +00:00
m_CSBKO = CSBKO(data[0U] & 0x3FU);
m_FID = data[1U];
switch (m_CSBKO) {
case CSBKO_BSDWNACT:
2016-01-14 18:45:04 +00:00
m_bsId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_srcId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Download Activate CSBK", data, 12U);
break;
case CSBKO_UUVREQ:
m_dstId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_srcId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Unit to Unit Service Request CSBK", data, 12U);
break;
case CSBKO_UUANSRSP:
m_dstId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_srcId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Unit to Unit Service Answer Response CSBK", data, 12U);
break;
case CSBKO_PRECCSBK:
m_dstId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_srcId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Preamble CSBK", data, 12U);
break;
case CSBKO_NACKRSP:
m_srcId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_dstId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Negative Acknowledge Response CSBK", data, 12U);
break;
default:
2016-01-14 18:45:04 +00:00
CUtils::dump("Unhandled CSBK type", data, 12U);
break;
2016-01-14 18:45:04 +00:00
}
}
CCSBK::~CCSBK()
{
}
bool CCSBK::isValid() const
{
return m_valid;
}
CSBKO CCSBK::getCSBKO() const
{
return m_CSBKO;
}
unsigned char CCSBK::getFID() const
{
return m_FID;
}
unsigned int CCSBK::getBSId() const
{
return m_bsId;
}
unsigned int CCSBK::getSrcId() const
{
return m_srcId;
}
unsigned int CCSBK::getDstId() const
{
return m_dstId;
}