Skip to content

Commit

Permalink
use UserDBentry from findWithName() to writeDMR(), add writeDMREx()
Browse files Browse the repository at this point in the history
  • Loading branch information
jg1uaa committed Mar 7, 2020
1 parent abf17e1 commit 4ff77c5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 26 deletions.
25 changes: 12 additions & 13 deletions DMRLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,27 @@ void CDMRLookup::stop()
wait();
}

std::string CDMRLookup::findWithName(unsigned int id)
void CDMRLookup::findWithName(unsigned int id, class CUserDBentry *entry)
{
std::string callsign;

if (id == 0xFFFFFFU)
return std::string("ALL");

class CUserDBentry entry;
if (m_table.lookup(id, &entry)) {
// callsign is always available
callsign = entry.get(keyCALLSIGN);
if (!entry.get(keyFIRST_NAME).empty())
callsign += " " + entry.get(keyFIRST_NAME);
if (id == 0xFFFFFFU) {
entry->clear();
entry->set(keyCALLSIGN, "ALL");
return;
}

LogDebug("FindWithName =%s",callsign.c_str());
if (m_table.lookup(id, entry)) {
LogDebug("FindWithName =%s %s", entry->get(keyCALLSIGN).c_str(), entry->get(keyFIRST_NAME).c_str());
} else {
entry->clear();

char text[10U];
::snprintf(text, sizeof(text), "%u", id);
callsign = std::string(text);
entry->set(keyCALLSIGN, text);
}

return callsign;
return;
}
std::string CDMRLookup::find(unsigned int id)
{
Expand Down
16 changes: 6 additions & 10 deletions DMRLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
#define DMRLookup_H

#include "Thread.h"
#include "Mutex.h"
#include "UserDB.h"

#include <string>
#include <unordered_map>

class CDMRLookup : public CThread {
public:
Expand All @@ -35,20 +34,17 @@ class CDMRLookup : public CThread {
virtual void entry();

std::string find(unsigned int id);
std::string findWithName(unsigned int id);
void findWithName(unsigned int id, class CUserDBentry *entry);

bool exists(unsigned int id);

void stop();

private:
std::string m_filename;
unsigned int m_reloadTime;
std::unordered_map<unsigned int, std::string> m_table;
CMutex m_mutex;
bool m_stop;

bool load();
std::string m_filename;
unsigned int m_reloadTime;
class CUserDB m_table;
bool m_stop;
};

#endif
9 changes: 6 additions & 3 deletions DMRSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,8 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
setShortLC(m_slotNo, dstId, flco, ACTIVITY_VOICE);
std::string src = m_lookup->find(srcId);
std::string dst = m_lookup->find(dstId);
std::string cn = m_lookup->findWithName(srcId);
class CUserDBentry cn;
m_lookup->findWithName(srcId, &cn);
m_display->writeDMR(m_slotNo, cn, flco == FLCO_GROUP, dst, "N");

#if defined(DUMP_DMR)
Expand Down Expand Up @@ -1177,7 +1178,8 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
setShortLC(m_slotNo, dstId, m_netLC->getFLCO(), ACTIVITY_VOICE);
std::string src = m_lookup->find(srcId);
std::string dst = m_lookup->find(dstId);
std::string cn = m_lookup->findWithName(srcId);
class CUserDBentry cn;
m_lookup->findWithName(srcId, &cn);

m_display->writeDMR(m_slotNo, cn, m_netLC->getFLCO() == FLCO_GROUP, dst, "N");

Expand Down Expand Up @@ -1373,7 +1375,8 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)

std::string src = m_lookup->find(srcId);
std::string dst = m_lookup->find(dstId);
std::string cn = m_lookup->findWithName(srcId);
class CUserDBentry cn;
m_lookup->findWithName(srcId, &cn);

m_display->writeDMR(m_slotNo, cn, m_netLC->getFLCO() == FLCO_GROUP, dst, "N");

Expand Down
27 changes: 27 additions & 0 deletions Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ void CDisplay::writeDMR(unsigned int slotNo, const std::string& src, bool group,
writeDMRInt(slotNo, src, group, dst, type);
}

void CDisplay::writeDMR(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type)
{
assert(type != NULL);

if (slotNo == 1U) {
m_timer1.start();
m_mode1 = MODE_IDLE;
} else {
m_timer2.start();
m_mode2 = MODE_IDLE;
}

if (writeDMRIntEx(slotNo, src, group, dst, type) < 0) {
std::string src_str;

src_str = src.get(keyCALLSIGN);
if (!src.get(keyFIRST_NAME).empty())
src_str += " " + src.get(keyFIRST_NAME);
writeDMRInt(slotNo, src_str, group, dst, type);
}
}

void CDisplay::writeDMRRSSI(unsigned int slotNo, unsigned char rssi)
{
if (rssi != 0U)
Expand Down Expand Up @@ -386,6 +408,11 @@ void CDisplay::writeDStarBERInt(float ber)
{
}

int CDisplay::writeDMRIntEx(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type)
{
return -1; // not supported
}

void CDisplay::writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi)
{
}
Expand Down
3 changes: 3 additions & 0 deletions Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define DISPLAY_H

#include "Timer.h"
#include "UserDBentry.h"

#include <string>

Expand Down Expand Up @@ -48,6 +49,7 @@ class CDisplay
void clearDStar();

void writeDMR(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type);
void writeDMR(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type);
void writeDMRRSSI(unsigned int slotNo, unsigned char rssi);
void writeDMRBER(unsigned int slotNo, float ber);
void writeDMRTA(unsigned int slotNo, unsigned char* talkerAlias, const char* type);
Expand Down Expand Up @@ -91,6 +93,7 @@ class CDisplay
virtual void clearDStarInt() = 0;

virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type) = 0;
virtual int writeDMRIntEx(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type);
virtual void writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi);
virtual void writeDMRTAInt(unsigned int slotNo, unsigned char* talkerAlias, const char* type);
virtual void writeDMRBERInt(unsigned int slotNo, float ber);
Expand Down

0 comments on commit 4ff77c5

Please sign in to comment.