TRISTATE CDVAPNodeTRXThread::checkHeader(CHeaderData& header)
{
	// If not in RPT1 validation mode, then a simplex header is converted to a proper repeater header
	if (!m_rpt1Validation) {
		if (!header.isRepeaterMode()) {
			// Convert to a properly addressed repeater packet
			header.setRepeaterMode(true);
			header.setRptCall1(m_rptCallsign);
			header.setRptCall2(m_gwyCallsign);
		}
	}

	// The repeater bit must be set
	if (!header.isRepeaterMode()) {
		wxLogMessage(wxT("Received a non-repeater packet, ignoring"));
		return STATE_FALSE;
	}

	wxString my = header.getMyCall1();

	// Make sure MyCall is not empty, a silly value, or the repeater or gateway callsigns
	if (my.IsSameAs(m_rptCallsign) ||
		my.IsSameAs(m_gwyCallsign) ||
		my.Left(6U).IsSameAs(wxT("NOCALL")) ||
		my.Left(6U).IsSameAs(wxT("N0CALL")) ||
		my.Left(6U).IsSameAs(wxT("MYCALL"))) {
		wxLogMessage(wxT("Invalid MYCALL value of %s, ignoring"), my.c_str());
		return STATE_UNKNOWN;
	}

	// Check the MyCall value against the regular expression
	bool ok = m_regEx.Matches(my);
	if (!ok) {
		wxLogMessage(wxT("Invalid MYCALL value of %s, ignoring"), my.c_str());
		return STATE_UNKNOWN;
	}

	// Is it for us?
	if (!header.getRptCall1().IsSameAs(m_rptCallsign)) {
		wxLogMessage(wxT("Invalid RPT1 value %s, ignoring"), header.getRptCall1().c_str());
		return STATE_FALSE;
	}

	// If using callsign restriction, validate the my callsign
	if (m_restriction) {
		if (!my.Left(LONG_CALLSIGN_LENGTH - 1U).IsSameAs(m_rptCallsign.Left(LONG_CALLSIGN_LENGTH - 1U))) {
			wxLogMessage(wxT("Unauthorised user %s tried to access the repeater"), my.c_str());
			return STATE_UNKNOWN;
		}
	}

	return STATE_TRUE;
}
예제 #2
0
void CGMSKModemWinUSB::writeHeader(const CHeaderData& header)
{
	unsigned char myCall1[LONG_CALLSIGN_LENGTH];
	unsigned char myCall2[SHORT_CALLSIGN_LENGTH];
	unsigned char yourCall[LONG_CALLSIGN_LENGTH];
	unsigned char rptCall1[LONG_CALLSIGN_LENGTH];
	unsigned char rptCall2[LONG_CALLSIGN_LENGTH];

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		myCall1[i] = header.getMyCall1().GetChar(i);
	for (unsigned int i = 0U; i < SHORT_CALLSIGN_LENGTH; i++)
		myCall2[i] = header.getMyCall2().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		yourCall[i] = header.getYourCall().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		rptCall1[i] = header.getRptCall1().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		rptCall2[i] = header.getRptCall2().GetChar(i);

	io(SET_MyCALL2,  0x40U, 0U, myCall2,  SHORT_CALLSIGN_LENGTH);
	io(SET_MyCALL,   0x40U, 0U, myCall1,  LONG_CALLSIGN_LENGTH);
	io(SET_YourCALL, 0x40U, 0U, yourCall, LONG_CALLSIGN_LENGTH);
	io(SET_RPT1CALL, 0x40U, 0U, rptCall1, LONG_CALLSIGN_LENGTH);
	io(SET_RPT2CALL, 0x40U, 0U, rptCall2, LONG_CALLSIGN_LENGTH);

	unsigned char flags[3U];
	flags[0U] = header.getFlag1();
	flags[1U] = header.getFlag2();
	flags[2U] = header.getFlag3();

	io(SET_FLAGS, 0x40U, 0U, flags, 3U);

	setPTT(true);
}
bool CDVAPController::writeHeader(const CHeaderData& header)
{
	m_streamId++;

	unsigned char buffer[50U];

	::memcpy(buffer, DVAP_HEADER, DVAP_HEADER_LEN);

	wxUint16 sid = wxUINT16_SWAP_ON_BE(m_streamId);
	::memcpy(buffer + 2U, &sid, sizeof(wxUint16));

	buffer[4U] = 0x80U;
	buffer[5U] = 0U;

	::memset(buffer + 6U, ' ', RADIO_HEADER_LENGTH_BYTES);

	buffer[6U] = header.getFlag1();
	buffer[7U] = header.getFlag2();
	buffer[8U] = header.getFlag3();

	wxString rpt2 = header.getRptCall2();
	for (unsigned int i = 0U; i < rpt2.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 9U]  = rpt2.GetChar(i);

	wxString rpt1 = header.getRptCall1();
	for (unsigned int i = 0U; i < rpt1.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 17U] = rpt1.GetChar(i);

	wxString your = header.getYourCall();
	for (unsigned int i = 0U; i < your.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 25U] = your.GetChar(i);

	wxString my1 = header.getMyCall1();
	for (unsigned int i = 0U; i < my1.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 33U] = my1.GetChar(i);

	wxString my2 = header.getMyCall2();
	for (unsigned int i = 0U; i < my2.Len() && i < SHORT_CALLSIGN_LENGTH; i++)
		buffer[i + 41U] = my2.GetChar(i);

	CCCITTChecksumReverse cksum;
	cksum.update(buffer + 6U, RADIO_HEADER_LENGTH_BYTES - 2U);
	cksum.result(buffer + 45U);

	m_framePos = 0U;
	m_seq = 0U;

	wxMutexLocker locker(m_mutex);

	unsigned int space = m_txData.freeSpace();
	if (space < 48U)
		return false;

	unsigned char len = DVAP_HEADER_LEN;
	m_txData.addData(&len, 1U);

	m_txData.addData(buffer, DVAP_HEADER_LEN);

	return true;
}
예제 #4
0
bool CDVRPTRV3Controller::writeHeader(const CHeaderData& header)
{
	bool ret = m_txData.hasSpace(106U);
	if (!ret) {
		wxLogWarning(wxT("No space to write the header"));
		return false;
	}

	unsigned char buffer[105U];

	::memset(buffer, 0x00U, 105U);

	buffer[0U] = 'H';
	buffer[1U] = 'E';
	buffer[2U] = 'A';
	buffer[3U] = 'D';
	buffer[4U] = 'X';
	buffer[5U] = '0';
	buffer[6U] = '0';
	buffer[7U] = '0';
	buffer[8U] = '2';

	::memset(buffer + 9U, ' ', RADIO_HEADER_LENGTH_BYTES);

	buffer[9U]  = header.getFlag1();
	buffer[10U] = header.getFlag2();
	buffer[11U] = header.getFlag3();

	wxString rpt2 = header.getRptCall2();
	for (unsigned int i = 0U; i < rpt2.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 12U]  = rpt2.GetChar(i);

	wxString rpt1 = header.getRptCall1();
	for (unsigned int i = 0U; i < rpt1.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 20U] = rpt1.GetChar(i);

	wxString your = header.getYourCall();
	for (unsigned int i = 0U; i < your.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 28U] = your.GetChar(i);

	wxString my1 = header.getMyCall1();
	for (unsigned int i = 0U; i < my1.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 36U] = my1.GetChar(i);

	wxString my2 = header.getMyCall2();
	for (unsigned int i = 0U; i < my2.Len() && i < SHORT_CALLSIGN_LENGTH; i++)
		buffer[i + 44U] = my2.GetChar(i);

	wxMutexLocker locker(m_mutex);

	unsigned char len = 105U;
	m_txData.addData(&len, 1U);

	m_txData.addData(buffer, 105U);

	m_tx = true;

	return true;
}
bool CRepeaterProtocolHandler::writeHeader(const CHeaderData& header)
{
	unsigned char buffer[50U];

	buffer[0] = 'D';
	buffer[1] = 'S';
	buffer[2] = 'R';
	buffer[3] = 'P';

	buffer[4] = 0x20U;

	// Create a random id for this transmission
	m_outId = (::rand() % 65535U) + 1U;

	buffer[5] = m_outId / 256U;	// Unique session id
	buffer[6] = m_outId % 256U;

	buffer[7] = 0U;

	buffer[8]  = header.getFlag1();
	buffer[9]  = header.getFlag2();
	buffer[10] = header.getFlag3();

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		buffer[11 + i] = header.getRptCall1().GetChar(i);

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		buffer[19 + i] = header.getRptCall2().GetChar(i);

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		buffer[27 + i] = header.getYourCall().GetChar(i);

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		buffer[35 + i] = header.getMyCall1().GetChar(i);

	for (unsigned int i = 0U; i < SHORT_CALLSIGN_LENGTH; i++)
		buffer[43 + i] = header.getMyCall2().GetChar(i);

	// Get the checksum for the header
	CCCITTChecksumReverse csum;
	csum.update(buffer + 8U, 4U * LONG_CALLSIGN_LENGTH + SHORT_CALLSIGN_LENGTH + 3U);
	csum.result(buffer + 47U);

	m_outSeq = 0U;

#if defined(DUMP_TX)
	CUtils::dump(wxT("Sending Header"), buffer, 49U);
	return true;
#else
	for (unsigned int i = 0U; i < 2U; i++) {
		bool ret = m_socket.write(buffer, 49U);
		if (!ret)
			return false;
	}

	return true;
#endif
}
예제 #6
0
bool CMMDVMController::writeHeader(const CHeaderData& header)
{
	bool ret = m_txData.hasSpace(46U);
	if (!ret) {
		wxLogWarning(wxT("No space to write the header"));
		return false;
	}

	unsigned char buffer[50U];

	buffer[0U] = MMDVM_FRAME_START;
	buffer[1U] = RADIO_HEADER_LENGTH_BYTES + 3U;
	buffer[2U] = MMDVM_DSTAR_HEADER;

	::memset(buffer + 3U, ' ', RADIO_HEADER_LENGTH_BYTES);

	buffer[3U] = header.getFlag1();
	buffer[4U] = header.getFlag2();
	buffer[5U] = header.getFlag3();

	wxString rpt2 = header.getRptCall2();
	for (unsigned int i = 0U; i < rpt2.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 6U]  = rpt2.GetChar(i);

	wxString rpt1 = header.getRptCall1();
	for (unsigned int i = 0U; i < rpt1.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 14U] = rpt1.GetChar(i);

	wxString your = header.getYourCall();
	for (unsigned int i = 0U; i < your.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 22U] = your.GetChar(i);

	wxString my1 = header.getMyCall1();
	for (unsigned int i = 0U; i < my1.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 30U] = my1.GetChar(i);

	wxString my2 = header.getMyCall2();
	for (unsigned int i = 0U; i < my2.Len() && i < SHORT_CALLSIGN_LENGTH; i++)
		buffer[i + 38U] = my2.GetChar(i);

	CCCITTChecksumReverse cksum1;
	cksum1.update(buffer + 3U, RADIO_HEADER_LENGTH_BYTES - 2U);
	cksum1.result(buffer + 42U);

	wxMutexLocker locker(m_mutex);

	unsigned char type = DSMTT_HEADER;
	m_txData.addData(&type, 1U);

	unsigned char len = RADIO_HEADER_LENGTH_BYTES + 3U;
	m_txData.addData(&len, 1U);

	m_txData.addData(buffer, RADIO_HEADER_LENGTH_BYTES + 3U);

	return true;
}
void CDummyRepeaterFrame::onHeader(wxEvent& event)
{
	CDummyRepeaterHeaderEvent& hdrEvent = dynamic_cast<CDummyRepeaterHeaderEvent&>(event);

	CHeaderData* header = hdrEvent.getHeaderData();

	if (header != NULL) {
		wxDateTime dateTime = header->getTime();
		wxString hrdDateTime = dateTime.FormatISODate() + wxT(" ") + dateTime.FormatISOTime();
		m_heard->InsertItem(0L, hrdDateTime);

		wxString urCall = header->getYourCall();
		m_hrdYour->SetLabel(urCall);
		m_heard->SetItem(0L, 1, urCall);

		wxString myCall = header->getMyCall1();

		wxString myCall2 = header->getMyCall2();
		if (!myCall2.IsSameAs(wxT("    "))) {
			myCall.Append(wxT("/"));
			myCall.Append(myCall2);
		}

		m_hrdMy->SetLabel(myCall);
		m_heard->SetItem(0L, 2, myCall);

		wxString rpt1Call = header->getRptCall1();
		m_hrdRpt1->SetLabel(rpt1Call);
		m_heard->SetItem(0L, 3, rpt1Call);

		wxString rpt2Call = header->getRptCall2();
		m_hrdRpt2->SetLabel(rpt2Call);
		m_heard->SetItem(0L, 4, rpt2Call);

		wxString flags;
		flags.Printf(wxT("%02X %02X %02X"), header->getFlag1(), header->getFlag2(), header->getFlag3());
		m_hrdFlags->SetLabel(flags);

		m_hrdMessage->SetLabel(wxEmptyString);

		delete header;
	} else {
		m_hrdYour->SetLabel(wxEmptyString);
		m_hrdMy->SetLabel(wxEmptyString);
		m_hrdRpt1->SetLabel(wxEmptyString);
		m_hrdRpt2->SetLabel(wxEmptyString);
		m_hrdFlags->SetLabel(wxEmptyString);
		m_hrdMessage->SetLabel(wxEmptyString);
	}
}
예제 #8
0
void CDVToolReaderFrame::onHeader(wxEvent& event)
{
	CHeaderEvent& hdrEvent = dynamic_cast<CHeaderEvent&>(event);

	CHeaderData* header = hdrEvent.getHeaderData();

	if (header != NULL) {
		wxDateTime dateTime = header->getTime();
		wxString hrdDateTime = dateTime.FormatISODate() + wxT(" ") + dateTime.FormatISOTime();

		wxString urCall = header->getYourCall();
		m_your->SetLabel(urCall);

		wxString myCall = header->getMyCall1();

		wxString myCall2 = header->getMyCall2();
		if (!myCall2.IsSameAs(wxT("    "))) {
			myCall.Append(wxT("/"));
			myCall.Append(myCall2);
		}

		m_my->SetLabel(myCall);

		wxString rpt1Call = header->getRptCall1();
		m_rpt1->SetLabel(rpt1Call);

		wxString rpt2Call = header->getRptCall2();
		m_rpt2->SetLabel(rpt2Call);

		wxString flags;
		flags.Printf(wxT("%02X %02X %02X"), header->getFlag1(), header->getFlag2(), header->getFlag3());
		m_flags->SetLabel(flags);

		m_message->SetLabel(wxEmptyString);

		delete header;
	} else {
		m_fileName->SetLabel(wxEmptyString);

		m_your->SetLabel(wxEmptyString);
		m_my->SetLabel(wxEmptyString);
		m_rpt1->SetLabel(wxEmptyString);
		m_rpt2->SetLabel(wxEmptyString);
		m_flags->SetLabel(wxEmptyString);
		m_message->SetLabel(wxEmptyString);
	}
}
bool CGMSKController::writeHeader(const CHeaderData& header)
{
	unsigned char buffer[50U];

	::memset(buffer, ' ', RADIO_HEADER_LENGTH_BYTES - 2U);

	buffer[0U] = header.getFlag1();
	buffer[1U] = header.getFlag2();
	buffer[2U] = header.getFlag3();

	wxString rpt2 = header.getRptCall2();
	for (unsigned int i = 0U; i < rpt2.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 3U]  = rpt2.GetChar(i);

	wxString rpt1 = header.getRptCall1();
	for (unsigned int i = 0U; i < rpt1.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 11U] = rpt1.GetChar(i);

	wxString your = header.getYourCall();
	for (unsigned int i = 0U; i < your.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 19U] = your.GetChar(i);

	wxString my1 = header.getMyCall1();
	for (unsigned int i = 0U; i < my1.Len() && i < LONG_CALLSIGN_LENGTH; i++)
		buffer[i + 27U] = my1.GetChar(i);

	wxString my2 = header.getMyCall2();
	for (unsigned int i = 0U; i < my2.Len() && i < SHORT_CALLSIGN_LENGTH; i++)
		buffer[i + 35U] = my2.GetChar(i);

	wxMutexLocker locker(m_mutex);

	bool ret = m_txData.hasSpace(RADIO_HEADER_LENGTH_BYTES);
	if (!ret)
		return false;

	unsigned char data[2U];
	data[0U] = DSMTT_HEADER;
	data[1U] = RADIO_HEADER_LENGTH_BYTES - 2U;
	m_txData.addData(data, 2U);

	m_txData.addData(buffer, RADIO_HEADER_LENGTH_BYTES - 2U);

	return true;
}
예제 #10
0
void CXReflectorDPlusHandler::processInt(CHeaderData& header)
{
    wxString   rpt1 = header.getRptCall1();
    wxString   rpt2 = header.getRptCall2();
    unsigned int id = header.getId();

    if (!m_linked)
        return;

    // Convert the callsign(s) from the DPlus call to the repeater call
    wxString rpt = m_dplusCallsign;

    wxChar band = rpt2.GetChar(LONG_CALLSIGN_LENGTH - 1U);
    rpt.SetChar(LONG_CALLSIGN_LENGTH - 1U, band);

    // Check the destination callsign
    m_destination = CXReflectorReflectorHandler::findReflector(rpt);
    if (m_destination == NULL) {
        band = rpt1.GetChar(LONG_CALLSIGN_LENGTH - 1U);
        rpt.SetChar(LONG_CALLSIGN_LENGTH - 1U, band);

        m_destination = CXReflectorReflectorHandler::findReflector(rpt);
        if (m_destination == NULL) {
            wxLogMessage(wxT("Incoming unmatched D-Plus header, RPT1=%s, RPT2=%s"), rpt1.c_str(), rpt2.c_str());
            return;
        }
    }

    if (m_dPlusId != 0x00)
        return;

    m_dPlusId = id;
    m_inactivityTimer.start();
    m_pollInactivityTimer.reset();

    header.setCQCQCQ();
    header.setFlag1(0x00U);
    bool ret = m_destination->process(m_dPlusId, header);

    // Write to Users.log if it's enabled
    if (ret && m_userLogger != NULL)
        m_userLogger->write(header.getMyCall1(), header.getRptCall2(), m_reflector, PROTO_DPLUS);
}
예제 #11
0
void CHeaderLogger::write(const wxChar* type, const CHeaderData& header)
{
	wxASSERT(type != NULL);

	time_t timeNow = ::time(NULL);
	struct tm* tm = ::gmtime(&timeNow);

	char* t = ::inet_ntoa(header.getYourAddress());
	wxString address(t, wxConvLocal);

	wxString text;
	text.Printf(wxT("%04d-%02d-%02d %02d:%02d:%02d: %s header - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X (%s:%u)\n"),
		tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, type,
		header.getMyCall1().c_str(), header.getMyCall2().c_str(), header.getYourCall().c_str(),
		header.getRptCall1().c_str(), header.getRptCall2().c_str(), header.getFlag1(), header.getFlag2(),
		header.getFlag3(), address.c_str(), header.getYourPort());

	m_file.Write(text);
	m_file.Flush();
}
예제 #12
0
void CXReflectorDPlusHandler::writeHeaderInt(CHeaderData& header)
{
    if (!m_linked)
        return;

    // If there's an incoming data stream, don't send
    if (m_dPlusId != 0x00U)
        return;

    wxString rpt2 = m_dplusCallsign;
    wxChar band = header.getRptCall1().GetChar(LONG_CALLSIGN_LENGTH - 1U);
    rpt2.SetChar(LONG_CALLSIGN_LENGTH - 1U, band);

    wxString rpt1 = m_dplusCallsign;
    band = header.getRptCall2().GetChar(LONG_CALLSIGN_LENGTH - 1U);
    rpt1.SetChar(LONG_CALLSIGN_LENGTH - 1U, band);

    header.setRepeaters(rpt1, rpt2);
    header.setDestination(m_address, m_port);
    m_handler->writeHeader(header);
}
예제 #13
0
void CDExtraHandler::processInt(CHeaderData& header)
{
	unsigned int id = header.getId();
	wxString rpt1 = header.getRptCall1();
	wxString rpt2 = header.getRptCall2();

	if (m_linkState != DEXTRA_LINKED)
		return;

	switch (m_direction) {
		case DIR_OUTGOING: {
				// Always a repeater connection
				if (!m_reflector.IsSameAs(rpt2) && !m_reflector.IsSameAs(rpt1))
					return;

				// If we're already processing, ignore the new header
				if (m_dExtraId != 0x00U)
					return;

				// Write to Header.log if it's enabled
				if (m_headerLogger != NULL)
					m_headerLogger->write(wxT("DExtra"), header);

				m_dExtraId  = id;
				m_dExtraSeq = 0x00U;
				m_inactivityTimer.start();

				delete m_header;

				m_header = new CHeaderData(header);
				m_header->setCQCQCQ();
				m_header->setFlags(0x00U, 0x00U, 0x00U);

				m_destination->process(*m_header, AS_DEXTRA);
			}
			break;

		case DIR_INCOMING:
			if (!m_repeater.IsEmpty()) {
				// A repeater connection
				if (!m_repeater.IsSameAs(rpt2) && !m_repeater.IsSameAs(rpt1))
					return;

				// If we're already processing, ignore the new header
				if (m_dExtraId != 0x00U)
					return;

				// Write to Header.log if it's enabled
				if (m_headerLogger != NULL)
					m_headerLogger->write(wxT("DExtra"), header);

				m_dExtraId  = id;
				m_dExtraSeq = 0x00U;
				m_inactivityTimer.start();

				delete m_header;

				m_header = new CHeaderData(header);
				m_header->setCQCQCQ();
				m_header->setFlags(0x00U, 0x00U, 0x00U);

				m_destination->process(*m_header, AS_DEXTRA);
			} else {
				// A Dongle connection
				// Check the destination callsign
				m_destination = CRepeaterHandler::findDVRepeater(rpt2);
				if (m_destination == NULL) {
					m_destination = CRepeaterHandler::findDVRepeater(rpt1);
					if (m_destination == NULL)
						return;
				}

				// If we're already processing, ignore the new header
				if (m_dExtraId != 0x00U)
					return;

				// Write to Header.log if it's enabled
				if (m_headerLogger != NULL)
					m_headerLogger->write(wxT("DExtra"), header);

				m_dExtraId  = id;
				m_dExtraSeq = 0x00U;
				m_inactivityTimer.start();

				delete m_header;

				m_header = new CHeaderData(header);
				m_header->setCQCQCQ();
				m_header->setFlags(0x00U, 0x00U, 0x00U);

				m_destination->process(*m_header, AS_DEXTRA);
			}
			break;
	}
}
void CDummyRepeaterThread::transmit()
{
	m_encodeData.clear();
	m_dongle->setMode(DVDMODE_ENCODE);

	// Pause until all the silence data has been processed by the AMBE2020
	for (unsigned int startCount = 30U; startCount > 0U; startCount--) {
		unsigned char frame[DV_FRAME_LENGTH_BYTES];
		unsigned int n = 0U;
		do {
			n += m_encodeData.getData(frame + n, VOICE_FRAME_LENGTH_BYTES - n);

			if (n < VOICE_FRAME_LENGTH_BYTES)
				Sleep(DSTAR_FRAME_TIME_MS / 4UL);
		} while (n < VOICE_FRAME_LENGTH_BYTES);

		serviceNetwork();
		checkController();
	}

	CHeaderData* header = new CHeaderData(m_callsign1, m_callsign2, m_your, m_rpt2, m_rpt1);

	wxLogMessage(wxT("Transmitting to - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str());

	m_slowDataEncoder.reset();
	m_slowDataEncoder.setHeaderData(*header);

	serviceNetwork();
	checkController();

	if (!m_message.IsEmpty())
		m_slowDataEncoder.setMessageData(m_message);

	m_protocol->writeHeader(*header);
	delete header;

	serviceNetwork();
	checkController();

	m_frameCount = 20U;

	unsigned int endCount = 30U;

	// While transmitting and not exiting
	for (;;) {
		unsigned char frame[DV_FRAME_LENGTH_BYTES];
		unsigned int n = 0U;
		do {
			n += m_encodeData.getData(frame + n, VOICE_FRAME_LENGTH_BYTES - n);

			if (n < VOICE_FRAME_LENGTH_BYTES)
				Sleep(DSTAR_FRAME_TIME_MS / 4UL);
		} while (n < VOICE_FRAME_LENGTH_BYTES);

		serviceNetwork();
		checkController();

		if (m_frameCount == 20U) {
			// Put in the data resync pattern
			::memcpy(frame + VOICE_FRAME_LENGTH_BYTES, DATA_SYNC_BYTES, DATA_FRAME_LENGTH_BYTES);
			m_frameCount = 0U;
		} else {
			// Tack the slow data on the end
			m_slowDataEncoder.getData(frame + VOICE_FRAME_LENGTH_BYTES);
			m_frameCount++;
		}

		if (m_transmit != CLIENT_TRANSMIT)
			endCount--;

		// Send the AMBE and slow data frame
		if (endCount == 0U || m_killed) {
			m_protocol->writeData(frame, DV_FRAME_LENGTH_BYTES, 0U, true);
			break;
		} else {
			m_protocol->writeData(frame, DV_FRAME_LENGTH_BYTES, 0U, false);
		}

		serviceNetwork();
		checkController();
	}

	m_dongle->setMode(DVDMODE_IDLE);

	resetReceiver();

	m_transmit = CLIENT_RECEIVE;

	serviceNetwork();
	checkController();
}
CHeaderData* CSoundCardRepeaterTXRXThread::processSlowData(bool sync)
{
	bool bits[DV_FRAME_LENGTH_BITS];
	m_bitBuffer.getData(bits, DV_FRAME_LENGTH_BITS);

	if (sync) {
		m_slowDataDecoder.sync();
		return NULL;
	}

	unsigned char bytes[DATA_FRAME_LENGTH_BYTES];

	// Convert the bits to bytes
	unsigned int n = 0U;
	for (unsigned int i = 0U; i < DATA_FRAME_LENGTH_BYTES; i++, n += 8U)
		bytes[i] = CUtils::bitsToByteRev(bits + VOICE_FRAME_LENGTH_BITS + n);

	m_slowDataDecoder.addData(bytes);

	CHeaderData* header = m_slowDataDecoder.getHeaderData();
	if (header == NULL)
		return NULL;

	wxLogMessage(wxT("Radio header from slow data - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X  BER: 0%%"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

	m_headerBER = 0U;

	return header;
}
예제 #16
0
void CDPlusHandler::processInt(CHeaderData& header)
{
	wxString   rpt1 = header.getRptCall1();
	wxString   rpt2 = header.getRptCall2();
	unsigned int id = header.getId();

	if (m_linkState != DPLUS_LINKED)
		return;

	switch (m_direction) {
		case DIR_OUTGOING:
			if (m_reflector.IsSameAs(rpt1) || m_reflector.IsSameAs(rpt2)) {
				// If we're already processing, ignore the new header
				if (m_dPlusId != 0x00U)
					return;

				// Write to Header.log if it's enabled
				if (m_headerLogger != NULL)
					m_headerLogger->write(wxT("DPlus"), header);

				m_dPlusId  = id;
				m_dPlusSeq = 0x00U;
				m_inactivityTimer.start();
				m_pollInactivityTimer.reset();

				delete m_header;

				m_header = new CHeaderData(header);
				m_header->setCQCQCQ();
				m_header->setFlags(0x00U, 0x00U, 0x00U);

				m_destination->process(*m_header, AS_DPLUS);
			}
			break;

		case DIR_INCOMING: {
				m_destination = CRepeaterHandler::findDVRepeater(rpt1);
				if (m_destination == NULL) {
					m_destination = CRepeaterHandler::findDVRepeater(rpt2);
					if (m_destination == NULL)
						return;
				}

				if (m_dPlusId != 0x00U)
					return;

				// Write to Header.log if it's enabled
				if (m_headerLogger != NULL)
					m_headerLogger->write(wxT("DPlus"), header);

				m_dPlusId  = id;
				m_dPlusSeq = 0x00U;
				m_inactivityTimer.start();
				m_pollInactivityTimer.reset();

				delete m_header;

				m_header = new CHeaderData(header);
				m_header->setCQCQCQ();
				m_header->setFlags(0x00U, 0x00U, 0x00U);

				m_destination->process(*m_header, AS_DPLUS);
			}
			break;
	}
}
예제 #17
0
void CIRCDDBGatewayThread::processRepeater(IRepeaterProtocolHandler* handler)
{
	for (;;) {
		REPEATER_TYPE type = handler->read();

		switch (type) {
			case RT_POLL: {
					CPollData* poll = handler->readPoll();
					if (poll != NULL) {
						CRepeaterHandler* handler = CRepeaterHandler::findRepeater(*poll);
						if (handler != NULL)
							handler->processRepeater(*poll);
						else
							CRepeaterHandler::pollAllIcom(*poll);

						delete poll;
					}
				}
				break;

			case RT_HEARD: {
					CHeardData* heard = handler->readHeard();
					if (heard != NULL) {
						wxString user = heard->getUser();
						wxString repeater = heard->getRepeater();

						// Internal controller heard have identical user and repeater values
						if (!repeater.IsSameAs(user)) {
							CRepeaterHandler* handler = CRepeaterHandler::findDVRepeater(repeater);
							if (handler == NULL)
								wxLogMessage(wxT("Heard received from unknown repeater, %s"), repeater.c_str());
							else
								handler->processRepeater(*heard);

							delete heard;
						}
					}
				}
				break;

			case RT_HEADER: {
					CHeaderData* header = handler->readHeader();
					if (header != NULL) {
						// wxLogMessage(wxT("Repeater header - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

						CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*header);
						if (repeater == NULL)
							wxLogMessage(wxT("Header received from unknown repeater, %s"), header->getRptCall1().c_str());
						else
							repeater->processRepeater(*header);

						delete header;
					}
				}
				break;

			case RT_AMBE: {
					CAMBEData* data = handler->readAMBE();
					if (data != NULL) {
						CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*data, false);
						if (repeater != NULL)
							repeater->processRepeater(*data);

						delete data;
					}
				}
				break;

			case RT_BUSY_HEADER: {
					CHeaderData* header = handler->readBusyHeader();
					if (header != NULL) {
						// wxLogMessage(wxT("Repeater busy header - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

						CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*header);
						if (repeater == NULL)
							wxLogMessage(wxT("Busy header received from unknown repeater, %s"), header->getRptCall1().c_str());
						else
							repeater->processBusy(*header);

						delete header;
					}
				}
				break;

			case RT_BUSY_AMBE: {
					CAMBEData* data = handler->readBusyAMBE();
					if (data != NULL) {
						CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*data, true);
						if (repeater != NULL)
							repeater->processBusy(*data);

						delete data;
					}
				}
				break;

			case RT_DD: {
					CDDData* data = handler->readDD();
					if (data != NULL) {
						// wxLogMessage(wxT("DD header - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), data->getMyCall1().c_str(), data->getMyCall2().c_str(), data->getYourCall().c_str(), data->getRptCall1().c_str(), data->getRptCall2().c_str(), data->getFlag1(), data->getFlag2(), data->getFlag3());

						CRepeaterHandler* repeater = CRepeaterHandler::findDDRepeater();
						if (repeater == NULL)
							wxLogMessage(wxT("DD data received from unknown DD repeater, %s"), data->getRptCall1().c_str());
						else
							repeater->processRepeater(*data);

						delete data;
					}
				}
				break;

			default:
				return;
		}
	}
}
예제 #18
0
void CDStarRepeaterRXThread::receiveSlowData(unsigned char* data, unsigned int)
{
    unsigned int errs;
    errs  = countBits(data[VOICE_FRAME_LENGTH_BYTES + 0U] ^ DATA_SYNC_BYTES[0U]);
    errs += countBits(data[VOICE_FRAME_LENGTH_BYTES + 1U] ^ DATA_SYNC_BYTES[1U]);
    errs += countBits(data[VOICE_FRAME_LENGTH_BYTES + 2U] ^ DATA_SYNC_BYTES[2U]);

    // The data sync has been seen, a fuzzy match is used, two bit errors or less
    if (errs <= MAX_DATA_SYNC_BIT_ERRS) {
        // wxLogMessage(wxT("Found data sync at frame %u, errs: %u"), m_radioSeqNo, errs);
        m_radioSeqNo     = 0U;
        m_slowDataDecoder.sync();
    } else if (m_radioSeqNo == 20U) {
        // wxLogMessage(wxT("Assuming data sync"));
        m_radioSeqNo = 0U;
        m_slowDataDecoder.sync();
    } else {
        m_radioSeqNo++;
        m_slowDataDecoder.addData(data + VOICE_FRAME_LENGTH_BYTES);

        CHeaderData* header = m_slowDataDecoder.getHeaderData();
        if (header == NULL)
            return;

        wxLogMessage(wxT("Radio header from slow data - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X  BER: 0%%"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

        if (header != NULL) {
            bool res = processRadioHeader(header);
            if (res) {
                // A valid header and is a DV packet, go to normal data relaying
                setRadioState(DSRXS_PROCESS_DATA);
            } else {
                // This is a DD packet or some other problem
                // wxLogMessage(wxT("Invalid header"));
            }
        }
    }
}
bool CGMSKModemLibUsb::writeHeader(const CHeaderData& header)
{
	char myCall1[LONG_CALLSIGN_LENGTH];
	char myCall2[SHORT_CALLSIGN_LENGTH];
	char yourCall[LONG_CALLSIGN_LENGTH];
	char rptCall1[LONG_CALLSIGN_LENGTH];
	char rptCall2[LONG_CALLSIGN_LENGTH];

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		myCall1[i] = header.getMyCall1().GetChar(i);
	for (unsigned int i = 0U; i < SHORT_CALLSIGN_LENGTH; i++)
		myCall2[i] = header.getMyCall2().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		yourCall[i] = header.getYourCall().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		rptCall1[i] = header.getRptCall1().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		rptCall2[i] = header.getRptCall2().GetChar(i);

	int ret = io(0x40, SET_MyCALL2, 0, 0, myCall2, SHORT_CALLSIGN_LENGTH, USB_TIMEOUT);
	if (ret < 0) {
		wxString errorText(m_usbStrerror(), wxConvLocal);
		wxLogMessage(wxT("SET_MyCALL2, ret: %d, err=%s"), ret, errorText.c_str());
		return false;
	}

	ret = io(0x40, SET_MyCALL, 0, 0, myCall1, LONG_CALLSIGN_LENGTH, USB_TIMEOUT);
	if (ret < 0) {
		wxString errorText(m_usbStrerror(), wxConvLocal);
		wxLogMessage(wxT("SET_MyCALL, ret: %d, err=%s"), ret, errorText.c_str());
		return false;
	}

	ret = io(0x40, SET_YourCALL, 0, 0, yourCall, LONG_CALLSIGN_LENGTH, USB_TIMEOUT);
	if (ret < 0) {
		wxString errorText(m_usbStrerror(), wxConvLocal);
		wxLogMessage(wxT("SET_YourCALL, ret: %d, err=%s"), ret, errorText.c_str());
		return false;
	}

	ret = io(0x40, SET_RPT1CALL, 0, 0, rptCall1, LONG_CALLSIGN_LENGTH, USB_TIMEOUT);
	if (ret < 0) {
		wxString errorText(m_usbStrerror(), wxConvLocal);
		wxLogMessage(wxT("SET_RPT1CALL, ret: %d, err=%s"), ret, errorText.c_str());
		return false;
	}

	ret = io(0x40, SET_RPT2CALL, 0, 0, rptCall2, LONG_CALLSIGN_LENGTH, USB_TIMEOUT);
	if (ret < 0) {
		wxString errorText(m_usbStrerror(), wxConvLocal);
		wxLogMessage(wxT("SET_RPT2CALL, ret: %d, err=%s"), ret, errorText.c_str());
		return false;
	}

	char flags[3U];
	flags[0U] = header.getFlag1();
	flags[1U] = header.getFlag2();
	flags[2U] = header.getFlag3();

	ret = io(0x40, SET_FLAGS, 0, 0, flags, 3, USB_TIMEOUT);
	if (ret < 0) {
		wxString errorText(m_usbStrerror(), wxConvLocal);
		wxLogMessage(wxT("SET_FLAGS, ret: %d, err=%s"), ret, errorText.c_str());
		return false;
	}

	return true;
}
void CSoundCardRepeaterTXThread::transmitNetworkHeader(CHeaderData& header)
{
	wxLogMessage(wxT("Transmitting to - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header.getMyCall1().c_str(), header.getMyCall2().c_str(), header.getYourCall().c_str(), header.getRptCall1().c_str(), header.getRptCall2().c_str(), header.getFlag1(), header.getFlag2(), header.getFlag3());

	// Send the bit sync, 700 bits in 4 bit chunks
	for (unsigned int i = 0U; i < 175U; i++)
		m_networkBuffer.addData(BIT_SYNC_BITS, BIT_SYNC_LENGTH_BITS);

	// Send the frame sync
	m_networkBuffer.addData(FRAME_SYNC_BITS, FRAME_SYNC_LENGTH_BITS);

	// Send the header
	bool headerBits[FEC_SECTION_LENGTH_BITS];
	CRadioHeaderEncoder encoder(header);
	encoder.getRadioData(headerBits, FEC_SECTION_LENGTH_BITS);
	m_networkBuffer.addData(headerBits, FEC_SECTION_LENGTH_BITS);

	m_networkStarted = false;
	m_networkRun = 0U;
}
void CDVAPNodeTRXThread::receiveRadioHeader()
{
	CHeaderData* header = m_dvap->readHeader();
	if (header == NULL)
		return;

	wxLogMessage(wxT("Header decoded - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

	bool res = processRadioHeader(header);
	if (res) {
		// A valid header and is a DV packet
		m_radioSeqNo     = 20U;
		m_ambeFrames     = 0U;
		m_ambeSilence    = 0U;
		m_ambeBits       = 1U;
		m_ambeErrors     = 0U;
		m_lastAMBEBits   = 0U;
		m_lastAMBEErrors = 0U;
	} else {
		// This is a DD packet or some other problem
		// wxLogMessage(wxT("Invalid header"));
	}
}
bool CGMSKModemLibUsb::writeHeader(const CHeaderData& header)
{
	wxASSERT(m_handle != NULL);

	unsigned char myCall1[LONG_CALLSIGN_LENGTH];
	unsigned char myCall2[SHORT_CALLSIGN_LENGTH];
	unsigned char yourCall[LONG_CALLSIGN_LENGTH];
	unsigned char rptCall1[LONG_CALLSIGN_LENGTH];
	unsigned char rptCall2[LONG_CALLSIGN_LENGTH];

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		myCall1[i] = header.getMyCall1().GetChar(i);
	for (unsigned int i = 0U; i < SHORT_CALLSIGN_LENGTH; i++)
		myCall2[i] = header.getMyCall2().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		yourCall[i] = header.getYourCall().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		rptCall1[i] = header.getRptCall1().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		rptCall2[i] = header.getRptCall2().GetChar(i);

	int ret = ::libusb_control_transfer(m_handle, 0x40, SET_MyCALL2, 0, 0, myCall2, SHORT_CALLSIGN_LENGTH, USB_TIMEOUT);
	if (ret < 0) {
		wxLogMessage(wxT("SET_MyCALL2, err=%d"), ret);
		return false;
	}

	ret = ::libusb_control_transfer(m_handle, 0x40, SET_MyCALL, 0, 0, myCall1, LONG_CALLSIGN_LENGTH,  USB_TIMEOUT);
	if (ret < 0) {
		wxLogMessage(wxT("SET_MyCALL, err=%d"), ret);
		return false;
	}

	ret = ::libusb_control_transfer(m_handle, 0x40, SET_YourCALL, 0, 0, yourCall, LONG_CALLSIGN_LENGTH,  USB_TIMEOUT);
	if (ret < 0) {
		wxLogMessage(wxT("SET_YourCALL, err=%d"), ret);
		return false;
	}

	ret = ::libusb_control_transfer(m_handle, 0x40, SET_RPT1CALL, 0, 0, rptCall1, LONG_CALLSIGN_LENGTH,  USB_TIMEOUT);
	if (ret < 0) {
		wxLogMessage(wxT("SET_RPT1CALL, err=%d"), ret);
		return false;
	}

	ret = ::libusb_control_transfer(m_handle, 0x40, SET_RPT2CALL, 0, 0, rptCall2, LONG_CALLSIGN_LENGTH,  USB_TIMEOUT);
	if (ret < 0) {
		wxLogMessage(wxT("SET_RPT2CALL, err=%d"), ret);
		return false;
	}

	unsigned char flags[3U];
	flags[0U] = header.getFlag1();
	flags[1U] = header.getFlag2();
	flags[2U] = header.getFlag3();

	ret = ::libusb_control_transfer(m_handle, 0x40, SET_FLAGS, 0, 0, flags, 3, USB_TIMEOUT);
	if (ret < 0) {
		wxLogMessage(wxT("SET_FLAGS, err=%d"), ret);
		return false;
	}

	return true;
}
CHeaderData* CSoundCardRepeaterTXRXThread::processFECHeader()
{
	bool buffer[FEC_SECTION_LENGTH_BITS];
	m_bitBuffer.getData(buffer, FEC_SECTION_LENGTH_BITS);

	CRadioHeaderDecoder decoder(buffer, FEC_SECTION_LENGTH_BITS);

	CHeaderData* header = decoder.getHeaderData();
	if (header == NULL)
		return NULL;

	m_headerBER = decoder.getBER();

	wxLogMessage(wxT("Radio header decoded - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X  BER: %u%%"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3(), m_headerBER);

	return header;
}
void CDVRPTRRepeaterRXThread::receiveHeader(unsigned char* data, unsigned int length)
{
	CHeaderData* header = new CHeaderData(data, length, false);

	wxLogMessage(wxT("Radio header decoded - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

	bool res = processRadioHeader(header);
	if (res) {
		// A valid header and is a DV packet
		m_radioSeqNo = 20U;
		setRadioState(DSRXS_PROCESS_DATA);
	} else {
		// This is a DD packet or some other problem
		// wxLogMessage(wxT("Invalid header"));
	}
}
void CGMSKRepeaterTXRXThread::transmitNetworkHeader(const CHeaderData& header)
{
	wxLogMessage(wxT("Transmitting to - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header.getMyCall1().c_str(), header.getMyCall2().c_str(), header.getYourCall().c_str(), header.getRptCall1().c_str(), header.getRptCall2().c_str(), header.getFlag1(), header.getFlag2(), header.getFlag3());

	bool empty = m_networkQueue[m_readNum]->isEmpty();
	if (!empty) {
		bool headerReady = m_networkQueue[m_readNum]->headerReady();
		if (headerReady) {
			// Transmission has never started, so just purge the queue
			m_networkQueue[m_readNum]->reset();

			m_readNum++;
			if (m_readNum >= NETWORK_QUEUE_COUNT)
				m_readNum = 0U;
		} else {
			// Purge the currently transmitting buffer and append an end of stream
			m_networkQueue[m_readNum]->reset();
			m_networkQueue[m_readNum]->addData(END_PATTERN_BYTES, DV_FRAME_LENGTH_BYTES, true);
		}
	}

	m_networkQueue[m_writeNum]->reset();
	m_networkQueue[m_writeNum]->setHeader(new CHeaderData(header));
}
예제 #26
0
CRadioHeaderEncoder::CRadioHeaderEncoder(const CHeaderData& header) :
m_header(NULL)
{
	m_header = new bool[FEC_SECTION_LENGTH_BITS];

	bool* buffer1 = new bool[700U];
	bool* buffer2 = new bool[700U];

	// Clear everything
	::memset(buffer1, 0x00, 700U * sizeof(bool));

	// Flag 1
	unsigned char flag1 = header.getFlag1();
	buffer1[0]  = (flag1 & 0x80U) == 0x80U; buffer1[1]  = (flag1 & 0x40U) == 0x40U;
	buffer1[2]  = (flag1 & 0x20U) == 0x20U; buffer1[3]  = (flag1 & 0x10U) == 0x10U;
	buffer1[4]  = (flag1 & 0x08U) == 0x08U; buffer1[5]  = (flag1 & 0x04U) == 0x04U;
	buffer1[6]  = (flag1 & 0x02U) == 0x02U; buffer1[7]  = (flag1 & 0x01U) == 0x01U;

	// Flag 2
	unsigned char flag2 = header.getFlag2();
	buffer1[8]  = (flag2 & 0x80U) == 0x80U; buffer1[9]  = (flag2 & 0x40U) == 0x40U;
	buffer1[10] = (flag2 & 0x20U) == 0x20U; buffer1[11] = (flag2 & 0x10U) == 0x10U;
	buffer1[12] = (flag2 & 0x08U) == 0x08U; buffer1[13] = (flag2 & 0x04U) == 0x04U;
	buffer1[14] = (flag2 & 0x02U) == 0x02U; buffer1[15] = (flag2 & 0x01U) == 0x01U;

	// Flag 3
	unsigned char flag3 = header.getFlag3();
	buffer1[16] = (flag3 & 0x80U) == 0x80U; buffer1[17] = (flag3 & 0x40U) == 0x40U;
	buffer1[18] = (flag3 & 0x20U) == 0x20U; buffer1[19] = (flag3 & 0x10U) == 0x10U;
	buffer1[20] = (flag3 & 0x08U) == 0x08U; buffer1[21] = (flag3 & 0x04U) == 0x04U;
	buffer1[22] = (flag3 & 0x02U) == 0x02U; buffer1[23] = (flag3 & 0x01U) == 0x01U;

	unsigned int n = 24U;

	stringToBits(header.getRptCall2(), buffer1 + n, LONG_CALLSIGN_LENGTH);
	n += LONG_CALLSIGN_LENGTH * 8U;

	stringToBits(header.getRptCall1(), buffer1 + n, LONG_CALLSIGN_LENGTH);
	n += LONG_CALLSIGN_LENGTH * 8U;

	stringToBits(header.getYourCall(), buffer1 + n, LONG_CALLSIGN_LENGTH);
	n += LONG_CALLSIGN_LENGTH * 8U;

	stringToBits(header.getMyCall1(),  buffer1 + n, LONG_CALLSIGN_LENGTH);
	n += LONG_CALLSIGN_LENGTH * 8U;

	stringToBits(header.getMyCall2(),  buffer1 + n, SHORT_CALLSIGN_LENGTH);
	n += SHORT_CALLSIGN_LENGTH * 8U;

	CCCITTChecksumReverse cksum;
	for (unsigned int i = 0U; i < n; i += 8U)
		cksum.update(buffer1 + i);
	cksum.result(buffer1 + n);

	// CUtils::dump(wxT("TX Raw Data"), buffer1, n + 16U);

	unsigned int length;
	CDStarFECEncoder fec;
	fec.encode(buffer1, buffer2, RADIO_HEADER_LENGTH_BITS, length);

	// CUtils::dump(wxT("TX After FEC"), buffer2, FEC_SECTION_LENGTH_BITS);

	CDStarInterleaver interleaver;
	interleaver.interleave(buffer2, m_header, FEC_SECTION_LENGTH_BITS);

	// CUtils::dump(wxT("TX After Interleaver"), m_header, FEC_SECTION_LENGTH_BITS);

	CDStarScrambler scrambler;
	scrambler.process(m_header, FEC_SECTION_LENGTH_BITS);

	// CUtils::dump(wxT("TX After Scrambler"), m_header, FEC_SECTION_LENGTH_BITS);

	delete[] buffer1;
	delete[] buffer2;
}
bool CGMSKModemWinUSB::writeHeader(const CHeaderData& header)
{
	unsigned char myCall1[LONG_CALLSIGN_LENGTH];
	unsigned char myCall2[SHORT_CALLSIGN_LENGTH];
	unsigned char yourCall[LONG_CALLSIGN_LENGTH];
	unsigned char rptCall1[LONG_CALLSIGN_LENGTH];
	unsigned char rptCall2[LONG_CALLSIGN_LENGTH];

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		myCall1[i] = header.getMyCall1().GetChar(i);
	for (unsigned int i = 0U; i < SHORT_CALLSIGN_LENGTH; i++)
		myCall2[i] = header.getMyCall2().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		yourCall[i] = header.getYourCall().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		rptCall1[i] = header.getRptCall1().GetChar(i);
	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		rptCall2[i] = header.getRptCall2().GetChar(i);

	int ret = io(SET_MyCALL2, 0x40U, 0U, myCall2, SHORT_CALLSIGN_LENGTH);
	if (ret < 0) {
		wxLogError(wxT("SET_MyCALL2 returned %d"), -ret);
		return false;
	}

	ret = io(SET_MyCALL, 0x40U, 0U, myCall1, LONG_CALLSIGN_LENGTH);
	if (ret < 0) {
		wxLogError(wxT("SET_MyCALL returned %d"), -ret);
		return false;
	}

	ret = io(SET_YourCALL, 0x40U, 0U, yourCall, LONG_CALLSIGN_LENGTH);
	if (ret < 0) {
		wxLogError(wxT("SET_YourCALL returned %d"), -ret);
		return false;
	}

	ret = io(SET_RPT1CALL, 0x40U, 0U, rptCall1, LONG_CALLSIGN_LENGTH);
	if (ret < 0) {
		wxLogError(wxT("SET_RPT1CALL returned %d"), -ret);
		return false;
	}

	ret = io(SET_RPT2CALL, 0x40U, 0U, rptCall2, LONG_CALLSIGN_LENGTH);
	if (ret < 0) {
		wxLogError(wxT("SET_RPT2CALL returned %d"), -ret);
		return false;
	}

	unsigned char flags[3U];
	flags[0U] = header.getFlag1();
	flags[1U] = header.getFlag2();
	flags[2U] = header.getFlag3();

	ret = io(SET_FLAGS, 0x40U, 0U, flags, 3U);
	if (ret < 0) {
		wxLogError(wxT("SET_FLAGS returned %d"), -ret);
		return false;
	}

	return setPTT(true);
}
예제 #28
0
void CDVToolReaderThread::processHeader(const unsigned char* buffer)
{
	// Tell the GUI about the header, we assume that it's valid
	CHeaderData* header = new CHeaderData(buffer, RADIO_HEADER_LENGTH_BYTES, false);

	wxLogMessage(wxT("Header decoded - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

	::wxGetApp().showHeader(header);
}
예제 #29
0
bool CDExtraProtocolHandler::writeHeader(const CHeaderData& header)
{
	wxASSERT(m_socket != NULL);

	// Create a random id for this transmission
	m_outId = (::rand() % 65535U) + 1U;

	unsigned char buffer[56U];

	buffer[0]  = 'D';
	buffer[1]  = 'S';
	buffer[2]  = 'V';
	buffer[3]  = 'T';

	buffer[4]  = 0x10;
	buffer[5]  = 0x00;
	buffer[6]  = 0x00;
	buffer[7]  = 0x00;
	buffer[8]  = 0x20;
	buffer[9]  = 0x00;
	buffer[10] = 0x01;

	buffer[11] = 0x00;				// Band

	buffer[12] = m_outId % 256U;	// Unique session id
	buffer[13] = m_outId / 256U;

	buffer[14] = 0x80;

	buffer[15] = 0x00;				// Flags 1, 2 and 3
	buffer[16] = 0x00;
	buffer[17] = 0x00;

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		buffer[18 + i] = header.getRptCall1().GetChar(i);

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		buffer[26 + i] = header.getRptCall2().GetChar(i);

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		buffer[34 + i] = header.getYourCall().GetChar(i);

	for (unsigned int i = 0U; i < LONG_CALLSIGN_LENGTH; i++)
		buffer[42 + i] = header.getMyCall1().GetChar(i);

	for (unsigned int i = 0U; i < SHORT_CALLSIGN_LENGTH; i++)
		buffer[50 + i] = header.getMyCall2().GetChar(i);

	// A dummy checksum
	buffer[54] = 0xFF;
	buffer[55] = 0xFF;

	m_outSeq = 0U;

#if defined(DUMP_TX)
	CUtils::dump(wxT("Sending Header"), buffer, 56U);
	return true;
#else
	for (unsigned int i = 0U; i < 5U; i++) {
		bool res = m_socket->write(buffer, 56U);
		if (!res)
			return false;
	}

	return true;
#endif
}