The beginnings of DMR Id to callsign lookups.
This commit is contained in:
parent
8dfa91beb1
commit
9c283395fd
6 changed files with 132 additions and 7 deletions
78
DMRLookup.cpp
Normal file
78
DMRLookup.cpp
Normal file
|
@ -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 <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
39
DMRLookup.h
Normal file
39
DMRLookup.h
Normal file
|
@ -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 <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
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<unsigned int, std::string> m_table;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -173,6 +173,7 @@
|
||||||
<ClInclude Include="Golay2087.h" />
|
<ClInclude Include="Golay2087.h" />
|
||||||
<ClInclude Include="Golay24128.h" />
|
<ClInclude Include="Golay24128.h" />
|
||||||
<ClInclude Include="Hamming.h" />
|
<ClInclude Include="Hamming.h" />
|
||||||
|
<ClInclude Include="DMRLookup.h" />
|
||||||
<ClInclude Include="Log.h" />
|
<ClInclude Include="Log.h" />
|
||||||
<ClInclude Include="MMDVMHost.h" />
|
<ClInclude Include="MMDVMHost.h" />
|
||||||
<ClInclude Include="Modem.h" />
|
<ClInclude Include="Modem.h" />
|
||||||
|
@ -213,6 +214,7 @@
|
||||||
<ClCompile Include="DMRFullLC.cpp" />
|
<ClCompile Include="DMRFullLC.cpp" />
|
||||||
<ClCompile Include="DMRIPSC.cpp" />
|
<ClCompile Include="DMRIPSC.cpp" />
|
||||||
<ClCompile Include="DMRLC.cpp" />
|
<ClCompile Include="DMRLC.cpp" />
|
||||||
|
<ClCompile Include="DMRLookup.cpp" />
|
||||||
<ClCompile Include="DMRShortLC.cpp" />
|
<ClCompile Include="DMRShortLC.cpp" />
|
||||||
<ClCompile Include="DMRSlot.cpp" />
|
<ClCompile Include="DMRSlot.cpp" />
|
||||||
<ClCompile Include="DMRSlotType.cpp" />
|
<ClCompile Include="DMRSlotType.cpp" />
|
||||||
|
|
|
@ -164,6 +164,9 @@
|
||||||
<ClInclude Include="Nextion.h">
|
<ClInclude Include="Nextion.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="DMRLookup.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="BPTC19696.cpp">
|
<ClCompile Include="BPTC19696.cpp">
|
||||||
|
@ -301,5 +304,8 @@
|
||||||
<ClCompile Include="Nextion.cpp">
|
<ClCompile Include="Nextion.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="DMRLookup.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
8
Makefile
8
Makefile
|
@ -7,10 +7,10 @@ LIBS =
|
||||||
LDFLAGS = -g
|
LDFLAGS = -g
|
||||||
|
|
||||||
OBJECTS = \
|
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 \
|
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 \
|
||||||
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 \
|
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 \
|
||||||
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 \
|
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 \
|
||||||
YSFFICH.o YSFParrot.o YSFPayload.o
|
YSFConvolution.o YSFFICH.o YSFParrot.o YSFPayload.o
|
||||||
|
|
||||||
all: MMDVMHost
|
all: MMDVMHost
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ LIBS = -lwiringPi -lwiringPiDev
|
||||||
LDFLAGS = -g -L/usr/local/lib
|
LDFLAGS = -g -L/usr/local/lib
|
||||||
|
|
||||||
OBJECTS = \
|
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 \
|
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 \
|
||||||
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 \
|
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 \
|
||||||
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 \
|
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
|
YSFConvolution.o YSFFICH.o YSFParrot.o YSFPayload.o
|
||||||
|
|
||||||
all: MMDVMHost
|
all: MMDVMHost
|
||||||
|
|
Loading…
Reference in a new issue