Пример #1
0
// DTMF to YOUR call command
wxString CDTMF::translate()
{
	wxString command = m_command;
	m_command.Clear();

	if (command.IsEmpty())
		return wxEmptyString;

	if (command.IsSameAs(wxT("#")))
		return wxT("       U");

	if (command.IsSameAs(wxT("0")))
		return wxT("       I");

	if (command.IsSameAs(wxT("A")))
		return wxT("CCSA");

	if (command.IsSameAs(wxT("00")))
		return wxT("       I");

	if (command.GetChar(0U) == wxT('*'))
		return processDPlus(command.Mid(1U));
	else if (command.GetChar(0U) == wxT('B'))
		return processDExtra(command.Mid(1U));
	else if (command.GetChar(0U) == wxT('D'))
		return processDCS(command.Mid(1U));
	else
		return processCCS(command);
}
Пример #2
0
void CIRCDDBGatewayThread::run()
{
	// Truncate the old Links.log file
	wxString fullName = LINKS_BASE_NAME;

	if (!m_name.IsEmpty()) {
		fullName.Append(wxT("_"));
		fullName.Append(m_name);
	}

	wxFileName fileName1(m_logDir, fullName, wxT("log"));
	wxLogMessage(wxT("Truncating %s"), fileName1.GetFullPath().c_str());

	wxFFile file;
	bool ret = file.Open(fileName1.GetFullPath(), wxT("wt"));
	if (ret)
		file.Close();

	// Truncate the old StarNet.log file
	fullName = STARNET_BASE_NAME;

	if (!m_name.IsEmpty()) {
		fullName.Append(wxT("_"));
		fullName.Append(m_name);
	}

	wxFileName fileName2(m_logDir, fullName, wxT("log"));
	wxLogMessage(wxT("Truncating %s"), fileName2.GetFullPath().c_str());

	ret = file.Open(fileName2.GetFullPath(), wxT("wt"));
	if (ret)
		file.Close();

	wxString dextraAddress = m_dextraEnabled ? m_gatewayAddress : LOOPBACK_ADDRESS;
	m_dextraPool = new CDExtraProtocolHandlerPool(MAX_OUTGOING + 1U, DEXTRA_PORT, dextraAddress);
	ret = m_dextraPool->open();
	if (!ret) {
		wxLogError(wxT("Could not open the DExtra protocol pool"));
		delete m_dextraPool;
		m_dextraPool = NULL;
	} else {
		// Allocate the incoming port
		CDExtraProtocolHandler* handler = m_dextraPool->getHandler(DEXTRA_PORT);
		CDExtraHandler::setDExtraProtocolIncoming(handler);
		CDExtraHandler::setDExtraProtocolHandlerPool(m_dextraPool);
	}

	wxString dplusAddress = m_dplusEnabled ? m_gatewayAddress : LOOPBACK_ADDRESS;
	m_dplusPool = new CDPlusProtocolHandlerPool(MAX_OUTGOING + 1U, DPLUS_PORT, dplusAddress);
	ret = m_dplusPool->open();
	if (!ret) {
		wxLogError(wxT("Could not open the D-Plus protocol pool"));
		delete m_dplusPool;
		m_dplusPool = NULL;
	} else {
		// Allocate the incoming port
		CDPlusProtocolHandler* handler = m_dplusPool->getHandler(DPLUS_PORT);
		CDPlusHandler::setDPlusProtocolIncoming(handler);
		CDPlusHandler::setDPlusProtocolHandlerPool(m_dplusPool);
	}

	wxString dcsAddress = m_dcsEnabled ? m_gatewayAddress : LOOPBACK_ADDRESS;
	m_dcsPool = new CDCSProtocolHandlerPool(MAX_OUTGOING + 1U, DCS_PORT, dcsAddress);
	ret = m_dcsPool->open();
	if (!ret) {
		wxLogError(wxT("Could not open the DCS protocol pool"));
		delete m_dcsPool;
		m_dcsPool = NULL;
	} else {
		// Allocate the incoming port
		CDCSProtocolHandler* handler = m_dcsPool->getHandler(DCS_PORT);
		CDCSHandler::setDCSProtocolIncoming(handler);
		CDCSHandler::setDCSProtocolHandlerPool(m_dcsPool);
	}

	m_g2Handler = new CG2ProtocolHandler(G2_DV_PORT, m_gatewayAddress);
	ret = m_g2Handler->open();
	if (!ret) {
		wxLogError(wxT("Could not open the G2 protocol handler"));
		delete m_g2Handler;
		m_g2Handler = NULL;
	}

	// Wait here until we have the essentials to run
	while (!m_killed && (m_dextraPool == NULL || m_dplusPool == NULL || m_dcsPool == NULL || m_g2Handler == NULL || (m_icomRepeaterHandler == NULL && m_hbRepeaterHandler == NULL && m_dummyRepeaterHandler == NULL) || m_gatewayCallsign.IsEmpty()))
		::wxMilliSleep(500UL);		// 1/2 sec

	if (m_killed)
		return;

	m_stopped = false;

	wxLogMessage(wxT("Starting the ircDDB Gateway thread"));

	CHeaderLogger* headerLogger = NULL;
	if (m_logEnabled) {
		m_statusTimer1.start();

		headerLogger = new CHeaderLogger(m_logDir, m_name);
		bool ret = headerLogger->open();
		if (!ret) {
			delete headerLogger;
			headerLogger = NULL;
		}
	}

	loadGateways();
	loadReflectors();

	CG2Handler::setG2ProtocolHandler(m_g2Handler);
	CG2Handler::setHeaderLogger(headerLogger);

	CDExtraHandler::setCallsign(m_gatewayCallsign);
	CDExtraHandler::setHeaderLogger(headerLogger);
	CDExtraHandler::setMaxDongles(m_dextraMaxDongles);

	CDPlusHandler::setCallsign(m_gatewayCallsign);
	CDPlusHandler::setDPlusLogin(m_dplusLogin);
	CDPlusHandler::setHeaderLogger(headerLogger);
	CDPlusHandler::setMaxDongles(m_dplusMaxDongles);
	if (m_dplusEnabled)
		CDPlusHandler::startAuthenticator(m_gatewayAddress, &m_cache);

	CDCSHandler::setGatewayType(m_gatewayType);
	CDCSHandler::setHeaderLogger(headerLogger);

	CRepeaterHandler::setLocalAddress(m_gatewayAddress);
	CRepeaterHandler::setG2Handler(m_g2Handler);

	if (m_irc != NULL)
		CRepeaterHandler::setIRC(m_irc);

	CRepeaterHandler::setCache(&m_cache);
	CRepeaterHandler::setGateway(m_gatewayCallsign);
	CRepeaterHandler::setLanguage(m_language);
	CRepeaterHandler::setDExtraEnabled(m_dextraEnabled);
	CRepeaterHandler::setDPlusEnabled(m_dplusEnabled);
	CRepeaterHandler::setDCSEnabled(m_dcsEnabled);
	CRepeaterHandler::setHeaderLogger(headerLogger);
	CRepeaterHandler::setAPRSWriter(m_aprsWriter);
	CRepeaterHandler::setInfoEnabled(m_infoEnabled);
	CRepeaterHandler::setEchoEnabled(m_echoEnabled);
	CRepeaterHandler::setDTMFEnabled(m_dtmfEnabled);
	if (m_whiteList != NULL) {
		CDExtraHandler::setWhiteList(m_whiteList);
		CDPlusHandler::setWhiteList(m_whiteList);
		CDCSHandler::setWhiteList(m_whiteList);
	}
	if (m_blackList != NULL) {
		CDExtraHandler::setBlackList(m_blackList);
		CDPlusHandler::setBlackList(m_blackList);
		CDCSHandler::setBlackList(m_blackList);
	}
	if (m_restrictList != NULL)
		CRepeaterHandler::setRestrictList(m_restrictList);

	CAudioUnit::setLanguage(m_language);

	CStarNetHandler::setCache(&m_cache);
	CStarNetHandler::setGateway(m_gatewayCallsign);
	CStarNetHandler::setG2Handler(m_g2Handler);

	if (m_irc != NULL)
		CStarNetHandler::setIRC(m_irc);

	CStarNetHandler::setLogging(m_logEnabled, m_logDir);
#if defined(DEXTRA_LINK) || defined(DCS_LINK)
	CStarNetHandler::link();
#endif

	if (m_ddModeEnabled) {
		CDDHandler::initialise(MAX_DD_ROUTES, m_name);
		CDDHandler::setLogging(m_logEnabled, m_logDir);
		CDDHandler::setHeaderLogger(headerLogger);

		if (m_irc != NULL)
			CDDHandler::setIRC(m_irc);
	}

	wxString ccsAddress = m_ccsEnabled ? m_gatewayAddress : LOOPBACK_ADDRESS;
	CCCSHandler::setLocalAddress(ccsAddress);
	CCCSHandler::setHeaderLogger(headerLogger);
	CCCSHandler::setHost(m_ccsHost);

	// If no ircDDB then APRS is started immediately
	if (m_aprsWriter != NULL && m_irc == NULL)
		m_aprsWriter->setEnabled(true);

	if (m_remoteEnabled && !m_remotePassword.IsEmpty() && m_remotePort > 0U) {
		m_remote = new CRemoteHandler(m_remotePassword, m_remotePort, m_gatewayAddress);
		bool res = m_remote->open();
		if (!res) {
			delete m_remote;
			m_remote = NULL;
		}
	}

	CRepeaterHandler::startup();

	m_statusFileTimer.start();

	CCallsignServer* server = NULL;
	if (m_dextraEnabled || m_dcsEnabled) {
		server = new CCallsignServer(m_gatewayCallsign, m_gatewayAddress, &m_cache);
		server->start();
	}

	wxStopWatch stopWatch;
	stopWatch.Start();

	m_statusTimer2.start();

	try {
		while (!m_killed) {
			if (m_icomRepeaterHandler != NULL)
				processRepeater(m_icomRepeaterHandler);

			if (m_hbRepeaterHandler != NULL)
				processRepeater(m_hbRepeaterHandler);

			if (m_dummyRepeaterHandler != NULL)
				processRepeater(m_dummyRepeaterHandler);

			if (m_irc != NULL)
				processIrcDDB();

			processDExtra();
			processDPlus();
			processDCS();
			processG2();
			CCCSHandler::process();

			if (m_ddModeEnabled)
				processDD();

			if (m_remote != NULL)
				m_remote->process();

			unsigned long ms = stopWatch.Time();
			stopWatch.Start();

			CRepeaterHandler::clock(ms);
			CG2Handler::clock(ms);
			CDExtraHandler::clock(ms);
			CDPlusHandler::clock(ms);
			CDCSHandler::clock(ms);
			CStarNetHandler::clock(ms);
			CDDHandler::clock(ms);
	 		CCCSHandler::clock(ms);

			m_statusTimer2.clock(ms);

			m_statusFileTimer.clock(ms);
			if (m_statusFileTimer.hasExpired()) {
				readStatusFiles();
				m_statusFileTimer.start();
			}

			if (m_aprsWriter != NULL)
				m_aprsWriter->clock(ms);

			if (m_logEnabled) {
				m_statusTimer1.clock(ms);
				if (m_statusTimer1.hasExpired()) {
					bool ret1 = CDExtraHandler::stateChange();
					bool ret2 = CDPlusHandler::stateChange();
					bool ret3 = CDCSHandler::stateChange();
					bool ret4 = CCCSHandler::stateChange();
					if (ret1 || ret2 || ret3 || ret4)
						writeStatus();
		
					m_statusTimer1.start();
				}
			}

			::wxMilliSleep(TIME_PER_TIC_MS);
		}
	}
	catch (std::exception& e) {
		wxString message(e.what(), wxConvLocal);
		wxLogError(wxT("Exception raised in the main thread - \"%s\""), message.c_str());
	}
	catch (...) {
		wxLogError(wxT("Unknown exception raised in the main thread"));
	}

	wxLogMessage(wxT("Stopping the ircDDB Gateway thread"));

	// Unlink from all reflectors
	CDExtraHandler::unlink();
	CDPlusHandler::unlink();
	CDCSHandler::unlink();
	CCCSHandler::disconnect();

	if (m_ddModeEnabled)
		CDDHandler::finalise();

	if (server != NULL)
		server->stop();

	m_dextraPool->close();
	delete m_dextraPool;

	m_dplusPool->close();
	delete m_dplusPool;

	m_dcsPool->close();
	delete m_dcsPool;

	m_g2Handler->close();
	delete m_g2Handler;

	if (m_irc != NULL) {
		m_irc->close();
		delete m_irc;
	}

	if (m_icomRepeaterHandler != NULL) {
		m_icomRepeaterHandler->close();
		delete m_icomRepeaterHandler;
	}

	if (m_hbRepeaterHandler != NULL) {
		m_hbRepeaterHandler->close();
		delete m_hbRepeaterHandler;
	}

	if (m_dummyRepeaterHandler != NULL) {
		m_dummyRepeaterHandler->close();
		delete m_dummyRepeaterHandler;
	}

	if (m_remote != NULL) {
		m_remote->close();
		delete m_remote;
	}

	if (headerLogger != NULL) {
		headerLogger->close();
		delete headerLogger;
	}
}
void CXReflectorThread::run()
{
	// Truncate the old Links.log file
	wxString fullName = LINKS_BASE_NAME;

	if (!m_name.IsEmpty()) {
		fullName.Append(wxT("_"));
		fullName.Append(m_name);
	}

	wxFileName fileName(m_logDir, fullName, wxT("log"));

	wxLogMessage(wxT("Truncating %s"), fileName.GetFullPath().c_str());

	wxFFile file;
	bool ret = file.Open(fileName.GetFullPath(), wxT("wt"));
	if (ret)
		file.Close();

	m_dextraHandler = new CDExtraProtocolHandler(DEXTRA_PORT, m_address);
	ret = m_dextraHandler->open();
	if (!ret) {
		wxLogError(wxT("Could not open the DExtra protocol handler"));
		delete m_dextraHandler;
		m_dextraHandler = NULL;
	}

	m_dplusHandler = new CDPlusProtocolHandler(m_dplusPort, m_address);
	ret = m_dplusHandler->open();
	if (!ret) {
		wxLogError(wxT("Could not open the DPlus protocol handler"));
		delete m_dplusHandler;
		m_dplusHandler = NULL;
	}

	// Wait here until we have the essentials to run
	while (!m_killed && (m_dextraHandler == NULL || m_dplusHandler == NULL || m_callsign.IsEmpty()))
		::wxMilliSleep(500UL);		// 1/2 sec

	if (m_killed)
		return;

	m_stopped = false;

	wxLogMessage(wxT("Starting the Reflector thread"));

	CXReflectorUserLog* userLogger = NULL;
	if (m_logEnabled) {
		m_statusTimer.start();

		userLogger = new CXReflectorUserLog(m_logDir, m_name);
		bool ret = userLogger->open();
		if (!ret) {
			delete userLogger;
			userLogger = NULL;
		}
	}

	CXReflectorDExtraHandler::setCallsign(m_callsign);
	CXReflectorDExtraHandler::setDExtraProtocolHandler(m_dextraHandler);
	CXReflectorDExtraHandler::setUserLogger(userLogger);

	CXReflectorDPlusHandler::setCallsign(m_callsign);
	CXReflectorDPlusHandler::setDPlusProtocolHandler(m_dplusHandler);
	CXReflectorDPlusHandler::setUserLogger(userLogger);

	CXReflectorReflectorHandler::setLogDirectory(m_logDir);

	wxStopWatch stopWatch;
	stopWatch.Start();

	while (!m_killed) {
		processDExtra();
		processDPlus();

		if (m_logEnabled && m_statusTimer.hasExpired()) {
			if (CXReflectorDExtraHandler::stateChange() || CXReflectorDPlusHandler::stateChange())
				writeStatus();
			m_statusTimer.reset();
		}

		::wxMilliSleep(TIME_PER_TIC_MS);

		unsigned long ms = stopWatch.Time();

		stopWatch.Start();

		CXReflectorReflectorHandler::clock(ms);
		CXReflectorDExtraHandler::clock(ms);
		CXReflectorDPlusHandler::clock(ms);

		if (m_logEnabled)
			m_statusTimer.clock(ms);
	}

	wxLogMessage(wxT("Stopping the XReflector thread"));

	// Unlink from all reflectors
	CXReflectorDExtraHandler::unlink();
	CXReflectorDPlusHandler::unlink();

	m_dextraHandler->close();
	delete m_dextraHandler;

	m_dplusHandler->close();
	delete m_dplusHandler;

	if (userLogger != NULL) {
		userLogger->close();
		delete userLogger;
	}
}
void* CStarNetServerThread::Entry()
{
	// Truncate the old StarNet.log file
	wxFileName fileName(m_logDir, STARNET_BASE_NAME, wxT("log"));
	wxLogMessage(wxT("Truncating %s"), fileName.GetFullPath().c_str());

	wxFFile file;
	bool ret = file.Open(fileName.GetFullPath(), wxT("wt"));
	if (ret)
		file.Close();

#if defined(DEXTRA_LINK)
	m_dextraHandler = new CDExtraProtocolHandler(DEXTRA_PORT, m_address);
	ret = m_dextraHandler->open();
	if (!ret) {
		wxLogError(wxT("Could not open the DExtra protocol handler"));
		delete m_dextraHandler;
		m_dextraHandler = NULL;
	}
#endif

#if defined(DCS_LINK)
	m_dcsHandler = new CDCSProtocolHandler(DCS_PORT, m_address);
	ret = m_dcsHandler->open();
	if (!ret) {
		wxLogError(wxT("Could not open the DCS protocol handler"));
		delete m_dcsHandler;
		m_dcsHandler = NULL;
	}
#endif

	m_g2Handler = new CG2ProtocolHandler(G2_DV_PORT, m_address);
	ret = m_g2Handler->open();
	if (!ret) {
		wxLogError(wxT("Could not open the G2 protocol handler"));
		delete m_g2Handler;
		m_g2Handler = NULL;
	}

	// Wait here until we have the essentials to run
#if defined(DEXTRA_LINK)
	while (!m_killed && (m_g2Handler == NULL || m_dextraHandler == NULL || m_irc == NULL || m_callsign.IsEmpty()))
		Sleep(500UL);		// 1/2 sec
#elif defined(DCS_LINK)
	while (!m_killed && (m_g2Handler == NULL || m_dcsHandler == NULL || m_irc == NULL || m_callsign.IsEmpty()))
		Sleep(500UL);		// 1/2 sec
#else
	while (!m_killed && (m_g2Handler == NULL || m_irc == NULL || m_callsign.IsEmpty()))
		Sleep(500UL);		// 1/2 sec
#endif

	if (m_killed)
		return NULL;

	m_stopped = false;

	wxLogMessage(wxT("Starting the StarNet Server thread"));

	CHeaderLogger* headerLogger = NULL;
	if (m_logEnabled) {
		headerLogger = new CHeaderLogger(m_logDir);
		bool ret = headerLogger->open();
		if (!ret) {
			delete headerLogger;
			headerLogger = NULL;
		}
	}

#if defined(DEXTRA_LINK) || defined(DCS_LINK)
	loadReflectors();
#endif

	CG2Handler::setG2ProtocolHandler(m_g2Handler);
	CG2Handler::setHeaderLogger(headerLogger);

#if defined(DEXTRA_LINK)
	CDExtraHandler::setCallsign(m_callsign);
	CDExtraHandler::setDExtraProtocolHandler(m_dextraHandler);
	CDExtraHandler::setHeaderLogger(headerLogger);
#endif
#if defined(DCS_LINK)
	CDCSHandler::setCallsign(m_callsign);
	CDCSHandler::setDCSProtocolHandler(m_dcsHandler);
	CDCSHandler::setHeaderLogger(headerLogger);
#endif

	CStarNetHandler::setCache(&m_cache);
	CStarNetHandler::setGateway(m_callsign);
	CStarNetHandler::setG2Handler(m_g2Handler);
	CStarNetHandler::setIRC(m_irc);
	CStarNetHandler::setLogging(m_logEnabled, m_logDir);
#if defined(DEXTRA_LINK) || defined(DCS_LINK)
	CStarNetHandler::link();
#endif

	if (m_remoteEnabled && !m_remotePassword.IsEmpty() && m_remotePort > 0U) {
		m_remote = new CRemoteHandler(m_remotePassword, m_remotePort);
		bool res = m_remote->open();
		if (!res) {
			delete m_remote;
			m_remote = NULL;
		}
	}

	wxStopWatch stopWatch;
	stopWatch.Start();

	m_statusTimer.start();

	while (!m_killed) {
		processIrcDDB();
		processG2();
#if defined(DEXTRA_LINK)
		processDExtra();
#endif
#if defined(DCS_LINK)
		processDCS();
#endif
		if (m_remote != NULL)
			m_remote->process();

		unsigned long ms = stopWatch.Time();
		stopWatch.Start();

		m_statusTimer.clock(ms);

		CG2Handler::clock(ms);
		CStarNetHandler::clock(ms);
#if defined(DEXTRA_LINK)
		CDExtraHandler::clock(ms);
#endif
#if defined(DCS_LINK)
		CDCSHandler::clock(ms);
#endif

		Sleep(TIME_PER_TIC_MS);
	}

	wxLogMessage(wxT("Stopping the StarNet Server thread"));

#if defined(DEXTRA_LINK)
	// Unlink from all reflectors
	CDExtraHandler::unlink();

	m_dextraHandler->close();
	delete m_dextraHandler;
#endif

#if defined(DCS_LINK)
	// Unlink from all reflectors
	CDCSHandler::unlink();

	m_dcsHandler->close();
	delete m_dcsHandler;
#endif

	m_g2Handler->close();
	delete m_g2Handler;

	m_irc->close();
	delete m_irc;

	if (m_remote != NULL) {
		m_remote->close();
		delete m_remote;
	}

	if (headerLogger != NULL) {
		headerLogger->close();
		delete headerLogger;
	}

	return NULL;
}