Add MMDVM lock file based on an idea by DB1OFH.
This commit is contained in:
parent
867e1745d8
commit
edaf37101a
24
Conf.cpp
24
Conf.cpp
|
@ -55,7 +55,8 @@ enum SECTION {
|
|||
SECTION_NEXTION,
|
||||
SECTION_OLED,
|
||||
SECTION_LCDPROC,
|
||||
SECTION_TGREWRITE
|
||||
SECTION_TGREWRITE,
|
||||
SECTION_LOCKFILE
|
||||
};
|
||||
|
||||
CConf::CConf(const std::string& file) :
|
||||
|
@ -238,7 +239,9 @@ m_lcdprocAddress(),
|
|||
m_lcdprocPort(0U),
|
||||
m_lcdprocLocalPort(0U),
|
||||
m_lcdprocDisplayClock(false),
|
||||
m_lcdprocUTC(false)
|
||||
m_lcdprocUTC(false),
|
||||
m_lockFileEnabled(false),
|
||||
m_lockFileName()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -314,6 +317,8 @@ bool CConf::read()
|
|||
section = SECTION_OLED;
|
||||
else if (::strncmp(buffer, "[LCDproc]", 9U) == 0)
|
||||
section = SECTION_LCDPROC;
|
||||
else if (::strncmp(buffer, "[LOCKFILE]", 9U) == 0)
|
||||
section = SECTION_LOCKFILE;
|
||||
else
|
||||
section = SECTION_NONE;
|
||||
|
||||
|
@ -785,6 +790,11 @@ bool CConf::read()
|
|||
m_lcdprocUTC = ::atoi(value) == 1;
|
||||
else if (::strcmp(key, "DimOnIdle") == 0)
|
||||
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;
|
||||
}
|
||||
|
||||
bool CConf::getLockFileEnabled() const
|
||||
{
|
||||
return m_lockFileEnabled;
|
||||
}
|
||||
|
||||
std::string CConf::getLockFileName() const
|
||||
{
|
||||
return m_lockFileName;
|
||||
}
|
||||
|
|
8
Conf.h
8
Conf.h
|
@ -262,6 +262,11 @@ public:
|
|||
bool getLCDprocUTC() const;
|
||||
bool getLCDprocDimOnIdle() const;
|
||||
|
||||
// The Lock File section
|
||||
bool getLockFileEnabled() const;
|
||||
std::string getLockFileName() const;
|
||||
|
||||
|
||||
private:
|
||||
std::string m_file;
|
||||
std::string m_callsign;
|
||||
|
@ -469,6 +474,9 @@ private:
|
|||
bool m_lcdprocDisplayClock;
|
||||
bool m_lcdprocUTC;
|
||||
bool m_lcdprocDimOnIdle;
|
||||
|
||||
bool m_lockFileEnabled;
|
||||
std::string m_lockFileName;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -826,6 +826,8 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len)
|
|||
return false;
|
||||
if (m_rfN == m_lastrfN)
|
||||
return false;
|
||||
if (m_rfN != (m_lastrfN + 1U))
|
||||
return false;
|
||||
m_lastrfN = m_rfN;
|
||||
|
||||
// Regenerate the EMB
|
||||
|
|
|
@ -240,3 +240,7 @@ Port=13666
|
|||
DimOnIdle=0
|
||||
DisplayClock=1
|
||||
UTC=0
|
||||
|
||||
[LOCKFILE]
|
||||
Enable=0
|
||||
File=/tmp/MMDVM_Active.lck
|
||||
|
|
|
@ -155,7 +155,9 @@ m_dmrLookup(NULL),
|
|||
m_nxdnLookup(NULL),
|
||||
m_callsign(),
|
||||
m_id(0U),
|
||||
m_cwCallsign()
|
||||
m_cwCallsign(),
|
||||
m_lockFileEnabled(false),
|
||||
m_lockFileName()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -342,6 +344,12 @@ int CMMDVMHost::run()
|
|||
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()) {
|
||||
unsigned int time = m_conf.getCWIdTime();
|
||||
m_cwCallsign = m_conf.getCWIdCallsign();
|
||||
|
@ -576,6 +584,7 @@ int CMMDVMHost::run()
|
|||
while (!m_killed) {
|
||||
bool lockout1 = m_modem->hasLockout();
|
||||
bool lockout2 = false;
|
||||
|
||||
if (m_ump != NULL)
|
||||
lockout2 = m_ump->getLockout();
|
||||
if ((lockout1 || lockout2) && m_mode != MODE_LOCKOUT)
|
||||
|
@ -596,6 +605,9 @@ int CMMDVMHost::run()
|
|||
m_ump->setCD(cd);
|
||||
}
|
||||
|
||||
if (m_mode == MODE_IDLE)
|
||||
removeLockFile();
|
||||
|
||||
unsigned char data[200U];
|
||||
unsigned int len;
|
||||
bool ret;
|
||||
|
@ -1381,6 +1393,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||
m_mode = MODE_DSTAR;
|
||||
m_modeTimer.start();
|
||||
m_cwIdTimer.stop();
|
||||
createLockFile();
|
||||
break;
|
||||
|
||||
case MODE_DMR:
|
||||
|
@ -1404,6 +1417,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||
m_mode = MODE_DMR;
|
||||
m_modeTimer.start();
|
||||
m_cwIdTimer.stop();
|
||||
createLockFile();
|
||||
break;
|
||||
|
||||
case MODE_YSF:
|
||||
|
@ -1423,6 +1437,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||
m_mode = MODE_YSF;
|
||||
m_modeTimer.start();
|
||||
m_cwIdTimer.stop();
|
||||
createLockFile();
|
||||
break;
|
||||
|
||||
case MODE_P25:
|
||||
|
@ -1442,6 +1457,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||
m_mode = MODE_P25;
|
||||
m_modeTimer.start();
|
||||
m_cwIdTimer.stop();
|
||||
createLockFile();
|
||||
break;
|
||||
|
||||
case MODE_NXDN:
|
||||
|
@ -1461,6 +1477,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||
m_mode = MODE_NXDN;
|
||||
m_modeTimer.start();
|
||||
m_cwIdTimer.stop();
|
||||
createLockFile();
|
||||
break;
|
||||
|
||||
case MODE_POCSAG:
|
||||
|
@ -1480,6 +1497,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||
m_mode = MODE_POCSAG;
|
||||
m_modeTimer.start();
|
||||
m_cwIdTimer.stop();
|
||||
createLockFile();
|
||||
break;
|
||||
|
||||
case MODE_LOCKOUT:
|
||||
|
@ -1564,11 +1582,41 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||
m_cwIdTimer.start();
|
||||
}
|
||||
m_display->setIdle();
|
||||
if (mode==MODE_QUIT) {
|
||||
if (mode == MODE_QUIT) {
|
||||
m_display->setQuit();
|
||||
removeLockFile();
|
||||
}
|
||||
m_mode = MODE_IDLE;
|
||||
m_modeTimer.stop();
|
||||
removeLockFile();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
class CMMDVMHost
|
||||
{
|
||||
public:
|
||||
|
@ -83,6 +85,8 @@ private:
|
|||
std::string m_callsign;
|
||||
unsigned int m_id;
|
||||
std::string m_cwCallsign;
|
||||
bool m_lockFileEnabled;
|
||||
std::string m_lockFileName;
|
||||
|
||||
void readParams();
|
||||
bool createModem();
|
||||
|
@ -94,6 +98,9 @@ private:
|
|||
bool createPOCSAGNetwork();
|
||||
|
||||
void setMode(unsigned char mode);
|
||||
|
||||
void createLockFile();
|
||||
void removeLockFile();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue