示例#1
0
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);

	DONGLE_TYPE dongleType;
	wxString dongleDevice, dongleAddress;
	unsigned int donglePort;
	getDongle(dongleType, dongleDevice, dongleAddress, donglePort);

	CDongleThread* dongle = NULL;

	switch (dongleType) {
		case DT_DVDONGLE:
			if (!dongleDevice.IsEmpty())
				dongle = new CDVDongleThread(new CDVDongleController(dongleDevice));
			break;
		case DT_DV3000:
			if (!dongleAddress.IsEmpty() && donglePort > 0U)
				dongle = new CAMBE3000Thread(new CDV3000Controller(dongleAddress, donglePort));
			break;
		default:
			wxLogError(wxT("Invalid Dongle type specified - %d"), int(dongleType));
			error(_("Invalid Dongle type specified"));
			break;
	}

	if (dongle != NULL) {
		dongle->setEncodeCallback(m_thread);
		dongle->setDecodeCallback(m_thread);

		bool res = dongle->open();
		if (!res) {
			wxLogError(wxT("Can't find the AMBE Dongle on the port specified"));
			error(_("Can't find the AMBE Dongle on the port specified"));
		} else {
			m_thread->setDongle(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 CSerialLineController(port, config), pttInvert, squelchInvert);
	} else if (type.StartsWith(wxT("Arduino - "), &port)) {
		controller = new CExternalController(new CArduinoController(port), pttInvert, squelchInvert);
#if defined(RASPBERRY_PI)
	} else if (type.IsSameAs(wxT("Raspberry Pi"))) {
		controller = new CExternalController(new CRaspberryController, pttInvert, squelchInvert);
#endif
	} 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);
}
示例#2
0
int main(int argc, char **argv) {
  libusb_context *ctx = NULL;
  dongleHandle dongle;
  int option;
  int address;
  int bus;
  ETERM *tuplep;
  ETERM *functionp;
  unsigned char buf[1024];
  const char* func_name;

  address = -1;
  bus = -1;

  while ((option = getopt(argc, argv, "p:b:")) != -1) {
    switch (option) {
      case 'p':
        address = atoi(optarg);
        break;
      case 'b':
        bus = atoi(optarg);
        break;
      default:
        return 1;
    }
  }

  if (bus == -1 || address == -1) {
    return 1;
  }

  erl_init(NULL, 0);

  initDongle(ctx);
  dongle = getDongle(ctx, address, bus);
  if (dongle == NULL) {
    ERL_WRITE_ERROR("not_found");
    exitDongle(ctx);
    return 1;
  }

  while (read_cmd(buf) > 0) {
    tuplep = erl_decode(buf);
    functionp = erl_element(1, tuplep);

    func_name = (const char*)ERL_ATOM_PTR(functionp);
    if (strncmp(func_name, "derive", 6) == 0){
      hsm_derive(dongle, tuplep);
    } else if (strncmp(func_name, "import", 6) == 0){
      hsm_import(dongle, tuplep);
    } else if (strncmp(func_name, "pin", 3) == 0){
      hsm_pin(dongle, tuplep);
    } else if (strncmp(func_name, "pubkey", 6) == 0){
      hsm_pubkey(dongle, tuplep);
    } else if (strncmp(func_name, "random", 6) == 0){
      hsm_random(dongle, tuplep);
    } else if (strncmp(func_name, "sign", 4) == 0){
      hsm_sign(dongle, tuplep);
    } else if (strncmp(func_name, "verify", 6) == 0){
      hsm_verify(dongle, tuplep);
    } else if (strncmp(func_name, "close", 5) == 0){
      break;
    } else {
      ERL_WRITE_ERROR("undef")
    }
    erl_free_compound(tuplep);
    erl_free_term(functionp);
  }

  closeDongle(dongle);
  exitDongle(ctx);

  ETERM *atom;
  atom = erl_mk_atom("closed");
  unsigned char closed_buf[erl_term_len(atom)];
  erl_encode(atom, closed_buf);
  write_cmd(closed_buf, erl_term_len(atom));
  erl_free_term(atom);
  fprintf(stderr, "CLOSED");

  return 0;
}