MMDVMHost-Private/DMRControl.cpp

148 lines
3.9 KiB
C++
Raw Normal View History

2016-01-14 19:45:04 +01:00
/*
2021-02-17 22:36:47 +01:00
* Copyright (C) 2015-2021 Jonathan Naylor, G4KLX
2016-01-14 19:45:04 +01: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; version 2 of the License.
*
* 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.
*/
#include "DMRControl.h"
2016-11-10 19:43:54 +01:00
#include "DMRAccessControl.h"
2016-01-14 19:45:04 +01:00
#include "Defines.h"
2016-02-15 19:45:57 +01:00
#include "DMRCSBK.h"
2016-01-14 19:45:04 +01:00
#include "Log.h"
2016-03-07 21:21:55 +01:00
#include <cstdio>
2016-01-14 19:45:04 +01:00
#include <cassert>
#include <algorithm>
2016-01-14 19:45:04 +01:00
2021-02-17 22:36:47 +01:00
CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, unsigned int callHang, bool selfOnly, bool embeddedLCOnly, bool dumpTAData, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blacklist, const std::vector<unsigned int>& whitelist, const std::vector<unsigned int>& slot1TGWhitelist, const std::vector<unsigned int>& slot2TGWhitelist, unsigned int timeout, CModem* modem, IDMRNetwork* network, CDisplay* display, bool duplex, CDMRLookup* lookup, CRSSIInterpolator* rssi, unsigned int jitter, DMR_OVCM_TYPES ovcm) :
2016-01-14 19:45:04 +01:00
m_colorCode(colorCode),
m_modem(modem),
m_network(network),
m_slot1(1U, timeout),
m_slot2(2U, timeout),
m_lookup(lookup)
2016-01-14 19:45:04 +01:00
{
2016-11-10 19:43:54 +01:00
assert(id != 0U);
2016-01-14 19:45:04 +01:00
assert(modem != NULL);
assert(display != NULL);
assert(lookup != NULL);
assert(rssi != NULL);
2016-01-14 19:45:04 +01:00
2016-11-10 19:43:54 +01:00
// Load black and white lists to DMRAccessControl
2017-01-05 20:15:10 +01:00
CDMRAccessControl::init(blacklist, whitelist, slot1TGWhitelist, slot2TGWhitelist, selfOnly, prefixes, id);
2016-11-10 19:43:54 +01:00
2022-07-29 23:08:25 +02:00
//Print whitelisted IDs
LogMessage("Allowed radio ids: ");
2022-07-29 23:23:49 +02:00
for (unsigned int i: whitelist) {
std::string id_name = std::to_string(i);
LogMessage(id_name.c_str());
}
2022-07-29 23:08:25 +02:00
2019-11-16 16:06:26 +01:00
CDMRSlot::init(colorCode, embeddedLCOnly, dumpTAData, callHang, modem, network, display, duplex, m_lookup, rssi, jitter, ovcm);
2016-01-14 19:45:04 +01:00
}
CDMRControl::~CDMRControl()
{
}
bool CDMRControl::processWakeup(const unsigned char* data)
{
2016-03-07 21:21:55 +01:00
assert(data != NULL);
2016-01-14 19:45:04 +01:00
// Wakeups always come in on slot 1
if (data[0U] != TAG_DATA || data[1U] != (DMR_IDLE_RX | DMR_SYNC_DATA | DT_CSBK))
2016-01-14 19:45:04 +01:00
return false;
CDMRCSBK csbk;
bool valid = csbk.put(data + 2U);
if (!valid)
return false;
2016-01-14 19:45:04 +01:00
CSBKO csbko = csbk.getCSBKO();
if (csbko != CSBKO_BSDWNACT)
return false;
unsigned int srcId = csbk.getSrcId();
std::string srcId_name = std::to_string(srcId);
LogMessage("Incoming uplink from radio id: %s", srcId_name.c_str());
std::string src = m_lookup->find(srcId);
2017-01-05 20:15:10 +01:00
bool ret = CDMRAccessControl::validateSrcId(srcId);
2016-11-10 19:43:54 +01:00
if (!ret) {
LogMessage("Blocked downlink activation from %s (%s)", src.c_str(), srcId_name.c_str());
2016-11-10 19:43:54 +01:00
return false;
2016-01-14 19:45:04 +01:00
}
2022-07-30 00:30:52 +02:00
LogMessage("Downlink request received from %s (%s)", src.c_str(), srcId_name.c_str());
2016-04-04 20:03:38 +02:00
return true;
2016-01-14 19:45:04 +01:00
}
2017-03-12 20:06:47 +01:00
bool CDMRControl::writeModemSlot1(unsigned char *data, unsigned int len)
2016-01-14 19:45:04 +01:00
{
2016-03-07 21:21:55 +01:00
assert(data != NULL);
2017-03-12 20:06:47 +01:00
return m_slot1.writeModem(data, len);
2016-01-14 19:45:04 +01:00
}
2017-03-12 20:06:47 +01:00
bool CDMRControl::writeModemSlot2(unsigned char *data, unsigned int len)
2016-01-14 19:45:04 +01:00
{
2016-03-07 21:21:55 +01:00
assert(data != NULL);
2017-03-12 20:06:47 +01:00
return m_slot2.writeModem(data, len);
2016-01-14 19:45:04 +01:00
}
unsigned int CDMRControl::readModemSlot1(unsigned char *data)
{
2016-03-07 21:21:55 +01:00
assert(data != NULL);
2016-01-14 19:45:04 +01:00
return m_slot1.readModem(data);
}
unsigned int CDMRControl::readModemSlot2(unsigned char *data)
{
2016-03-07 21:21:55 +01:00
assert(data != NULL);
2016-01-14 19:45:04 +01:00
return m_slot2.readModem(data);
}
void CDMRControl::clock()
2016-01-14 19:45:04 +01:00
{
if (m_network != NULL) {
CDMRData data;
bool ret = m_network->read(data);
if (ret) {
unsigned int slotNo = data.getSlotNo();
switch (slotNo) {
case 1U: m_slot1.writeNetwork(data); break;
case 2U: m_slot2.writeNetwork(data); break;
default: LogError("Invalid slot no %u", slotNo); break;
}
}
}
m_slot1.clock();
m_slot2.clock();
2016-01-14 19:45:04 +01:00
}
bool CDMRControl::isBusy() const
{
if (m_slot1.isBusy())
return true;
return m_slot2.isBusy();
}
void CDMRControl::enable(bool enabled)
{
m_slot1.enable(enabled);
m_slot2.enable(enabled);
}