Skip to content

Commit 9c28339

Browse files
committed
The beginnings of DMR Id to callsign lookups.
1 parent 8dfa91b commit 9c28339

6 files changed

+132
-7
lines changed

DMRLookup.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (C) 2016 by Jonathan Naylor G4KLX
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17+
*/
18+
19+
#include "DMRLookup.h"
20+
#include "Log.h"
21+
22+
#include <cstdio>
23+
#include <cstring>
24+
#include <cctype>
25+
26+
CDMRLookup::CDMRLookup(const std::string& filename) :
27+
m_filename(filename)
28+
{
29+
}
30+
31+
CDMRLookup::~CDMRLookup()
32+
{
33+
}
34+
35+
bool CDMRLookup::read()
36+
{
37+
FILE* fp = ::fopen(m_filename.c_str(), "rt");
38+
if (fp == NULL) {
39+
LogWarning("Cannot open the DMR Id lookup file - %s", m_filename.c_str());
40+
return false;
41+
}
42+
43+
char buffer[100U];
44+
while (::fgets(buffer, 100U, fp) != NULL) {
45+
if (buffer[0U] == '#')
46+
continue;
47+
48+
char* p1 = ::strtok(buffer, " \t\r\n");
49+
char* p2 = ::strtok(NULL, " \t\r\n");
50+
51+
if (p1 != NULL && p2 != NULL) {
52+
unsigned int id = (unsigned int)::atoi(p1);
53+
for (char* p = p2; *p != 0x00U; p++)
54+
*p = ::toupper(*p);
55+
56+
m_table[id] = std::string(p2);
57+
}
58+
}
59+
60+
LogInfo("Loaded %u DMR Ids to the callsign lookup table", m_table.size());
61+
62+
return true;
63+
}
64+
65+
std::string CDMRLookup::find(unsigned int id) const
66+
{
67+
std::string callsign;
68+
69+
try {
70+
callsign = m_table.at(id);
71+
} catch (std::out_of_range& e) {
72+
char text[10U];
73+
::sprintf(text, "%u", id);
74+
callsign = std::string(text);
75+
}
76+
77+
return callsign;
78+
}

DMRLookup.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2016 by Jonathan Naylor G4KLX
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17+
*/
18+
19+
#ifndef DMRLookup_H
20+
#define DMRLookup_H
21+
22+
#include <string>
23+
#include <unordered_map>
24+
25+
class CDMRLookup {
26+
public:
27+
CDMRLookup(const std::string& filename);
28+
~CDMRLookup();
29+
30+
bool read();
31+
32+
std::string find(unsigned int id) const;
33+
34+
private:
35+
std::string m_filename;
36+
std::unordered_map<unsigned int, std::string> m_table;
37+
};
38+
39+
#endif

MMDVMHost.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
<ClInclude Include="Golay2087.h" />
174174
<ClInclude Include="Golay24128.h" />
175175
<ClInclude Include="Hamming.h" />
176+
<ClInclude Include="DMRLookup.h" />
176177
<ClInclude Include="Log.h" />
177178
<ClInclude Include="MMDVMHost.h" />
178179
<ClInclude Include="Modem.h" />
@@ -213,6 +214,7 @@
213214
<ClCompile Include="DMRFullLC.cpp" />
214215
<ClCompile Include="DMRIPSC.cpp" />
215216
<ClCompile Include="DMRLC.cpp" />
217+
<ClCompile Include="DMRLookup.cpp" />
216218
<ClCompile Include="DMRShortLC.cpp" />
217219
<ClCompile Include="DMRSlot.cpp" />
218220
<ClCompile Include="DMRSlotType.cpp" />

MMDVMHost.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
<ClInclude Include="Nextion.h">
165165
<Filter>Header Files</Filter>
166166
</ClInclude>
167+
<ClInclude Include="DMRLookup.h">
168+
<Filter>Header Files</Filter>
169+
</ClInclude>
167170
</ItemGroup>
168171
<ItemGroup>
169172
<ClCompile Include="BPTC19696.cpp">
@@ -301,5 +304,8 @@
301304
<ClCompile Include="Nextion.cpp">
302305
<Filter>Source Files</Filter>
303306
</ClCompile>
307+
<ClCompile Include="DMRLookup.cpp">
308+
<Filter>Source Files</Filter>
309+
</ClCompile>
304310
</ItemGroup>
305311
</Project>

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LIBS =
77
LDFLAGS = -g
88

99
OBJECTS = \
10-
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 \
11-
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 \
12-
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 \
13-
YSFFICH.o YSFParrot.o YSFPayload.o
10+
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 \
11+
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 \
12+
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 \
13+
YSFConvolution.o YSFFICH.o YSFParrot.o YSFPayload.o
1414

1515
all: MMDVMHost
1616

Makefile.Pi

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ LIBS = -lwiringPi -lwiringPiDev
77
LDFLAGS = -g -L/usr/local/lib
88

99
OBJECTS = \
10-
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 \
11-
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 \
12-
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 \
10+
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 \
11+
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 \
12+
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 \
1313
YSFConvolution.o YSFFICH.o YSFParrot.o YSFPayload.o
1414

1515
all: MMDVMHost

0 commit comments

Comments
 (0)