diff --git a/DMRLookup.cpp b/DMRLookup.cpp new file mode 100644 index 0000000..8a7669d --- /dev/null +++ b/DMRLookup.cpp @@ -0,0 +1,78 @@ +/* +* Copyright (C) 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 "DMRLookup.h" +#include "Log.h" + +#include +#include +#include + +CDMRLookup::CDMRLookup(const std::string& filename) : +m_filename(filename) +{ +} + +CDMRLookup::~CDMRLookup() +{ +} + +bool CDMRLookup::read() +{ + FILE* fp = ::fopen(m_filename.c_str(), "rt"); + if (fp == NULL) { + LogWarning("Cannot open the DMR Id lookup file - %s", m_filename.c_str()); + return false; + } + + char buffer[100U]; + while (::fgets(buffer, 100U, fp) != NULL) { + if (buffer[0U] == '#') + continue; + + char* p1 = ::strtok(buffer, " \t\r\n"); + char* p2 = ::strtok(NULL, " \t\r\n"); + + if (p1 != NULL && p2 != NULL) { + unsigned int id = (unsigned int)::atoi(p1); + for (char* p = p2; *p != 0x00U; p++) + *p = ::toupper(*p); + + m_table[id] = std::string(p2); + } + } + + LogInfo("Loaded %u DMR Ids to the callsign lookup table", m_table.size()); + + return true; +} + +std::string CDMRLookup::find(unsigned int id) const +{ + std::string callsign; + + try { + callsign = m_table.at(id); + } catch (std::out_of_range& e) { + char text[10U]; + ::sprintf(text, "%u", id); + callsign = std::string(text); + } + + return callsign; +} diff --git a/DMRLookup.h b/DMRLookup.h new file mode 100644 index 0000000..0403154 --- /dev/null +++ b/DMRLookup.h @@ -0,0 +1,39 @@ +/* +* Copyright (C) 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. +*/ + +#ifndef DMRLookup_H +#define DMRLookup_H + +#include +#include + +class CDMRLookup { +public: + CDMRLookup(const std::string& filename); + ~CDMRLookup(); + + bool read(); + + std::string find(unsigned int id) const; + +private: + std::string m_filename; + std::unordered_map m_table; +}; + +#endif diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index ffdc777..a1a54a3 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -173,6 +173,7 @@ + @@ -213,6 +214,7 @@ + diff --git a/MMDVMHost.vcxproj.filters b/MMDVMHost.vcxproj.filters index d1c0428..b0fe876 100644 --- a/MMDVMHost.vcxproj.filters +++ b/MMDVMHost.vcxproj.filters @@ -164,6 +164,9 @@ Header Files + + Header Files + @@ -301,5 +304,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/Makefile b/Makefile index 289f016..45115cd 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,10 @@ LIBS = LDFLAGS = -g OBJECTS = \ - AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLC.o DMRShortLC.o \ - DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o Nextion.o \ - NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o Trellis.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o \ - YSFFICH.o YSFParrot.o YSFPayload.o + AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \ + DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o \ + Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o Trellis.o UDPSocket.o Utils.o YSFControl.o \ + YSFConvolution.o YSFFICH.o YSFParrot.o YSFPayload.o all: MMDVMHost diff --git a/Makefile.Pi b/Makefile.Pi index 5aac706..5d2f28d 100644 --- a/Makefile.Pi +++ b/Makefile.Pi @@ -7,9 +7,9 @@ LIBS = -lwiringPi -lwiringPiDev LDFLAGS = -g -L/usr/local/lib OBJECTS = \ - AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLC.o DMRShortLC.o \ - DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o Modem.o \ - Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o Trellis.o UDPSocket.o Utils.o YSFControl.o \ + AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \ + DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o \ + Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o Trellis.o UDPSocket.o Utils.o YSFControl.o \ YSFConvolution.o YSFFICH.o YSFParrot.o YSFPayload.o all: MMDVMHost