Add MMDVM lock file based on an idea by DB1OFH.

This commit is contained in:
Jonathan Naylor
2018-10-10 20:05:24 +01:00
parent 867e1745d8
commit edaf37101a
6 changed files with 93 additions and 4 deletions

View File

@@ -55,7 +55,8 @@ enum SECTION {
SECTION_NEXTION, SECTION_NEXTION,
SECTION_OLED, SECTION_OLED,
SECTION_LCDPROC, SECTION_LCDPROC,
SECTION_TGREWRITE SECTION_TGREWRITE,
SECTION_LOCKFILE
}; };
CConf::CConf(const std::string& file) : CConf::CConf(const std::string& file) :
@@ -238,7 +239,9 @@ m_lcdprocAddress(),
m_lcdprocPort(0U), m_lcdprocPort(0U),
m_lcdprocLocalPort(0U), m_lcdprocLocalPort(0U),
m_lcdprocDisplayClock(false), m_lcdprocDisplayClock(false),
m_lcdprocUTC(false) m_lcdprocUTC(false),
m_lockFileEnabled(false),
m_lockFileName()
{ {
} }
@@ -314,6 +317,8 @@ bool CConf::read()
section = SECTION_OLED; section = SECTION_OLED;
else if (::strncmp(buffer, "[LCDproc]", 9U) == 0) else if (::strncmp(buffer, "[LCDproc]", 9U) == 0)
section = SECTION_LCDPROC; section = SECTION_LCDPROC;
else if (::strncmp(buffer, "[LOCKFILE]", 9U) == 0)
section = SECTION_LOCKFILE;
else else
section = SECTION_NONE; section = SECTION_NONE;
@@ -785,6 +790,11 @@ bool CConf::read()
m_lcdprocUTC = ::atoi(value) == 1; m_lcdprocUTC = ::atoi(value) == 1;
else if (::strcmp(key, "DimOnIdle") == 0) else if (::strcmp(key, "DimOnIdle") == 0)
m_lcdprocDimOnIdle = ::atoi(value) == 1; m_lcdprocDimOnIdle = ::atoi(value) == 1;
} else if (section == SECTION_LOCKFILE) {
if (::strcmp(key, "Enable") == 0)
m_lockFileEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "File") == 0)
m_lockFileName = value;
} }
} }
@@ -1692,3 +1702,13 @@ bool CConf::getNextionTempInFahrenheit() const
{ {
return m_nextionTempInFahrenheit; return m_nextionTempInFahrenheit;
} }
bool CConf::getLockFileEnabled() const
{
return m_lockFileEnabled;
}
std::string CConf::getLockFileName() const
{
return m_lockFileName;
}

8
Conf.h
View File

@@ -262,6 +262,11 @@ public:
bool getLCDprocUTC() const; bool getLCDprocUTC() const;
bool getLCDprocDimOnIdle() const; bool getLCDprocDimOnIdle() const;
// The Lock File section
bool getLockFileEnabled() const;
std::string getLockFileName() const;
private: private:
std::string m_file; std::string m_file;
std::string m_callsign; std::string m_callsign;
@@ -469,6 +474,9 @@ private:
bool m_lcdprocDisplayClock; bool m_lcdprocDisplayClock;
bool m_lcdprocUTC; bool m_lcdprocUTC;
bool m_lcdprocDimOnIdle; bool m_lcdprocDimOnIdle;
bool m_lockFileEnabled;
std::string m_lockFileName;
}; };
#endif #endif

View File

@@ -826,6 +826,8 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)
return false; return false;
if (m_rfN == m_lastrfN) if (m_rfN == m_lastrfN)
return false; return false;
if (m_rfN != (m_lastrfN + 1U))
return false;
m_lastrfN = m_rfN; m_lastrfN = m_rfN;
// Regenerate the EMB // Regenerate the EMB

View File

@@ -240,3 +240,7 @@ Port=13666
DimOnIdle=0 DimOnIdle=0
DisplayClock=1 DisplayClock=1
UTC=0 UTC=0
[LOCKFILE]
Enable=0
File=/tmp/MMDVM_Active.lck

View File

@@ -155,7 +155,9 @@ m_dmrLookup(NULL),
m_nxdnLookup(NULL), m_nxdnLookup(NULL),
m_callsign(), m_callsign(),
m_id(0U), m_id(0U),
m_cwCallsign() m_cwCallsign(),
m_lockFileEnabled(false),
m_lockFileName()
{ {
} }
@@ -342,6 +344,12 @@ int CMMDVMHost::run()
m_modem->setTransparentDataParams(sendFrameType); m_modem->setTransparentDataParams(sendFrameType);
} }
if (m_conf.getLockFileEnabled()) {
m_lockFileName = m_conf.getLockFileName();
LogInfo("Lock File Parameters");
LogInfo(" Name: %s", m_lockFileName.c_str());
}
if (m_conf.getCWIdEnabled()) { if (m_conf.getCWIdEnabled()) {
unsigned int time = m_conf.getCWIdTime(); unsigned int time = m_conf.getCWIdTime();
m_cwCallsign = m_conf.getCWIdCallsign(); m_cwCallsign = m_conf.getCWIdCallsign();
@@ -576,6 +584,7 @@ int CMMDVMHost::run()
while (!m_killed) { while (!m_killed) {
bool lockout1 = m_modem->hasLockout(); bool lockout1 = m_modem->hasLockout();
bool lockout2 = false; bool lockout2 = false;
if (m_ump != NULL) if (m_ump != NULL)
lockout2 = m_ump->getLockout(); lockout2 = m_ump->getLockout();
if ((lockout1 || lockout2) && m_mode != MODE_LOCKOUT) if ((lockout1 || lockout2) && m_mode != MODE_LOCKOUT)
@@ -596,6 +605,9 @@ int CMMDVMHost::run()
m_ump->setCD(cd); m_ump->setCD(cd);
} }
if (m_mode == MODE_IDLE)
removeLockFile();
unsigned char data[200U]; unsigned char data[200U];
unsigned int len; unsigned int len;
bool ret; bool ret;
@@ -1381,6 +1393,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_mode = MODE_DSTAR; m_mode = MODE_DSTAR;
m_modeTimer.start(); m_modeTimer.start();
m_cwIdTimer.stop(); m_cwIdTimer.stop();
createLockFile();
break; break;
case MODE_DMR: case MODE_DMR:
@@ -1404,6 +1417,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_mode = MODE_DMR; m_mode = MODE_DMR;
m_modeTimer.start(); m_modeTimer.start();
m_cwIdTimer.stop(); m_cwIdTimer.stop();
createLockFile();
break; break;
case MODE_YSF: case MODE_YSF:
@@ -1423,6 +1437,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_mode = MODE_YSF; m_mode = MODE_YSF;
m_modeTimer.start(); m_modeTimer.start();
m_cwIdTimer.stop(); m_cwIdTimer.stop();
createLockFile();
break; break;
case MODE_P25: case MODE_P25:
@@ -1442,6 +1457,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_mode = MODE_P25; m_mode = MODE_P25;
m_modeTimer.start(); m_modeTimer.start();
m_cwIdTimer.stop(); m_cwIdTimer.stop();
createLockFile();
break; break;
case MODE_NXDN: case MODE_NXDN:
@@ -1461,6 +1477,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_mode = MODE_NXDN; m_mode = MODE_NXDN;
m_modeTimer.start(); m_modeTimer.start();
m_cwIdTimer.stop(); m_cwIdTimer.stop();
createLockFile();
break; break;
case MODE_POCSAG: case MODE_POCSAG:
@@ -1480,6 +1497,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_mode = MODE_POCSAG; m_mode = MODE_POCSAG;
m_modeTimer.start(); m_modeTimer.start();
m_cwIdTimer.stop(); m_cwIdTimer.stop();
createLockFile();
break; break;
case MODE_LOCKOUT: case MODE_LOCKOUT:
@@ -1564,11 +1582,41 @@ void CMMDVMHost::setMode(unsigned char mode)
m_cwIdTimer.start(); m_cwIdTimer.start();
} }
m_display->setIdle(); m_display->setIdle();
if (mode==MODE_QUIT) { if (mode == MODE_QUIT) {
m_display->setQuit(); m_display->setQuit();
removeLockFile();
} }
m_mode = MODE_IDLE; m_mode = MODE_IDLE;
m_modeTimer.stop(); m_modeTimer.stop();
removeLockFile();
break; break;
} }
} }
void CMMDVMHost::createLockFile()
{
if (m_lockFileEnabled) {
FILE* fp = ::fopen(m_lockFileName.c_str(), "r");
if (fp == NULL) { //if file does not exist, create it
fp = ::fopen(m_lockFileName.c_str(), "wt");
if (fp != NULL) {
::fputs("ACTIVE\n", fp);
::fclose(fp);
}
}
else {
::fclose(fp);
}
}
}
void CMMDVMHost::removeLockFile()
{
if (m_lockFileEnabled) {
FILE* fp = ::fopen(m_lockFileName.c_str(), "r");
if (fp != NULL) {
::fclose(fp);
::remove(m_lockFileName.c_str());
}
}
}

View File

@@ -35,6 +35,8 @@
#include <string> #include <string>
class CMMDVMHost class CMMDVMHost
{ {
public: public:
@@ -83,6 +85,8 @@ private:
std::string m_callsign; std::string m_callsign;
unsigned int m_id; unsigned int m_id;
std::string m_cwCallsign; std::string m_cwCallsign;
bool m_lockFileEnabled;
std::string m_lockFileName;
void readParams(); void readParams();
bool createModem(); bool createModem();
@@ -94,6 +98,9 @@ private:
bool createPOCSAGNetwork(); bool createPOCSAGNetwork();
void setMode(unsigned char mode); void setMode(unsigned char mode);
void createLockFile();
void removeLockFile();
}; };
#endif #endif