Example #1
0
void CUsers::Hearing(const CCallsign &my, const CCallsign &rpt1, const CCallsign &xlx)
{
    CUser heard(my, rpt1, xlx);
    
    // first check if we have this user listed yet
    bool found = false;
    for ( int i = 0; (i < m_Users.size()) && !found; i++ )
    {
        found = (m_Users[i] == heard);
        if ( found )
        {
            m_Users[i].HeardNow();
        }
    }
    
    // if not found, add user to list
    // otherwise just re-sort the list
    if ( !found )
    {
        AddUser(heard);
    }
    else
    {
        std::sort(m_Users.begin(), m_Users.end());
    }
}
Example #2
0
void LxMQApp::start()
{
	QStringList args = QCoreApplication::arguments();
	if(args.size() < 3) 
	{
		qWarning() << "Usage: " << args.front() << " client|server <key>";
		QCoreApplication::exit();
		return;
	}

	m_byteKey = args.at(2).toLocal8Bit();

	QTimer *ndyt = new QTimer(this);
	connect(ndyt, SIGNAL(timeout()), this, SLOT(ndy()));
	ndyt->setInterval(5000);
	ndyt->start();

	if(args.at(1) == "client") 
	{
		m_pSocket = new ZmqSocket(ZMQ_SUB, this);
		connect(m_pSocket, SIGNAL(readyRead()), this, SLOT(heard()));
		m_pSocket->subscribe(m_byteKey);
		m_pSocket->connectTo("tcp://127.0.0.1:3782");
	}

	if(args.at(1) == "server") 
	{
		m_pSocket = new ZmqSocket(ZMQ_PUB, this);
		m_pSocket->bind("tcp://127.0.0.1:3782");
		QTimer *t = new QTimer(this);
		connect(t, SIGNAL(timeout()), this, SLOT(squawk()));
		t->setInterval(1000);
		t->start();
	}
}
void CCCSHandler::writeHeard(CHeaderData& header)
{
	if (m_state != CS_CONNECTED && m_state != CS_ACTIVE)
		return;

	CHeardData heard(header, m_callsign, m_reflector);
	heard.setDestination(m_ccsAddress, CCS_PORT);
	m_protocol.writeHeard(heard);
}
void CCCSHandler::clockInt(unsigned int ms)
{
	m_announceTimer.clock(ms);
	m_pollInactivityTimer.clock(ms);
	m_inactivityTimer.clock(ms);
	m_pollTimer.clock(ms);
	m_waitTimer.clock(ms);
	m_tryTimer.clock(ms);

	if (m_pollInactivityTimer.isRunning() && m_pollInactivityTimer.hasExpired()) {
		wxLogMessage(wxT("CCS: Connection has failed (poll inactivity) for %s, reconnecting"), m_callsign.c_str());

		m_announceTimer.stop();
		m_pollInactivityTimer.stop();
		m_inactivityTimer.stop();
		m_pollTimer.stop();

		if (m_state == CS_ACTIVE) {
			m_stateChange = true;
			m_handler->ccsLinkEnded(m_yourCall);
		}

		m_waitTimer.start();

		m_state = CS_CONNECTING;

		return;
	}

	if (m_tryTimer.isRunning() && m_tryTimer.hasExpired()) {
		CConnectData connect(m_callsign, CT_LINK1, m_ccsAddress, CCS_PORT);
		m_protocol.writeConnect(connect);

		unsigned int t = calcBackoff();
		m_tryTimer.setTimeout(t);
		m_tryTimer.reset();
	}

	if (m_pollTimer.isRunning() && m_pollTimer.hasExpired()) {
		CPollData poll(m_callsign, m_ccsAddress, CCS_PORT);
		m_protocol.writePoll(poll);

		m_pollTimer.reset();
	}

	if (m_inactivityTimer.isRunning() && m_inactivityTimer.hasExpired()) {
		wxLogMessage(wxT("CCS: Activity timeout on link for %s"), m_callsign.c_str());
		m_stateChange = true;
		m_state       = CS_CONNECTED;
		m_inactivityTimer.stop();

		m_handler->ccsLinkEnded(m_yourCall);
	}

	if (m_waitTimer.isRunning() && m_waitTimer.hasExpired()) {
		CConnectData connect(m_callsign, CT_LINK1, m_ccsAddress, CCS_PORT);
		if (m_latitude != 0.0 && m_longitude != 0.0) {
			wxString locator = CUtils::latLonToLoc(m_latitude, m_longitude);
			connect.setLocator(locator);
		}
		m_protocol.writeConnect(connect);

		m_tryTimer.setTimeout(1U);
		m_tryTimer.start();

		m_tryCount = 1U;

		m_waitTimer.stop();
	}

	if (m_announceTimer.isRunning() && m_announceTimer.hasExpired()) {
		CHeaderData header;
		header.setMyCall1(m_callsign.Left(LONG_CALLSIGN_LENGTH - 1U));
		CHeardData heard(header, m_callsign, wxEmptyString);
		heard.setDestination(m_ccsAddress, CCS_PORT);
		m_protocol.writeHeard(heard);

		m_announceTimer.setTimeout(3600U);
		m_announceTimer.reset();
	}
}