示例#1
0
void InitOptions() {
	hEventOptInit = HookEvent(ME_OPT_INITIALISE, OptInit);
	DBVARIANT dbv;
	if(!DBGetContactSettingTString(0, MODULE, "Host", &dbv)) { 
		options.host = strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}
	if(!DBGetContactSettingTString(0, MODULE, "Username", &dbv)) {
		options.username = strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}
	if(!DBGetContactSettingTString(0, MODULE, "Password", &dbv)) {
		options.password = strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}
	if(!DBGetContactSettingTString(0, MODULE, "CIDName", &dbv)) {
		options.cid_name = strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}
	if(!DBGetContactSettingTString(0, MODULE, "CIDNumber", &dbv)) {
		options.cid_number = strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}

	iaxc_audio_device *dev;
	int nDevs, in, out, ring;
	iaxc_audio_devices_get(&dev, &nDevs, &in, &out, &ring);
	if(!DBGetContactSettingTString(0, MODULE, "DeviceIn", &dbv)) {
		for(int i = 0; i < nDevs; i++) {
			if((dev[i].capabilities & IAXC_AD_INPUT) && strcmp(dbv.pszVal, dev[i].name) == 0) in = i;
		}
		DBFreeVariant(&dbv);
	}
	if(!DBGetContactSettingTString(0, MODULE, "DeviceOut", &dbv)) {
		for(int i = 0; i < nDevs; i++) {
			if((dev[i].capabilities & IAXC_AD_OUTPUT) && strcmp(dbv.pszVal, dev[i].name) == 0) out = i;
		}
		DBFreeVariant(&dbv);
	}
	/*
	if(!DBGetContactSettingTString(0, MODULE, "DeviceRing", &dbv)) {
		for(int i = 0; i < nDevs; i++) {
			if((dev[i].capabilities & IAXC_AD_RING) && strcmp(dbv.pszVal, dev[i].name) == 0) ring = i;
		}
		DBFreeVariant(&dbv);
	}
	*/

	options.port = DBGetContactSettingDword(0, MODULE, "Port", 4569);
	iaxc_audio_devices_set(in, out, ring);

	options.dlgHotkey = DBGetContactSettingWord(0, MODULE, "DlgHotkey", 0);
	options.pop_dial_in = (DBGetContactSettingByte(0, MODULE, "PopupDial", 1) == 1);
	options.pop_dial_out = (DBGetContactSettingByte(0, MODULE, "PopupDialOut", 0) == 1);
	
	options.mic_boost = (DBGetContactSettingByte(0, MODULE, "MicBoost", 0) == 1);
	iaxc_mic_boost_set(options.mic_boost ? 1 : 0);
	//options.mic_boost = (iaxc_mic_boost_get() != 0);
}
示例#2
0
static BOOL CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
	switch ( msg ) {
	case WM_INITDIALOG:
		TranslateDialogDefault( hwndDlg );

		SetDlgItemText(hwndDlg, IDC_ED_UNAME, options.username);
		SetDlgItemText(hwndDlg, IDC_ED_PW, options.password);
		SetDlgItemText(hwndDlg, IDC_ED_HOST, options.host);
		SetDlgItemText(hwndDlg, IDC_ED_CIDNAME, options.cid_name);
		SetDlgItemText(hwndDlg, IDC_ED_CIDNUM, options.cid_number);
		SetDlgItemInt(hwndDlg, IDC_ED_PORT, options.port, FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_POPDIALIN, options.pop_dial_in ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_POPDIALOUT, options.pop_dial_out ? TRUE : FALSE);
		CheckDlgButton(hwndDlg, IDC_CHK_MICBOOST, options.mic_boost ? TRUE : FALSE);

		{
			iaxc_audio_device *dev;
			int nDevs, in, out, ring, ind;
			iaxc_audio_devices_get(&dev, &nDevs, &in, &out, &ring);
			for(int i = 0; i < nDevs; i++) {
				if(dev[i].capabilities & IAXC_AD_INPUT) {
					ind = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVIN, CB_ADDSTRING, 0, (LPARAM)dev[i].name);
					SendDlgItemMessage(hwndDlg, IDC_CMB_DEVIN, CB_SETITEMDATA, ind, i);
					if(i == in) SendDlgItemMessage(hwndDlg, IDC_CMB_DEVIN, CB_SETCURSEL, ind, 0);
				}
				if(dev[i].capabilities & IAXC_AD_OUTPUT) {
					ind = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVOUT, CB_ADDSTRING, 0, (LPARAM)dev[i].name);
					SendDlgItemMessage(hwndDlg, IDC_CMB_DEVOUT, CB_SETITEMDATA, ind, i);
					if(i == out) SendDlgItemMessage(hwndDlg, IDC_CMB_DEVOUT, CB_SETCURSEL, ind, 0);
				}
				/*
				if(dev[i].capabilities & IAXC_AD_RING) {
					ind = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVRING, CB_ADDSTRING, 0, (LPARAM)dev[i].name);
					SendDlgItemMessage(hwndDlg, IDC_CMB_DEVRING, CB_SETITEMDATA, ind, i);
					if(i == ring) SendDlgItemMessage(hwndDlg, IDC_CMB_DEVRING, CB_SETCURSEL, ind, 0);
				}
				*/
			}
		}
		SendDlgItemMessage(hwndDlg, IDC_HK_DLG, HKM_SETHOTKEY, options.dlgHotkey, 0);

		return FALSE;		
	case WM_COMMAND:
		if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) {
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);		
		}
		if ( HIWORD( wParam ) == CBN_SELCHANGE) {
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);		
		}
		if ( HIWORD( wParam ) == BN_CLICKED) {
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);		
		}
		break;
	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code)
		{
			case PSN_APPLY:
				{
					char buffer[512];

					GetDlgItemText(hwndDlg, IDC_ED_UNAME, buffer, 512);
					if(options.username) free(options.username);
					options.username = strdup(buffer);

					GetDlgItemText(hwndDlg, IDC_ED_PW, buffer, 512);
					if(options.password) free(options.password);
					options.password = strdup(buffer);

					GetDlgItemText(hwndDlg, IDC_ED_HOST, buffer, 512);
					if(options.host) free(options.host);
					options.host = strdup(buffer);

					GetDlgItemText(hwndDlg, IDC_ED_CIDNAME, buffer, 512);
					if(options.cid_name) free(options.cid_name);
					options.cid_name = strdup(buffer);

					GetDlgItemText(hwndDlg, IDC_ED_CIDNUM, buffer, 512);
					if(options.cid_number) free(options.cid_number);
					options.cid_number = strdup(buffer);

					DBWriteContactSettingTString(0, MODULE, "Host", options.host);
					DBWriteContactSettingTString(0, MODULE, "Username", options.username);
					DBWriteContactSettingTString(0, MODULE, "Password", options.password);
					DBWriteContactSettingTString(0, MODULE, "CIDName", options.cid_name);
					DBWriteContactSettingTString(0, MODULE, "CIDNumber", options.cid_number);

					iaxc_audio_device *dev;
					int nDevs, in, out, ring, ind;
					iaxc_audio_devices_get(&dev, &nDevs, &in, &out, &ring);

					ind = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVIN, CB_GETCURSEL, 0, 0);
					in = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVIN, CB_GETITEMDATA, ind, 0);
					ind = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVOUT, CB_GETCURSEL, 0, 0);
					out = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVOUT, CB_GETITEMDATA, ind, 0);
					//ind = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVRING, CB_GETCURSEL, 0, 0);
					//ring = SendDlgItemMessage(hwndDlg, IDC_CMB_DEVRING, CB_GETITEMDATA, ind, 0);

					DBWriteContactSettingTString(0, MODULE, "DeviceIn", dev[in].name);
					DBWriteContactSettingTString(0, MODULE, "DeviceOut", dev[out].name);
					//DBWriteContactSettingTString(0, MODULE, "DeviceRing", dev[ring].name);

					BOOL trans;
					int port = GetDlgItemInt(hwndDlg, IDC_ED_PORT, &trans, FALSE);
					if(trans) options.port = port;
					DBWriteContactSettingDword(0, MODULE, "Port", options.port);

					iaxc_audio_devices_set(in, out, ring);

					options.dlgHotkey = (WORD)SendDlgItemMessage(hwndDlg, IDC_HK_DLG, HKM_GETHOTKEY, 0, 0);
					DBWriteContactSettingWord(0, MODULE, "DlgHotkey", options.dlgHotkey);
					ResetDlgHotkey();

					options.pop_dial_in = IsDlgButtonChecked(hwndDlg, IDC_CHK_POPDIALIN) ? true : false;
					options.pop_dial_out = IsDlgButtonChecked(hwndDlg, IDC_CHK_POPDIALOUT) ? true : false;
					DBWriteContactSettingByte(0, MODULE, "PopupDial", options.pop_dial_in ? 1 : 0);
					DBWriteContactSettingByte(0, MODULE, "PopupDialOut", options.pop_dial_out ? 1 : 0);

					options.mic_boost = IsDlgButtonChecked(hwndDlg, IDC_CHK_MICBOOST) ? true : false;
					DBWriteContactSettingByte(0, MODULE, "MicBoost", options.mic_boost ? 1 : 0);
					iaxc_mic_boost_set(options.mic_boost ? 1 : 0);
				}

				return TRUE;
		}
		break;
	}

	return 0;
}
示例#3
0
文件: fgcom.cpp 项目: Affix/fgcom
int
main (int argc, char *argv[])
{
  int numbytes;
  static char buf[MAXBUFLEN];
  //int c;
  //int ret = 0;

	prog = strdup( base_name(argv[0]) );
  
	/* program header */
	std::cout << prog << " - a communication radio based on VoIP with IAX/Asterisk" << std::endl;
	std::cout << "Original (c) 2007-2011 by H. Wirtz <*****@*****.**>" << std::endl;
    std::cout << "OSX and Windows ports 2012 by Yves Sablonier and Geoff R. McLane, respectively." << std::endl;
	std::cout << "Version " << FGCOM_VERSION << " build " << SVN_REV << " date " << __DATE__ << ", at " << __TIME__ << std::endl;
	std::cout << "Using iaxclient library Version " << iaxc_version (tmp) << std::endl;
	std::cout << std::endl;

  /* init values */
  voipserver = DEFAULT_VOIP_SERVER;
  fgserver = DEFAULT_FG_SERVER;
  port = DEFAULT_FG_PORT;
  username = DEFAULT_USER;
  password = DEFAULT_PASSWORD;
  codec_option = DEFAULT_CODEC;
  mode = 0;			/* 0 = ATC mode, 1 = FG mode */
  positions_file = (char *) DEFAULT_POSITIONS_FILE;
  frequency_file = (char *) SPECIAL_FREQUENCIES_FILE;

#ifndef _WIN32
  /* catch signals */
  signal (SIGINT, quit);
  signal (SIGQUIT, quit);
  signal (SIGTERM, quit);
#endif

  /* setup iax */
#ifdef HAVE_IAX12
  if (iaxc_initialize (DEFAULT_MAX_CALLS))
#else
  if (iaxc_initialize (DEFAULT_IAX_AUDIO, DEFAULT_MAX_CALLS))
#endif
    fatal_error ("cannot initialize iaxclient!\nHINT: Have you checked the mic and speakers?");

  initialized = 1;

  // option parser
  fgcomInitOptions (fgcomOptionArray, argc, argv);

  // codec
  if (codec_option)
    {
      switch (codec_option)
	{
	case 'u':
	  codec = IAXC_FORMAT_ULAW;
	  break;
	case 'a':
	  codec = IAXC_FORMAT_ALAW;
	  break;
	case 'g':
	  codec = IAXC_FORMAT_GSM;
	  break;
	case '7':
	  codec = IAXC_FORMAT_G726;
	  break;
	case 's':
	  codec = IAXC_FORMAT_SPEEX;
	  break;
	}
    }

  // airport
  if (airport_option)
    {
      strtoupper (airport_option, airport, sizeof (airport));
    }

  // input level
  if (level_in > 1.0)
    {
      level_in = 1.0;
    }
  if (level_in < 0.0)
    {
      level_in = 0.0;
    }

  // output level
  if (level_out > 1.0)
    {
      level_out = 1.0;
    }
  if (level_out < 0.0)
    {
      level_out = 0.0;
    }

  // microphone boost
  if (mic_boost)
    {
      iaxc_mic_boost_set (1);
    }

  if (list_audio)
    {
      std::cout << "Input audio devices:" << std::endl;
      std::cout << report_devices (IAXC_AD_INPUT) << std::endl;

      std::cout << "Output audio devices:" << std::endl;
      std::cout << report_devices (IAXC_AD_OUTPUT) << std::endl;

      iaxc_shutdown ();
      exit (1);
    }


  if (audio_in)
    {
      set_device (audio_in, 0);
    }

  if (audio_out)
    {
      set_device (audio_out, 1);
    }

//#ifdef DEBUG
  /* Print any remaining command line arguments (not options). */
  //if (optind < argc) {
  //      printf ("non-option ARGV-elements: ");
  //      while (optind < argc)
  //              printf ("%s ", argv[optind++]);
  //      putchar ('\n');
  //}
//#endif

  /* checking consistency of arguments */
  if (frequency > 0.0 && frequency < 1000.0)
    {
      if (strlen (airport) == 0 || strlen (airport) > 4)
	{
	  strcpy (airport, "ZZZZ");
	}
      /* airport and frequency are given => ATC mode */
      mode = 0;
    }
  else
    {
      /* no airport => FG mode */
      mode = 1;
    }

	/* Read special frequencies file (if exists).
	 * If no file $(INSTALL_DIR)/special_frequencies.txt exists, then default frequencies
	 * are used and are hard coded.
	 */

    if (fix_input_files()) { /* adjust default input per OS */
        fatal_error ("cannot adjust default input files per OS!\nHINT: Maybe recompile with larger buffer.");
    }

	if((special_frequencies = read_special_frequencies(frequency_file)) == 0) {
        std::cout << "Failed to load file [" << frequency_file << "]!\nUsing internal defaults." << std::endl;
        special_frequencies = special_frq;
    } else {
        std::cout << "Loaded file [" << frequency_file << "]." << std::endl;
    }

	/* read airport frequencies and positions */
	airportlist = read_airports (positions_file);   /* never returns if fail! */

  /* preconfigure iax */
  std::cout << "Initializing IAX client as " << username << ":" <<
    "xxxxxxxxxxx@" << voipserver << std::endl;

  iaxc_set_callerid (const_cast < char *>(username),
		     const_cast < char *>("0125252525122750"));
  iaxc_set_formats (codec,
		    IAXC_FORMAT_ULAW | IAXC_FORMAT_GSM | IAXC_FORMAT_SPEEX);
  iaxc_set_event_callback (iaxc_callback);

  iaxc_start_processing_thread ();

  if (username && password && voipserver)
    {
      reg_id =
	iaxc_register (const_cast < char *>(username),
		       const_cast < char *>(password),
		       const_cast < char *>(voipserver));
#ifdef DEBUG
      std::cout << "DEBUG: Registered as '" << username << "' at '" << voipserver <<
	"'." << std::endl;
#endif
    }
  else
    {
      std::cout << "Failed iaxc_register!\nHINT: Check user name, pwd and ip of server." << std::endl;
      exitcode = 130;
      quit (0);
    }

  iaxc_millisleep (DEFAULT_MILLISLEEP);

  /* main loop */
#ifdef DEBUG
  std::cout << "Entering main loop in mode " << mode_map[mode] << "." <<
    std::endl;
#endif

  if (mode == 1)
    {
      /* only in FG mode */
      netInit ();
      netSocket fgsocket;
      fgsocket.open (false);
      fgsocket.bind (fgserver, port);

      /* mute mic, speaker on */
      iaxc_input_level_set (0);
      iaxc_output_level_set (level_out);

      ulClock clock;
      clock.update ();
      double next_update = clock.getAbsTime () + DEFAULT_ALARM_TIMER;
      /* get data from flightgear */
      while (1)
	{
	  clock.update ();
	  double wait = next_update - clock.getAbsTime ();
	  if (wait > 0.001)
	    {
	      netSocket *readsockets[2] = { &fgsocket, 0 };
	      if (fgsocket.select (readsockets, readsockets + 1,
				   (int) (wait * 1000)) == 1)
		{
		  netAddress their_addr;
		  if ((numbytes =
		       fgsocket.recvfrom (buf, MAXBUFLEN - 1, 0,
					  &their_addr)) == -1)
		    {
		      perror ("recvfrom");
		      exit (1);
		    }
		  buf[numbytes] = '\0';
#ifdef DEBUG
		  std::
		    cout << "DEBUG: got packet from " << their_addr.getHost () << ":"
		    << their_addr.getPort () << std::endl;
		  std::cout << "packet is " << numbytes << " bytes long" <<
		    std::endl;
		  std::
		    cout << "packet contains \"" << buf << "\"" << std::endl;
#endif
		  process_packet (buf);
		}
	    }
	  else
	    {
	      alarm_handler (0);
	      clock.update ();
	      next_update = clock.getAbsTime () + DEFAULT_ALARM_TIMER;
	    }
	}
    }
  else
    {
      /* only in ATC mode */
      struct pos p;

      /* mic on, speaker on */
      iaxc_input_level_set (level_in);
      iaxc_output_level_set (level_out);

      /* get geo positions of the airport */
      p = posbyicao (airportlist, airport);

      icao2number (airport, frequency, tmp);
#ifdef DEBUG
      printf ("DEBUG: dialing %s %3.3f MHz: %s\n", airport, frequency, tmp);
#endif
      do_iaxc_call (username, password, voipserver, tmp);
      /* iaxc_select_call (0); */

      while (1)
	{
	  /* sleep endless */
	  ulSleep (3600);
	}
    }

  /* should never be reached */
  exitcode = 999;
  quit (0);
}