Skip to content

Commit

Permalink
RF power level control for MMDVM_HS compatible devices
Browse files Browse the repository at this point in the history
  • Loading branch information
juribeparada committed Dec 30, 2017
1 parent 8445663 commit 1805a98
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ m_modemTXOffset(0),
m_modemRXOffset(0),
m_modemRXDCOffset(0),
m_modemTXDCOffset(0),
m_modemRFLevel(100.0F),
m_modemRXLevel(50.0F),
m_modemCWIdTXLevel(50.0F),
m_modemDStarTXLevel(50.0F),
Expand Down Expand Up @@ -359,6 +360,8 @@ bool CConf::read()
m_modemRXDCOffset = ::atoi(value);
else if (::strcmp(key, "TXDCOffset") == 0)
m_modemTXDCOffset = ::atoi(value);
else if (::strcmp(key, "RFLevel") == 0)
m_modemRFLevel = float(::atof(value));
else if (::strcmp(key, "RXLevel") == 0)
m_modemRXLevel = float(::atof(value));
else if (::strcmp(key, "TXLevel") == 0)
Expand Down Expand Up @@ -815,6 +818,11 @@ int CConf::getModemTXDCOffset() const
return m_modemTXDCOffset;
}

float CConf::getModemRFLevel() const
{
return m_modemRFLevel;
}

float CConf::getModemRXLevel() const
{
return m_modemRXLevel;
Expand Down
2 changes: 2 additions & 0 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class CConf
int getModemRXOffset() const;
int getModemRXDCOffset() const;
int getModemTXDCOffset() const;
float getModemRFLevel() const;
float getModemRXLevel() const;
float getModemCWIdTXLevel() const;
float getModemDStarTXLevel() const;
Expand Down Expand Up @@ -252,6 +253,7 @@ class CConf
int m_modemRXOffset;
int m_modemRXDCOffset;
int m_modemTXDCOffset;
float m_modemRFLevel;
float m_modemRXLevel;
float m_modemCWIdTXLevel;
float m_modemDStarTXLevel;
Expand Down
1 change: 1 addition & 0 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ RXLevel=50
TXLevel=50
RXDCOffset=0
TXDCOffset=0
RFLevel=100
# CWIdTXLevel=50
# D-StarTXLevel=50
# DMRTXLevel=50
Expand Down
4 changes: 3 additions & 1 deletion MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ bool CMMDVMHost::createModem()
int txOffset = m_conf.getModemTXOffset();
int rxDCOffset = m_conf.getModemRXDCOffset();
int txDCOffset = m_conf.getModemTXDCOffset();
float rfLevel = m_conf.getModemRFLevel();

LogInfo("Modem Parameters");
LogInfo(" Port: %s", port.c_str());
Expand All @@ -865,6 +866,7 @@ bool CMMDVMHost::createModem()
LogInfo(" TX Offset: %dHz", txOffset);
LogInfo(" RX DC Offset: %d", rxDCOffset);
LogInfo(" TX DC Offset: %d", txDCOffset);
LogInfo(" RF Level: %.1f%%", rfLevel);
LogInfo(" DMR Delay: %u (%.1fms)", dmrDelay, float(dmrDelay) * 0.0416666F);
LogInfo(" RX Level: %.1f%%", rxLevel);
LogInfo(" CW Id TX Level: %.1f%%", cwIdTXLevel);
Expand All @@ -878,7 +880,7 @@ bool CMMDVMHost::createModem()
m_modem = new CModem(port, m_duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, trace, debug);
m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled, m_p25Enabled);
m_modem->setLevels(rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel);
m_modem->setRFParams(rxFrequency, rxOffset, txFrequency, txOffset, txDCOffset, rxDCOffset);
m_modem->setRFParams(rxFrequency, rxOffset, txFrequency, txOffset, txDCOffset, rxDCOffset, rfLevel);
m_modem->setDMRParams(colorCode);
m_modem->setYSFParams(lowDeviation);

Expand Down
15 changes: 9 additions & 6 deletions Modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ CModem::~CModem()
delete[] m_buffer;
}

void CModem::setRFParams(unsigned int rxFrequency, int rxOffset, unsigned int txFrequency, int txOffset, int txDCOffset, int rxDCOffset)
void CModem::setRFParams(unsigned int rxFrequency, int rxOffset, unsigned int txFrequency, int txOffset, int txDCOffset, int rxDCOffset, float rfLevel)
{
m_rxFrequency = rxFrequency + rxOffset;
m_txFrequency = txFrequency + txOffset;
m_txDCOffset = txDCOffset;
m_rxDCOffset = rxDCOffset;
m_rfLevel = rfLevel;
}

void CModem::setModeParams(bool dstarEnabled, bool dmrEnabled, bool ysfEnabled, bool p25Enabled)
Expand Down Expand Up @@ -1042,11 +1043,11 @@ bool CModem::setConfig()

bool CModem::setFrequency()
{
unsigned char buffer[15U];
unsigned char buffer[16U];

buffer[0U] = MMDVM_FRAME_START;

buffer[1U] = 12U;
buffer[1U] = 13U;

buffer[2U] = MMDVM_SET_FREQ;

Expand All @@ -1061,11 +1062,13 @@ bool CModem::setFrequency()
buffer[9U] = (m_txFrequency >> 8) & 0xFFU;
buffer[10U] = (m_txFrequency >> 16) & 0xFFU;
buffer[11U] = (m_txFrequency >> 24) & 0xFFU;

buffer[12U] = (unsigned char)(m_rfLevel * 2.55F + 0.5F);

// CUtils::dump(1U, "Written", buffer, 12U);
// CUtils::dump(1U, "Written", buffer, 13U);

int ret = m_serial.write(buffer, 12U);
if (ret != 12)
int ret = m_serial.write(buffer, 13U);
if (ret != 13)
return false;

unsigned int count = 0U;
Expand Down
3 changes: 2 additions & 1 deletion Modem.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CModem {
CModem(const std::string& port, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, unsigned int txDelay, unsigned int dmrDelay, bool trace, bool debug);
~CModem();

void setRFParams(unsigned int rxFrequency, int rxOffset, unsigned int txFrequency, int txOffset, int txDCOffset, int rxDCOffset);
void setRFParams(unsigned int rxFrequency, int rxOffset, unsigned int txFrequency, int txOffset, int txDCOffset, int rxDCOffset, float rfLevel);
void setModeParams(bool dstarEnabled, bool dmrEnabled, bool ysfEnabled, bool p25Enabled);
void setLevels(float rxLevel, float cwIdTXLevel, float dstarTXLevel, float dmrTXLevel, float ysfTXLevel, float p25Enabled);
void setDMRParams(unsigned int colorCode);
Expand Down Expand Up @@ -103,6 +103,7 @@ class CModem {
float m_dmrTXLevel;
float m_ysfTXLevel;
float m_p25TXLevel;
float m_rfLevel;
bool m_trace;
bool m_debug;
unsigned int m_rxFrequency;
Expand Down

0 comments on commit 1805a98

Please sign in to comment.