void CDVToolReaderApp::createThread()
{
	m_thread = new CDVToolReaderThread;
	m_thread->Create();
	m_thread->Run();

	wxString device;
	getDVDongle( device);

	if (!device.IsEmpty()) {
		CDVDongleController* dongle = new CDVDongleController(new CSerialDataController(device, SERIAL_230400));

		bool res = dongle->open();
		if (!res)
			error(_("Can't find the DV-Dongle on the port specified"));
		else
			m_thread->setDVDongle(dongle);
	}

	getSoundcard(device);

	if (!device.IsEmpty()) {
#if defined(__WINDOWS__)
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(wxEmptyString, device, DSTAR_RADIO_SAMPLE_RATE, DSTAR_RADIO_BLOCK_SIZE);
#else
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(wxEmptyString, device, DSTAR_RADIO_SAMPLE_RATE, 64U);
#endif
		soundcard->setCallback(m_thread, 0);

		bool res = soundcard->open();
		if (!res)
			error(_("Cannot open the sound card"));
		else
			m_thread->setSoundCard(soundcard);
	}

	bool bleep;
	getBleep(bleep);
	m_thread->setBleep(bleep);
}
void CDVRPTRClientApp::createThread()
{
	m_thread = new CDVRPTRClientThread;
	m_thread->Create();
	m_thread->Run();

	wxString callsign1, callsign2;
	getCallsign(callsign1, callsign2);
	m_thread->setCallsign(callsign1, callsign2);

	wxString call;
	wxSortedArrayString list;

	getYourCalls(call, list);
	m_thread->setYour(call);

	getRpt1Calls(call, list);
	m_thread->setRpt1(call);

	getRpt2Calls(call, list);
	m_thread->setRpt2(call);

	wxString message;
	getMessage(message);
	m_thread->setMessage(message);

	wxString device;
	getDVDongle(device);

	if (!device.IsEmpty()) {
		CDVDongleController* dongle = new CDVDongleController(new CSerialDataController(device, SERIAL_230400));

		bool res = dongle->open();
		if (!res) {
			wxLogError(wxT("Can't find the DV-Dongle on the port specified"));
			error(_("Can't find the DV-Dongle on the port specified"));
		} else {
			m_thread->setDVDongle(dongle);
		}
	}

	wxString readDevice, writeDevice;
	getSoundcard(readDevice, writeDevice);

	if (!readDevice.IsEmpty() && !writeDevice.IsEmpty()) {
#if defined(__WINDOWS__)
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, DSTAR_RADIO_SAMPLE_RATE, DSTAR_RADIO_BLOCK_SIZE);
#else
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, DSTAR_RADIO_SAMPLE_RATE, 64U);
#endif
		soundcard->setCallback(m_thread, 0);

		bool res = soundcard->open();
		if (!res) {
			wxLogError(wxT("Cannot open the sound card"));
			error(_("Cannot open the sound card"));
		} else {
			m_thread->setSoundCard(soundcard);
		}
	}

	wxString modemPort;
	DVRPTR_VERSION version;
	bool rxInvert, txInvert, channel;
	unsigned int modLevel, txDelay;
	getModem(version, modemPort, rxInvert, txInvert, channel, modLevel, txDelay);

	if (!modemPort.IsEmpty()) {
		IDVRPTRController* controller = NULL;
		switch (version) {
			case DVRPTR_V1:
				controller = new CDVRPTRControllerV1(modemPort, rxInvert, txInvert, channel, modLevel, txDelay);
				break;
			case DVRPTR_V2:
				controller = new CDVRPTRControllerV2(modemPort, txInvert, modLevel);
				break;
			default:
				wxLogError(wxT("Unknown DV-RPTR modem version - %d"), int(version));
				break;
		}

		if (controller != NULL) {
			bool res = controller->open();
			if (!res) {
				wxLogError(wxT("Cannot open the DV-RPTR modem"));
				error(_("Cannot open the DV-RPTR modem"));
			} else {
				m_thread->setModem(controller);
			}
		}
	}

	bool bleep;
	getBleep(bleep);
	m_thread->setBleep(bleep);
}
void CDummyRepeaterApp::createThread()
{
	m_thread = new CDummyRepeaterThread;
	m_thread->Create();
	m_thread->Run();

	wxString callsign1, callsign2;
	getCallsign(callsign1, callsign2);
	m_thread->setCallsign(callsign1, callsign2);

	wxString call;
	wxSortedArrayString list;

	getYourCalls(call, list);
	m_thread->setYour(call);

	getRpt1Calls(call, list);
	m_thread->setRpt1(call);

	getRpt2Calls(call, list);
	m_thread->setRpt2(call);

	wxString message;
	getMessage(message);
	m_thread->setMessage(message);

	wxString device;
	getDVDongle(device);

	if (!device.IsEmpty()) {
		CDVDongleController* dongle = new CDVDongleController(new CSerialDataController(device, SERIAL_230400));

		bool res = dongle->open();
		if (!res) {
			wxLogError(wxT("Can't find the DV-Dongle on the port specified"));
			error(_("Can't find the DV-Dongle on the port specified"));
		} else {
			m_thread->setDVDongle(dongle);
		}
	}

	wxString readDevice, writeDevice;
	getSoundcard(readDevice, writeDevice);

	if (!readDevice.IsEmpty() && !writeDevice.IsEmpty()) {
#if defined(__WINDOWS__)
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, DSTAR_RADIO_SAMPLE_RATE, DSTAR_RADIO_BLOCK_SIZE);
#else
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, DSTAR_RADIO_SAMPLE_RATE, 64U);
#endif
		soundcard->setCallback(m_thread, 0);

		bool res = soundcard->open();
		if (!res) {
			wxLogError(wxT("Cannot open the sound card"));
			error(_("Cannot open the sound card"));
		} else {
			m_thread->setSoundCard(soundcard);
		}
	}

	wxString gwyAddress, localAddress;
	unsigned int gwyPort, localPort;
	getNetwork(gwyAddress, gwyPort, localAddress, localPort);

	if (!gwyAddress.IsEmpty()) {
		CRepeaterProtocolHandler* protocol = new CRepeaterProtocolHandler(gwyAddress, gwyPort, localAddress, localPort);

		bool res = protocol->open();
		if (!res) {
			wxLogError(wxT("Cannot open the protocol handler"));
			error(_("Cannot open the protocol handler"));
		} else {
			m_thread->setProtocol(protocol);
		}
	}

	wxString type;
	unsigned int config;
	bool pttInvert, squelchInvert;
	getController(type, config, pttInvert, squelchInvert);

	CExternalController* controller = NULL;

	wxString port;
	if (type.StartsWith(wxT("Velleman K8055 - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CExternalController(new CK8055Controller(num), pttInvert, squelchInvert);
	} else if (type.StartsWith(wxT("URI USB - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CExternalController(new CURIUSBController(num, true), pttInvert, squelchInvert);
	} else if (type.StartsWith(wxT("Serial - "), &port)) {
		controller = new CExternalController(new CSerialController(port, config), pttInvert, squelchInvert);
	} else {
		controller = new CExternalController(new CDummyController, pttInvert, squelchInvert);
	}

	bool res = controller->open();
	if (!res) {
		wxLogError(wxT("Cannot open the hardware interface - %s"), type.c_str());
		error(_("Cannot open the hardware interface"));
	} else {
		m_thread->setController(controller);
	}

	bool bleep;
	getBleep(bleep);
	m_thread->setBleep(bleep);
}
void CDCSClientApp::createThread()
{
	m_thread = new CDCSClientThread;
	m_thread->Create();
	m_thread->Run();

	wxString callsign;
	getCallsign(callsign);
	m_thread->setCallsign(callsign);

	wxString message;
	getMessage(message);
	m_thread->setMessage(message);

	wxString device;
	getDVDongle(device);

	if (!device.IsEmpty()) {
		CDVDongleController* dongle = new CDVDongleController(new CSerialDataController(device, SERIAL_230400));

		bool res = dongle->open();
		if (!res) {
			wxLogError(wxT("Can't find the DV-Dongle on the port specified"));
			error(_("Can't find the DV-Dongle on the port specified"));
		} else {
			m_thread->setDVDongle(dongle);
		}
	}

	wxString readDevice, writeDevice;
	getSoundcard(readDevice, writeDevice);

	if (!readDevice.IsEmpty() && !writeDevice.IsEmpty()) {
#if defined(__WINDOWS__)
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, DSTAR_RADIO_SAMPLE_RATE, DSTAR_RADIO_BLOCK_SIZE);
#else
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, DSTAR_RADIO_SAMPLE_RATE, 64U);
#endif
		soundcard->setCallback(m_thread, 0);

		bool res = soundcard->open();
		if (!res) {
			wxLogError(wxT("Cannot open the sound card"));
			error(_("Cannot open the sound card"));
		} else {
			m_thread->setSoundCard(soundcard);
		}
	}

	bool bleep;
	getBleep(bleep);
	m_thread->setBleep(bleep);

	wxString type;
	unsigned int audioDelay;
	bool squelchInvert, pttInvert;
	getController(type, audioDelay, squelchInvert, pttInvert);

	IExternalController* controller = NULL;

	wxString port;
	if (type.StartsWith(wxT("Velleman K8055 - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CK8055Controller(num);
	} else if (type.StartsWith(wxT("URI USB - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CURIUSBController(num);
	} else if (type.StartsWith(wxT("Serial - "), &port)) {
		controller = new CSerialController(port);
	} else {
		controller = new CDummyController;
	}

	bool res = controller->open();
	if (!res)
		wxLogError(wxT("Cannot open the hardware interface - %s"), type.c_str());
	else
		m_thread->setController(controller, audioDelay, pttInvert, squelchInvert);
}