You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
F4KXL_DStarGateway/Common/APRSCollector.cpp

118 lines
3.4 KiB

/*
* Copyright (C) 2010,2012,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2021 by Geoffrey Merck F4FXL / KC3FRA
*
* 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 <cassert>
#include <cstring>
#include <string>
#include <boost/algorithm/string.hpp>
#include "APRSCollector.h"
#include "DStarDefines.h"
#include "Utils.h"
#include "NMEASentenceCollector.h"
#include "GPSACollector.h"
#include "RSMS1AMessageCollector.h"
#include "SlowDataCollectorThrottle.h"
CAPRSCollector::CAPRSCollector() :
m_collectors()
{
m_collectors.push_back(new CRSMS1AMessageCollector()); // we do not throttle messages, they have highest priority !
m_collectors.push_back(new CSlowDataCollectorThrottle(new CGPSACollector(), 10U));
m_collectors.push_back(new CSlowDataCollectorThrottle(new CNMEASentenceCollector("$GPGGA"), 10U));
m_collectors.push_back(new CSlowDataCollectorThrottle(new CNMEASentenceCollector("$GPGLL"), 10U));
m_collectors.push_back(new CSlowDataCollectorThrottle(new CNMEASentenceCollector("$GPVTG"), 10U));
m_collectors.push_back(new CSlowDataCollectorThrottle(new CNMEASentenceCollector("$GPRMC"), 10U));
m_collectors.push_back(new CSlowDataCollectorThrottle(new CNMEASentenceCollector("$GPGSA"), 10U));
m_collectors.push_back(new CSlowDataCollectorThrottle(new CNMEASentenceCollector("$GPGSV"), 10U));
}
CAPRSCollector::~CAPRSCollector()
{
for(auto collector : m_collectors) {
delete collector;
}
m_collectors.clear();
}
void CAPRSCollector::writeHeader(const CHeaderData& header)
{
std::string mycall1 = header.getMyCall1();
std::string mycall2 = header.getMyCall2();
for(auto collector : m_collectors) {
collector->setMyCall1(mycall1);
collector->setMyCall2(mycall2);
}
}
bool CAPRSCollector::writeData(const unsigned char* data)
{
bool ret = false;
for(auto collector : m_collectors) {
bool ret2 = collector->writeData(data);
ret = ret || ret2;
}
return ret;
}
void CAPRSCollector::reset()
{
for(auto collector : m_collectors) {
collector->reset();
}
}
void CAPRSCollector::sync()
{
for(auto collector : m_collectors) {
collector->sync();
}
}
unsigned int CAPRSCollector::getData(unsigned char dataType, unsigned char* data, unsigned int length)
{
for(auto collector : m_collectors) {
if(collector->getDataType() == dataType) {
unsigned int res = collector->getData(data, length);
if(res > 0U)
return res;
}
}
return 0U;
}
void CAPRSCollector::getData(std::function<void(const std::string&, const std::string&)> dataHandler)
{
for(auto collector : m_collectors) {
std::string data;
if(collector->getData(data)) {
dataHandler(data, collector->getMyCall1().append("/").append(collector->getMyCall2()));
collector->reset();
}
}
}
void CAPRSCollector::clock(unsigned int ms)
{
for(auto collector : m_collectors) {
collector->clock(ms);
}
}

Powered by TurnKey Linux.