mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 15:09:23 +08:00
Add MMDVM lock file based on an idea by DB1OFH.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user