Beispiel #1
0
bool rigControl::init()
{
    int retcode;
    if(!catParams.enableCAT) return false;

    addToLog(QString("rigcontrol:init myport pathname: %1").arg(myport.pathname),LOGRIGCTRL);
    catParams.radioModelNumber=getModelNumber(getRadioModelIndex());
    my_rig = rig_init(catParams.radioModelNumber);
    if(!my_rig)
    {
        addToLog(QString("Error in connection using radio model %1").arg(catParams.radioModel),LOGALL);
        initError=QString("Error in connection using radio model %1").arg(catParams.radioModel);
        return false;
    }

    if(QString(my_rig->caps->mfg_name)=="Icom")
    {
        if(!catParams.civAddress.isEmpty())
        {
            rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), catParams.civAddress.toLatin1());
        }
    }

    strncpy(my_rig->state.rigport.pathname,(const char *)catParams.serialPort.toLatin1().data(),FILPATHLEN);
    strncpy(my_rig->state.pttport.pathname,(const char *)catParams.serialPort.toLatin1().data(),FILPATHLEN);
    my_rig->state.rigport.parm.serial.rate = catParams.baudrate;
    my_rig->state.rigport.parm.serial.data_bits=catParams.databits;
    my_rig->state.rigport.parm.serial.stop_bits=catParams.stopbits;
    if(catParams.parity=="Even") my_rig->state.rigport.parm.serial.parity= RIG_PARITY_EVEN;
    else if (catParams.parity=="Odd") my_rig->state.rigport.parm.serial.parity = RIG_PARITY_ODD;
    else  my_rig->state.rigport.parm.serial.parity = RIG_PARITY_NONE;
    if(catParams.handshake=="XOn/Xoff") my_rig->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF;
    if(catParams.handshake=="Hardware") my_rig->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE;
    else my_rig->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
    my_rig->state.pttport.type.ptt = catParams.pttType;

    addToLog(QString("rigcontrol:init rigport.pathname: %1").arg(my_rig->state.rigport.pathname),LOGRIGCTRL);
    retcode = rig_open(my_rig);
    if (retcode != RIG_OK )
    {
        addToLog(QString("CAT Error: %1").arg(QString(rigerror(retcode))),LOGALL);
        initError=QString("CAT Error: %1").arg(QString(rigerror(retcode)));
        return false;
    }
    addToLog("rigcontroller successfully opened",LOGRIGCTRL);
    rigControlEnabled=true;
    // int verbose=0;
    // rig_set_debug(verbose<2 ? RIG_DEBUG_NONE: (rig_debug_level_e)verbose);
    // rig_debug(RIG_DEBUG_VERBOSE, "rigctl, %s\n", hamlib_version);
    // test if we can contact the tranceiver
    double fr;
    if(!getFrequency(fr))
    {
        //        rigControlEnabled=false;
    }
    return true;
}
Beispiel #2
0
void __fastcall TRigCtlMain::FormShow( TObject */*Sender*/ )
{
   TIniFile * t = new TIniFile( ".\\Configuration\\RigSelect.ini" );
   mfg = t->ReadString( "RigControl", "Manufacturer", "NoMfG" );
   model = t->ReadString( "RigControl", "Model", "NoMoDeL" );
   delete t;
   makeRPCObjects();
   XMPPInitialise( "RigCtl" );
   rig_load_all_backends();

   selected = -1;
   int status = rig_list_foreach( print_model_list, NULL );
   if ( status != RIG_OK )
   {
      char buff[ 1024 ];
      sprintf( buff, "rig_list_foreach: error = %s \n", rigerror( status ) );
      trace( buff );
   }
   RigCombo->Sorted = true;

   if ( selected != -1 )
   {
      RigCombo->ItemIndex = RigCombo->Items->IndexOfObject( ( TObject * ) selected );
      RigSelectButtonClick( this );
   }
   else
      RigCombo->ItemIndex = 0;
}
Beispiel #3
0
void Hamlib::setFrequency(Session::ref session, Request::ref request, Reply::ref reply) {
	Config *config = m_server->getConfig();
	if (config->getUnregistered().find("hamlib.device") == config->getUnregistered().end()) {
		LOG_ERROR(logger, "Set '[hamlib] device' in config file.");
	}

	std::string device = config->getUnregistered().find("hamlib.device")->second;

	RIG *my_rig;
	freq_t freq;
	int retcode;

	std::string f = request->getContent();

	if (sscanf(f.c_str(), "%lf", &freq) != 1) {
		LOG_WARN(logger, "Unable to read freq " << f)
		fprintf(stderr, "ERROR: Unable to read freq.\n");
	}
	std::cout << boost::lexical_cast<std::string>((double) freq) << "\n";
	rig_set_debug(RIG_DEBUG_NONE);
	//  rig_set_debug(RIG_DEBUG_TRACE);

	rig_model_t myrig_model = RIG_MODEL_IC706MKIIG;
	my_rig = rig_init(myrig_model);
	my_rig->state.rigport.type.rig = RIG_PORT_SERIAL;
	my_rig->state.rigport.parm.serial.rate = 19200;
	my_rig->state.rigport.parm.serial.data_bits = 8;
	my_rig->state.rigport.parm.serial.stop_bits = 1;
	my_rig->state.rigport.parm.serial.parity = RIG_PARITY_NONE;
	my_rig->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
	strncpy(my_rig->state.rigport.pathname, device.c_str(), FILPATHLEN - 1);
	if ((retcode = rig_open(my_rig)) != RIG_OK)
	{
		fprintf(stderr, "rig_open: error = %s\n", rigerror(retcode));
		LOG_ERROR(logger, "rig_open: error " << rigerror(retcode));
	}
	if ((retcode = rig_set_freq(my_rig, RIG_VFO_CURR, freq) != RIG_OK))
	{
		LOG_ERROR(logger, "rig_set_freq: error " << rigerror(retcode));
	}
	rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
	rig_close(my_rig);
	rig_cleanup(my_rig);
}
Beispiel #4
0
int icmarine_open(RIG *rig)
{
  char respbuf[BUFSZ+1];
  rig_debug(RIG_DEBUG_VERBOSE,"%s called\n", __FUNCTION__);
  int retval = icmarine_transaction(rig, "REMOTE", "ON", respbuf); 
  if (retval != RIG_OK) {
    rig_debug(RIG_DEBUG_VERBOSE, "%s: rig not responding? %s\n",__FUNCTION__, rigerror(retval));
        
  }
  return RIG_OK;
}
Beispiel #5
0
int ft857_set_vfo(RIG *rig, vfo_t vfo)
{
  vfo_t curvfo;
  int retval =  ft857_get_vfo(rig,&curvfo);
  if (retval != RIG_OK) {
    rig_debug(RIG_DEBUG_ERR,"%s: error get_vfo '%s'\n",__func__,rigerror(retval));
    return retval; 
  }
  if (curvfo == vfo) {
    return RIG_OK;
  }
  return ft857_send_cmd(rig, FT857_NATIVE_CAT_SET_VFOAB);
}
Beispiel #6
0
int initialize_rig()
{
  RIG *my_rig;            /* handle to rig (nstance) */
  int retcode;

  config_setting_t *rig_control_settings;
  rig_control_settings = config_lookup(&cfg, "repeater.rig_control");

  int rig_id, baud_rate, data_bits, stop_bits, enabled;
  const char *serial_port, *frequency;
  
  config_setting_lookup_int(rig_control_settings, "rig_id", &rig_id);
  config_setting_lookup_int(rig_control_settings, "baud_rate", &baud_rate);
  config_setting_lookup_int(rig_control_settings, "data_bits", &data_bits);
  config_setting_lookup_int(rig_control_settings, "stop_bits", &stop_bits);
  config_setting_lookup_bool(rig_control_settings, "enabled", &enabled);
  config_setting_lookup_string(rig_control_settings, "frequency", &frequency);
  config_setting_lookup_string(rig_control_settings, "serial_port", &serial_port);

  if (!enabled)
    return -1;
  
  printf("frequency: %s\n", frequency);

  rig_set_debug(RIG_DEBUG_WARN);
  my_rig = rig_init(rig_id);

  if (!my_rig) {
    fprintf(stderr,"Unknown rig num: %d\n", rig_id);
    fprintf(stderr,"Please check riglist.h\n");
    exit(1); /* whoops! something went wrong (mem alloc?) */
  }

  strncpy(my_rig->state.rigport.pathname, "/dev/ttyS0", FILPATHLEN - 1);
  my_rig->state.rigport.parm.serial.rate = baud_rate;
  my_rig->state.rigport.parm.serial.data_bits = data_bits;
  my_rig->state.rigport.parm.serial.stop_bits = stop_bits;

  retcode = rig_open(my_rig);
  if (retcode != RIG_OK) {
    printf("rig_open: error = %s\n", rigerror(retcode));
    exit(2);
  }

  return rig_set_freq(my_rig, RIG_VFO_CURR, atoi(frequency));
}
void __fastcall TTestRigMain::FreqSliderChange( TObject */*Sender*/ )
{
   if ( !noSetFreq )
   {
      int pos = FreqSlider->Position;
      freq_t freq = 28000000;

      freq += pos * 100;
      int ferr = rig_set_freq( my_rig, RIG_VFO_CURR, freq );
      if ( ferr != RIG_OK )
      {
         char buff[ 1024 ];
         sprintf( buff, "rig_setFreq: error = %s", rigerror( ferr ) );
         Label2->Caption = buff;
      }
   }
}
void hamlib_set_ptt(gint ptt)
{
	gint ret;

	if (!rig || !hamlib_ptt)
		return;

	G_LOCK(hamlib_mutex);

	ret = rig_set_ptt(rig, RIG_VFO_CURR, ptt ? RIG_PTT_ON : RIG_PTT_OFF);

	if (ret != RIG_OK) {
		errmsg(_("rig_set_ptt failed: %s.\nHamlib PTT disabled.\n"), rigerror(ret));
		hamlib_ptt = FALSE;
	}

	G_UNLOCK(hamlib_mutex);
}
static gboolean hamlib_set_param(const gchar *par, const gchar *val)
{
	token_t t;
	gint ret;

	g_return_val_if_fail(rig != NULL, FALSE);

	if ((t = rig_token_lookup(rig, par)) == RIG_CONF_END) {
		errmsg(_("Hamlib init: Bad rig config parameter: '%s'"), par);
		return FALSE;
	}

	if ((ret = rig_set_conf(rig, t, val)) != RIG_OK) {
		errmsg(_("Hamlib init: rig_set_conf failed (%s=%s): %s"), par, val, rigerror(ret));
		return FALSE;
	}

	return TRUE;
}
Beispiel #10
0
void __fastcall TRigCtlMain::RigSelectButtonClick( TObject *Sender )
{
   if ( my_rig )
   {
      rig_cleanup( my_rig );
      my_rig = 0;
   }

   int rig_model = ( int ) RigCombo->Items->Objects[ RigCombo->ItemIndex ];
   std::string port = PortCombo->Text.t_str();
   //  	my_rig = rig_init(RIG_MODEL_FT1000MP);
   my_rig = rig_init( rig_model );
   if ( !my_rig )
   {
      Label1->Caption = "rig_init failed";
      return ;
   }
   strncpy( my_rig->state.rigport.pathname, port.c_str(), FILPATHLEN );
   int retcode = rig_open( my_rig );
   char buff[ 1024 ];
   if ( retcode != RIG_OK )
   {
      sprintf( buff, "rig_open: error = %s \n", rigerror( retcode ) );
      Label1->Caption = buff;
      my_rig = 0;
   }
   else
   {
      sprintf( buff, "Opened rig model %d, '%s'\n", my_rig->caps->rig_model,
               my_rig->caps->model_name );

      TIniFile *t = new TIniFile( ".\\Configuration\\RigSelect.ini" );
      t->WriteString( "RigControl", "Manufacturer", my_rig->caps->mfg_name );
      t->WriteString( "RigControl", "Model", my_rig->caps->model_name );
      delete t;

      Label1->Caption = buff;
      trace( std::string( "Rig selected: " ) + buff );

      ChangeButtonClick( Sender );
   }
}
void __fastcall TTestRigMain::RigSelectButtonClick( TObject */*Sender*/ )
{
   if ( my_rig )
   {
      rig_cleanup( my_rig );
      my_rig = 0;
   }

   int rig_model = ( int ) RigCombo->Items->Objects[ RigCombo->ItemIndex ];
   String port = PortCombo->Text;

   my_rig = rig_init( rig_model );
   if ( !my_rig )
   {
      Label1->Caption = "rig_init failed";
      return ;
   }
   strncpy( my_rig->state.rigport.pathname, port.t_str(), FILPATHLEN );
   int retcode = rig_open( my_rig );
   char buff[ 1024 ];
   if ( retcode != RIG_OK )
   {
      sprintf( buff, "rig_open: error = %s \n", rigerror( retcode ) );
      Label1->Caption = buff;
      my_rig = 0;
   }
   else
   {
      sprintf( buff, "Opened rig model %d, %s '%s'\n", my_rig->caps->rig_model,
               my_rig->caps->mfg_name, my_rig->caps->model_name );

      TIniFile *t = new TIniFile( ".\\Configuration\\RigSelect.ini" );
      t->WriteString( "TestRig", "Manufacturer", my_rig->caps->mfg_name );
      t->WriteString( "TestRig", "Model", my_rig->caps->model_name );
      delete t;

      Label1->Caption = buff;
   }

}
void __fastcall TTestRigMain::ModeRadioGroupClick( TObject */*Sender*/ )
{
   if ( !noSetMode )
   {
      rmode_t mode;
      if ( ModeRadioGroup->ItemIndex == 0 )
         mode = RIG_MODE_NONE;
      if ( ModeRadioGroup->ItemIndex == 1 )
         mode = RIG_MODE_CW;
      else
         if ( ModeRadioGroup->ItemIndex == 2 )
            mode = RIG_MODE_USB;
         else
            mode = RIG_MODE_NONE;

      int ferr = rig_set_mode( my_rig, RIG_VFO_CURR, mode, RIG_FREQ_NONE );
      if ( ferr != RIG_OK )
      {
         char buff[ 1024 ];
         sprintf( buff, "rig_set_mode: error = %s", rigerror( ferr ) );
         Label2->Caption = buff;
      }
   }
}
void __fastcall TTestRigMain::Timer1Timer( TObject *Sender )
{
   static in_timer = false;
   if ( in_timer )
      return ;

   static bool closed = false;
   if ( !closed )
   {
      if ( checkCloseEvent() )
      {
         closed = true;
         CloseButtonClick( Sender );
      }
   }

   in_timer = true;

   freq_t freq;
   shortfreq_t ritfreq;
   shortfreq_t xitfreq;
   rmode_t mode;
   pbwidth_t width;

   char buff[ 1024 ];

   DWORD t = GetTickCount();

   int ferr = rig_get_freq( my_rig, RIG_VFO_CURR, &freq );
   //  int rerr = rig_get_rit(my_rig, RIG_VFO_CURR, &ritfreq);
   //  int xerr = rig_get_xit(my_rig, RIG_VFO_CURR, &xitfreq);
   int merr = rig_get_mode( my_rig, RIG_VFO_CURR, &mode, &width );

   DWORD t1 = GetTickCount();

   if ( ferr != RIG_OK )
   {
      sprintf( buff, "Time %d rig_getFreq: error = %s", ( int ) ( t1 - t ), rigerror( ferr ) );
      Label2->Caption = buff;
   }
   else
   {
      sprintf( buff, "rig_getFreq Time %d Freq %lld", ( int ) ( t1 - t ), ( long long ) freq );
      Label2->Caption = buff;

      noSetFreq = true;
      FreqSlider->Position = ( freq - 28000000 ) / 100;
      noSetFreq = false;
   }
   if ( merr != RIG_OK )
   {
      sprintf( buff, "Time %d rig_get_mode: error = %s", ( int ) ( t1 - t ), rigerror( ferr ) );
      Label2->Caption = buff;
   }
   else
   {
      sprintf( buff, "rig_get_mode Time %d mode %d", ( int ) ( t1 - t ), ( long ) mode );
      Label2->Caption = buff;

      noSetMode = true;
      switch ( mode )
      {
         case RIG_MODE_AM:
            ModeRadioGroup->ItemIndex = 0;
            break;

         case RIG_MODE_CW:
            ModeRadioGroup->ItemIndex = 1;
            break;

         case RIG_MODE_USB:
            ModeRadioGroup->ItemIndex = 2;
            break;

         case RIG_MODE_LSB:
            ModeRadioGroup->ItemIndex = 2;
            break;

         case RIG_MODE_RTTY:
            ModeRadioGroup->ItemIndex = 0;
            break;

         case RIG_MODE_FM:
            ModeRadioGroup->ItemIndex = 0;
            break;

         case RIG_MODE_WFM:
            ModeRadioGroup->ItemIndex = 0;
            break;

         case RIG_MODE_CWR:
            ModeRadioGroup->ItemIndex = 1;
            break;

         case RIG_MODE_RTTYR:
            ModeRadioGroup->ItemIndex = 0;
            break;

         case RIG_MODE_AMS:
            ModeRadioGroup->ItemIndex = 0;
            break;

         case RIG_MODE_PKTLSB:
            ModeRadioGroup->ItemIndex = 2;
            break;

         case RIG_MODE_PKTUSB:
            ModeRadioGroup->ItemIndex = 2;
            break;

         case RIG_MODE_PKTFM:
            ModeRadioGroup->ItemIndex = 0;
            break;

         case RIG_MODE_ECSSUSB:
            ModeRadioGroup->ItemIndex = 2;
            break;

         case RIG_MODE_ECSSLSB:
            ModeRadioGroup->ItemIndex = 2;
            break;

         case RIG_MODE_FAX:
            ModeRadioGroup->ItemIndex = 0;
            break;

         case RIG_MODE_NONE:
         default:
            ModeRadioGroup->ItemIndex = 0;
            break;

      }
      noSetMode = false;
   }

   in_timer = false;
}
Beispiel #14
0
int main (int argc, char *argv[])
{
	RIG *my_rig;		/* handle to rig (nstance) */
	rig_model_t my_model = RIG_MODEL_DUMMY;

	int retcode;		/* generic return code from functions */
	int exitcode;

	int verbose = 0;
	int show_conf = 0;
	int dump_caps_opt = 0;
#ifdef HAVE_READLINE_HISTORY
	int rd_hist = 0;
	int sv_hist = 0;
	const char *hist_dir = NULL;
	const char hist_file[] = "/.rigctl_history";
	char *hist_path = NULL;
	struct stat hist_dir_stat;
#endif
	const char *rig_file=NULL, *ptt_file=NULL, *dcd_file=NULL;
	ptt_type_t ptt_type = RIG_PTT_NONE;
	dcd_type_t dcd_type = RIG_DCD_NONE;
	int serial_rate = 0;
	char *civaddr = NULL;	/* NULL means no need to set conf */
	char conf_parms[MAXCONFLEN] = "";

	while(1) {
		int c;
		int option_index = 0;

		c = getopt_long (argc, argv, SHORT_OPTIONS HST_SHRT_OPTS,
			long_options, &option_index);
		if (c == -1)
			break;

		switch(c) {
			case 'h':
				usage();
				exit(0);
			case 'V':
				version();
				exit(0);
			case 'm':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				my_model = atoi(optarg);
				break;
			case 'r':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				rig_file = optarg;
				break;
			case 'p':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				ptt_file = optarg;
				break;
			case 'd':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				dcd_file = optarg;
				break;
			case 'P':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				if (!strcmp(optarg, "RIG"))
					ptt_type = RIG_PTT_RIG;
				else if (!strcmp(optarg, "DTR"))
					ptt_type = RIG_PTT_SERIAL_DTR;
				else if (!strcmp(optarg, "RTS"))
					ptt_type = RIG_PTT_SERIAL_RTS;
				else if (!strcmp(optarg, "PARALLEL"))
					ptt_type = RIG_PTT_PARALLEL;
				else if (!strcmp(optarg, "CM108"))
					ptt_type = RIG_PTT_CM108;
				else if (!strcmp(optarg, "GPIO"))
					ptt_type = RIG_PTT_GPIO;
				else if (!strcmp(optarg, "GPION"))
					ptt_type = RIG_PTT_GPION;
				else if (!strcmp(optarg, "NONE"))
					ptt_type = RIG_PTT_NONE;
				else
					ptt_type = atoi(optarg);
				break;
			case 'D':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				if (!strcmp(optarg, "RIG"))
					dcd_type = RIG_DCD_RIG;
				else if (!strcmp(optarg, "DSR"))
					dcd_type = RIG_DCD_SERIAL_DSR;
				else if (!strcmp(optarg, "CTS"))
					dcd_type = RIG_DCD_SERIAL_CTS;
				else if (!strcmp(optarg, "CD"))
					dcd_type = RIG_DCD_SERIAL_CAR;
				else if (!strcmp(optarg, "PARALLEL"))
					dcd_type = RIG_DCD_PARALLEL;
				else if (!strcmp(optarg, "CM108"))
					dcd_type = RIG_DCD_CM108;
				else if (!strcmp(optarg, "NONE"))
					dcd_type = RIG_DCD_NONE;
				else
					dcd_type = atoi(optarg);
				break;
			case 'c':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				civaddr = optarg;
				break;
			case 't':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				if (strlen(optarg) > 1)
					send_cmd_term = strtol(optarg, NULL, 0);
				else
					send_cmd_term = optarg[0];
				break;
			case 's':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				serial_rate = atoi(optarg);
				break;
			case 'C':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				if (*conf_parms != '\0')
					strcat(conf_parms, ",");
				strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
				break;
			case 'o':
				vfo_mode++;
				break;
		  case 'n':
			  rig_no_restore_ai();
        break;
#ifdef HAVE_READLINE_HISTORY
			case 'i':
				rd_hist++;
				break;
			case 'I':
				sv_hist++;
				break;
#endif
			case 'v':
				verbose++;
				break;
			case 'L':
				show_conf++;
				break;
			case 'l':
				rig_set_debug(verbose);
				list_models();
				exit(0);
			case 'u':
				dump_caps_opt++;
				break;
			default:
				usage();	/* unknown option? */
				exit(1);
		}
	}

	rig_set_debug(verbose);

	rig_debug(RIG_DEBUG_VERBOSE, "rigctl, %s\n", hamlib_version);
	rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
			"<*****@*****.**>\n\n");

	/*
	 * at least one command on command line,
	 * disable interactive mode
	 */
	if (optind < argc)
		interactive = 0;

  	my_rig = rig_init(my_model);

	if (!my_rig) {
		fprintf(stderr, "Unknown rig num %d, or initialization error.\n",
						my_model);
		fprintf(stderr, "Please check with --list option.\n");
		exit(2);
	}

	retcode = set_conf(my_rig, conf_parms);
	if (retcode != RIG_OK) {
		fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
		exit(2);
	}

	if (rig_file)
		strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);

	/*
	 * ex: RIG_PTT_PARALLEL and /dev/parport0
	 */
	if (ptt_type != RIG_PTT_NONE)
		my_rig->state.pttport.type.ptt = ptt_type;
	if (dcd_type != RIG_DCD_NONE)
		my_rig->state.dcdport.type.dcd = dcd_type;
	if (ptt_file)
		strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
	if (dcd_file)
		strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
	/* FIXME: bound checking and port type == serial */
	if (serial_rate != 0)
		my_rig->state.rigport.parm.serial.rate = serial_rate;
	if (civaddr)
        	rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);

	/*
	 * print out conf parameters
	 */
	if (show_conf) {
		dumpconf(my_rig, stdout);
	}

	/*
	 * print out capabilities, and exists immediately
	 * We may be interested only in only caps, and rig_open may fail.
	 */
	if (dump_caps_opt) {
		dumpcaps(my_rig, stdout);
		rig_cleanup(my_rig); /* if you care about memory */
		exit(0);
	}

	retcode = rig_open(my_rig);
	if (retcode != RIG_OK) {
	  	fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
		exit(2);
	}

	if (verbose > 0)
		printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model,
				my_rig->caps->model_name);
	rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
			my_rig->caps->version, rig_strstatus(my_rig->caps->status));

	exitcode = 0;

#ifdef HAVE_LIBREADLINE
	if (interactive && prompt && have_rl) {
		rl_readline_name = "rigctl";
#ifdef HAVE_READLINE_HISTORY
		using_history();	/* Initialize Readline History */

		if (rd_hist || sv_hist) {
			if (!(hist_dir = getenv("RIGCTL_HIST_DIR")))
				hist_dir = getenv("HOME");

			if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
				|| !(S_ISDIR(hist_dir_stat.st_mode))) {
				fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
			}

			hist_path = (char *)calloc((sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1)), sizeof(char));

			strncpy(hist_path, hist_dir, strlen(hist_dir));
			strncat(hist_path, hist_file, strlen(hist_file));
		}

		if (rd_hist && hist_path)
			if (read_history(hist_path) == ENOENT)
				fprintf(stderr, "Warning: Could not read history from %s\n", hist_path);
#endif
	}
#endif	/* HAVE_LIBREADLINE */

	do {
		retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc);
		if (retcode == 2)
			exitcode = 2;
	}
	while (retcode == 0 || retcode == 2);

#ifdef HAVE_LIBREADLINE
	if (interactive && prompt && have_rl) {
#ifdef HAVE_READLINE_HISTORY
		if (sv_hist && hist_path)
			if (write_history(hist_path) == ENOENT)
				fprintf(stderr, "\nWarning: Could not write history to %s\n", hist_path);

		if ((rd_hist || sv_hist) && hist_path) {
			free(hist_path);
			hist_path = (char *)NULL;
		}
#endif
	}
#endif
	rig_close(my_rig); /* close port */
	rig_cleanup(my_rig); /* if you care about memory */

	return exitcode;
}
Beispiel #15
0
void  rigControl::errorMessage(int errorCode,QString command)
{
    QMessageBox::information(0,"Cat interface",QString("Error in connection: %1\n%2").arg(QString(rigerror(errorCode))).arg(command));
}
Beispiel #16
0
int main (int argc, char *argv[])
{
	RIG *my_rig;		/* handle to rig (instance) */
	rig_model_t my_model = RIG_MODEL_DUMMY;

	int retcode;		/* generic return code from functions */

	int verbose = 0;
	int show_conf = 0;
	int dump_caps_opt = 0;
	const char *rig_file=NULL, *ptt_file=NULL, *dcd_file=NULL;
	ptt_type_t ptt_type = RIG_PTT_NONE;
	dcd_type_t dcd_type = RIG_DCD_NONE;
	int serial_rate = 0;
	char *civaddr = NULL;	/* NULL means no need to set conf */
	char conf_parms[MAXCONFLEN] = "";

	struct addrinfo hints, *result, *saved_result;
	int sock_listen;
	int reuseaddr = 1;
	char host[NI_MAXHOST];
	char serv[NI_MAXSERV];

	while(1) {
		int c;
		int option_index = 0;

		c = getopt_long (argc, argv, SHORT_OPTIONS,
			long_options, &option_index);
		if (c == -1)
			break;

		switch(c) {
			case 'h':
				usage();
				exit(0);
			case 'V':
				version();
				exit(0);
			case 'm':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				my_model = atoi(optarg);
				break;
			case 'r':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				rig_file = optarg;
				break;
			case 'p':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				ptt_file = optarg;
				break;
			case 'd':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				dcd_file = optarg;
				break;
			case 'P':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				if (!strcmp(optarg, "RIG"))
					ptt_type = RIG_PTT_RIG;
				else if (!strcmp(optarg, "DTR"))
					ptt_type = RIG_PTT_SERIAL_DTR;
				else if (!strcmp(optarg, "RTS"))
					ptt_type = RIG_PTT_SERIAL_RTS;
				else if (!strcmp(optarg, "PARALLEL"))
					ptt_type = RIG_PTT_PARALLEL;
				else if (!strcmp(optarg, "CM108"))
					ptt_type = RIG_PTT_CM108;
				else if (!strcmp(optarg, "NONE"))
					ptt_type = RIG_PTT_NONE;
				else
					ptt_type = atoi(optarg);
				break;
			case 'D':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				if (!strcmp(optarg, "RIG"))
					dcd_type = RIG_DCD_RIG;
				else if (!strcmp(optarg, "DSR"))
					dcd_type = RIG_DCD_SERIAL_DSR;
				else if (!strcmp(optarg, "CTS"))
					dcd_type = RIG_DCD_SERIAL_CTS;
				else if (!strcmp(optarg, "CD"))
					dcd_type = RIG_DCD_SERIAL_CAR;
				else if (!strcmp(optarg, "PARALLEL"))
					dcd_type = RIG_DCD_PARALLEL;
				else if (!strcmp(optarg, "NONE"))
					dcd_type = RIG_DCD_NONE;
				else
					dcd_type = atoi(optarg);
				break;
			case 'c':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				civaddr = optarg;
				break;
			case 's':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				serial_rate = atoi(optarg);
				break;
			case 'C':
				if (!optarg) {
						usage();	/* wrong arg count */
						exit(1);
				}
				if (*conf_parms != '\0')
						strcat(conf_parms, ",");
				strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
				break;
			case 't':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				portno = optarg;
				break;
			case 'T':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				src_addr = optarg;
				break;
			case 'o':
				vfo_mode++;
				break;
			case 'v':
				verbose++;
				break;
			case 'L':
				show_conf++;
				break;
			case 'l':
				list_models();
				exit(0);
			case 'u':
				dump_caps_opt++;
				break;
			default:
				usage();	/* unknown option? */
				exit(1);
		}
	}

  rig_set_debug(verbose);

	rig_debug(RIG_DEBUG_VERBOSE, "rigctld, %s\n", hamlib_version);
	rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
			"<*****@*****.**>\n\n");

	my_rig = rig_init(my_model);

	if (!my_rig) {
		fprintf(stderr, "Unknown rig num %d, or initialization error.\n",
						my_model);
		fprintf(stderr, "Please check with --list option.\n");
		exit(2);
	}

	retcode = set_conf(my_rig, conf_parms);
	if (retcode != RIG_OK) {
		fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
		exit(2);
	}

	if (rig_file)
		strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);

	/*
	 * ex: RIG_PTT_PARALLEL and /dev/parport0
	 */
	if (ptt_type != RIG_PTT_NONE)
		my_rig->state.pttport.type.ptt = ptt_type;
	if (dcd_type != RIG_DCD_NONE)
		my_rig->state.dcdport.type.dcd = dcd_type;
	if (ptt_file)
		strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
	if (dcd_file)
		strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
	/* FIXME: bound checking and port type == serial */
	if (serial_rate != 0)
		my_rig->state.rigport.parm.serial.rate = serial_rate;
	if (civaddr)
        	rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);

	/*
	 * print out conf parameters
	 */
	if (show_conf) {
		rig_token_foreach(my_rig, print_conf_list, (rig_ptr_t)my_rig);
	}

	/*
	 * print out conf parameters, and exits immediately
	 * We may be interested only in only caps, and rig_open may fail.
	 */
	if (dump_caps_opt) {
		dumpcaps(my_rig, stdout);
		rig_cleanup(my_rig); /* if you care about memory */
		exit(0);
	}

	retcode = rig_open(my_rig);
	if (retcode != RIG_OK) {
	  	fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
		exit(2);
	}

	if (verbose > 0)
		printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model,
				my_rig->caps->model_name);
	rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
			my_rig->caps->version, rig_strstatus(my_rig->caps->status));

#ifdef __MINGW32__
# ifndef SO_OPENTYPE
#  define SO_OPENTYPE     0x7008
# endif
# ifndef SO_SYNCHRONOUS_NONALERT
#  define SO_SYNCHRONOUS_NONALERT 0x20
# endif
# ifndef INVALID_SOCKET
#  define INVALID_SOCKET -1
# endif

    WSADATA wsadata;
    if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
	  	fprintf(stderr,"WSAStartup socket error\n");
		exit(1);
	}

	int sockopt = SO_SYNCHRONOUS_NONALERT;
	setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sockopt, sizeof(sockopt));
#endif

	/*
	 * Prepare listening socket
	 */
	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
	hints.ai_socktype = SOCK_STREAM;/* TCP socket */
	hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
	hints.ai_protocol = 0;          /* Any protocol */

	retcode = getaddrinfo(src_addr, portno, &hints, &result);
	if (retcode != 0) {
	    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
	    exit(2);
	}
  saved_result = result;

	do
		{
			sock_listen = socket(result->ai_family, result->ai_socktype,
													 result->ai_protocol);
			if (sock_listen < 0) {
				handle_error (RIG_DEBUG_ERR, "socket");
				freeaddrinfo(saved_result);		/* No longer needed */
				exit(2);
			}

      if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR,
										 (char *)&reuseaddr, sizeof(reuseaddr)) < 0) {
				handle_error (RIG_DEBUG_ERR, "setsockopt");
				freeaddrinfo(saved_result);		/* No longer needed */
				exit (1);
			}

#ifdef __MINGW32__
			/* allow IPv4 mapped to IPv6 clients, MS default this to 1! */
			sockopt = 0;
      if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY,
										 (char *)&sockopt, sizeof(sockopt)) < 0) {
				handle_error (RIG_DEBUG_ERR, "setsockopt");
				freeaddrinfo(saved_result);		/* No longer needed */
				exit (1);
			}
#endif

      if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
				break;
			}
			handle_error (RIG_DEBUG_WARN, "binding failed (trying next interface)");
#ifdef __MINGW32__
			closesocket (sock_listen);
#else
			close (sock_listen);
#endif
		} while ((result = result->ai_next) != NULL);

	freeaddrinfo(saved_result);		/* No longer needed */
  if (NULL == result)
		{
			rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n");
			exit (1);
		}

	if (listen(sock_listen, 4) < 0) {
		handle_error (RIG_DEBUG_ERR, "listening");
		exit (1);
	}

	/*
	 * main loop accepting connections
	 */
	do {
#ifdef HAVE_PTHREAD
		pthread_t thread;
		pthread_attr_t attr;
#endif
		struct handle_data *arg;

		arg = malloc(sizeof(struct handle_data));
		if (!arg) {
			rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
			exit (1);
		}

		arg->rig = my_rig;
		arg->clilen = sizeof (arg->cli_addr);
		arg->sock = accept(sock_listen, (struct sockaddr *)&arg->cli_addr, &arg->clilen);
		if (arg->sock < 0) {
			handle_error (RIG_DEBUG_ERR, "accept");
			break;
		}

		if ((retcode = getnameinfo ((struct sockaddr const *)&arg->cli_addr, arg->clilen, host, sizeof (host)
																, serv, sizeof (serv), NI_NOFQDN)) < 0)
			{
				rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode));
			}
		rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n",
							host, serv);

#ifdef HAVE_PTHREAD
		pthread_attr_init(&attr);
		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

		retcode = pthread_create(&thread, &attr, handle_socket, arg);
		if (retcode != 0) {
			rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
			break;
		}
#else
		handle_socket(arg);
#endif
	}
	while (retcode == 0);

	rig_close(my_rig); /* close port */
	rig_cleanup(my_rig); /* if you care about memory */

#ifdef __MINGW32__
	WSACleanup();
#endif

	return 0;
}
Beispiel #17
0
/**  csv_load assumes the first line in a csv file is a key line,
     defining entries and their number. First line should not
     contain 'empty column', i.e. two adjacent commas.
     Each next line should contain the same number of entries.
     However, empty columns (two adjacent commas) are allowed.
     \param rig - a pointer to the rig
     \param infilename - a string with a file name to write to
*/
int csv_load(RIG *rig, const char *infilename)
{
    int status = RIG_OK;
    FILE *f;
    char *key_list[ 64 ];
    char *value_list[ 64 ];
    char keys[ 256 ];
    char line[ 256 ];
    channel_t chan;

    f = fopen(infilename, "r");

    if (!f)
    {
        return -1;
    }

    /* First read the first line, containing the key */
    if (fgets(keys, sizeof(keys), f) != NULL)
    {

        /* fgets stores '\n' in a buffer, get rid of it */
        keys[ strlen(keys) - 1 ] = '\0';
        printf("Read the key: %s\n", keys);

        /* Tokenize the key list */
        if (!tokenize_line(keys,
                           key_list,
                           sizeof(key_list) / sizeof(char *),
                           ','))
        {
            fprintf(stderr,
                    "Invalid (possibly too long or empty) key line, cannot continue.\n");
            fclose(f);
            return -1;
        }
    }
    else
    {
        /* File exists, but is empty */
        fclose(f);
        return -1;
    }

    /* Next, read the file line by line */
    while (fgets(line, sizeof line, f) != NULL)
    {
        /* Tokenize the line */
        if (!tokenize_line(line,
                           value_list,
                           sizeof(value_list) / sizeof(char *),
                           ','))
        {

            fprintf(stderr, "Invalid (possibly too long or empty) line ignored\n");
            continue;
        }

        /* Parse a line, write channel data into chan */
        set_channel_data(rig, &chan, key_list, value_list);

        /* Write a rig memory */
        status = rig_set_channel(rig, &chan);

        if (status != RIG_OK)
        {
            fprintf(stderr, "rig_get_channel: error = %s \n", rigerror(status));
            fclose(f);
            return status;
        }

    }

    fclose(f);
    return status;
}
Beispiel #18
0
int main (int argc, char *argv[])
{
	RIG *my_rig;		/* handle to rig (nstance) */
	int retcode;		/* generic return code from functions */
	int i, count = 0;

	if (argc != 2) {
		fprintf(stderr,"%s <rig_num>\n", argv[0]);
		exit(1);
	}

	printf("testrig:hello, I am your main() !\n");

 	/*
	 * allocate memory, setup & open port
	 */

	my_rig = rig_init(atoi(argv[1]));
	if (!my_rig) {
			fprintf(stderr,"Unknown rig num: %d\n",atoi(argv[1]));
			fprintf(stderr,"Please check riglist.h\n");
			exit(1); /* whoops! something went wrong (mem alloc?) */
	}

	strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);

	if (rig_open(my_rig))
			exit(2);

	printf("Port %s opened ok\n", SERIAL_PORT);

	/*
	 * Below are examples of set/get routines.
	 * Must add checking of functionality map prior to command execution -- FS
	 *
	 */


	retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 439700000);

	if (retcode != RIG_OK ) {
	  printf("rig_set_freq: error = %s \n", rigerror(retcode));
	}

	rig_set_freq_callback(my_rig, myfreq_event, (rig_ptr_t)&count);

	retcode = rig_set_trn(my_rig, RIG_TRN_RIG);

	if (retcode != RIG_OK ) {
	  printf("rig_set_trn: error = %s \n", rigerror(retcode));
	}


	for (i=0;i<12;i++)
	  {
	    printf("Loop count: %d\n", i);
	    sleep(10);	/* or anything smarter */
	  }

	printf("Frequency changed %d times\n", count);

	rig_close(my_rig); /* close port */
	rig_cleanup(my_rig); /* if you care about memory */

	printf("port %s closed ok \n",SERIAL_PORT);

	return 0;
}
Beispiel #19
0
int main (int argc, char *argv[])
{
	ROT *my_rot;		/* handle to rot (instance) */
	rot_model_t my_model = ROT_MODEL_DUMMY;

	int retcode;		/* generic return code from functions */

	int verbose = 0;
	int show_conf = 0;
	int dump_caps_opt = 0;
	const char *rot_file=NULL;
	int serial_rate = 0;
	char conf_parms[MAXCONFLEN] = "";

	struct addrinfo hints, *result;
	int sock_listen;
	int reuseaddr = 1;

	while(1) {
		int c;
		int option_index = 0;

		c = getopt_long (argc, argv, SHORT_OPTIONS,
			long_options, &option_index);
		if (c == -1)
			break;

		switch(c) {
			case 'h':
				usage();
				exit(0);
			case 'V':
				version();
				exit(0);
			case 'm':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				my_model = atoi(optarg);
				break;
			case 'r':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				rot_file = optarg;
				break;
			case 's':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				serial_rate = atoi(optarg);
				break;
			case 'C':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				if (*conf_parms != '\0')
					strcat(conf_parms, ",");
				strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
				break;
			case 't':
				if (!optarg) {
					usage();        /* wrong arg count */
					exit(1);
				}
				portno = optarg;
				break;
			case 'T':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				src_addr = optarg;
				break;
			case 'v':
				verbose++;
				break;
			case 'L':
				show_conf++;
				break;
			case 'l':
				list_models();
				exit(0);
			case 'u':
				dump_caps_opt++;
				break;
			default:
				usage();	/* unknown option? */
				exit(1);
		}
	}

	rig_set_debug(verbose);

	rig_debug(RIG_DEBUG_VERBOSE, "rotctld, %s\n", hamlib_version);
	rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
			"<*****@*****.**>\n\n");

  	my_rot = rot_init(my_model);

	if (!my_rot) {
		fprintf(stderr, "Unknown rot num %d, or initialization error.\n",
						my_model);
		fprintf(stderr, "Please check with --list option.\n");
		exit(2);
	}

	retcode = set_conf(my_rot, conf_parms);
	if (retcode != RIG_OK) {
		fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
		exit(2);
	}

	if (rot_file)
		strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);

	/* FIXME: bound checking and port type == serial */
	if (serial_rate != 0)
		my_rot->state.rotport.parm.serial.rate = serial_rate;

	/*
	 * print out conf parameters
	 */
	if (show_conf) {
		rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
	}

	/*
	 * print out conf parameters, and exits immediately
	 * We may be interested only in only caps, and rig_open may fail.
	 */
	if (dump_caps_opt) {
		dumpcaps_rot(my_rot, stdout);
		rot_cleanup(my_rot); /* if you care about memory */
		exit(0);
	}

	retcode = rot_open(my_rot);
	if (retcode != RIG_OK) {
	  	fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode));
		exit(2);
	}

	if (verbose > 0)
		printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model,
						my_rot->caps->model_name);

	rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
			my_rot->caps->version, rig_strstatus(my_rot->caps->status));

#ifdef __MINGW32__
# ifndef SO_OPENTYPE
#  define SO_OPENTYPE     0x7008
# endif
# ifndef SO_SYNCHRONOUS_NONALERT
#  define SO_SYNCHRONOUS_NONALERT 0x20
# endif
# ifndef INVALID_SOCKET
#  define INVALID_SOCKET -1
# endif

	WSADATA wsadata;
	if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
		fprintf(stderr,"WSAStartup socket error\n");
		exit(1);
	}

	int sockopt = SO_SYNCHRONOUS_NONALERT;
	setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sockopt, sizeof(sockopt));
#endif

	/*
	 * Prepare listening socket
	 */
	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
	hints.ai_socktype = SOCK_STREAM;/* TCP socket */
	hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
	hints.ai_protocol = 0;          /* Any protocol */

	retcode = getaddrinfo(src_addr, portno, &hints, &result);
	if (retcode != 0) {
		fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
		exit(2);
	}

	sock_listen = socket(result->ai_family, result->ai_socktype,
			result->ai_protocol);
	if (sock_listen < 0)  {
		perror("ERROR opening socket");
		exit(1);
	}

	if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR,
				(char *)&reuseaddr,sizeof(reuseaddr)) < 0) {
		rig_debug(RIG_DEBUG_ERR, "setsockopt: %s\n", strerror(errno));
		exit (1);
	}
	if (bind(sock_listen, result->ai_addr, result->ai_addrlen) < 0) {
		rig_debug(RIG_DEBUG_ERR, "binding: %s\n", strerror(errno));
		exit (1);
	}

	freeaddrinfo(result);           /* No longer needed */

	if (listen(sock_listen,4) < 0) {
		rig_debug(RIG_DEBUG_ERR, "listening: %s\n", strerror(errno));
		exit (1);
	}

	/*
	 * main loop accepting connections
	 */
	do {
#ifdef HAVE_PTHREAD
		pthread_t thread;
		pthread_attr_t attr;
#endif
		struct handle_data *arg;

		arg = malloc(sizeof(struct handle_data));
		if (!arg) {
			rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
			exit (1);
		}

		arg->rot = my_rot;
		arg->clilen = sizeof(arg->cli_addr);
		arg->sock = accept(sock_listen, (struct sockaddr *) &arg->cli_addr,
				&arg->clilen);
		if (arg->sock < 0) {
			rig_debug(RIG_DEBUG_ERR, "accept: %s\n", strerror(errno));
			break;
		}

		rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%d\n",
				inet_ntoa(arg->cli_addr.sin_addr),
				ntohs(arg->cli_addr.sin_port));

#ifdef HAVE_PTHREAD
		pthread_attr_init(&attr);
		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

		retcode = pthread_create(&thread, &attr, handle_socket, arg);
		if (retcode != 0) {
			rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
			break;
		}
#else
		handle_socket(arg);
#endif
	}
	while (retcode == 0);

	rot_close(my_rot); /* close port */
	rot_cleanup(my_rot); /* if you care about memory */

#ifdef __MINGW32__
	WSACleanup();
#endif

	return 0;
}
static void *hamlib_loop(void *args)
{
	struct timespec sleep;
	gdouble freq = 0.0;
	rmode_t mode = RIG_MODE_USB;
	gint ret;
	gchar *str;

	sleep.tv_sec = 0;
	sleep.tv_nsec = 100000000L;	/* 100ms */

	for (;;) {
		nanosleep(&sleep, NULL);

//		need_freq = (hamlib_waterfall || hamlib_qsodata || hamlib_qsy);
//		need_mode = need_freq;

		/* see if we are being canceled */
		if (hamlib_exit)
			break;

		if (need_freq) {
			freq_t f;

			G_LOCK(hamlib_mutex);
			ret = rig_get_freq(rig, RIG_VFO_CURR, &f);
			G_UNLOCK(hamlib_mutex);

			if (ret != RIG_OK) {
				str = g_strdup_printf(_("rig_get_freq failed: %s"),
						      rigerror(ret));
				statusbar_set("mainstatusbar", str);
				g_free(str);
				continue;
			}

			freq = (gdouble) f;
		}

		/* see if we are being canceled */
		if (hamlib_exit)
			break;

		if (need_mode) {
			pbwidth_t width;

			G_LOCK(hamlib_mutex);
			ret = rig_get_mode(rig, RIG_VFO_CURR, &mode, &width);
			G_UNLOCK(hamlib_mutex);

			if (ret != RIG_OK) {
				str = g_strdup_printf(_("rig_get_mode failed: %s"),
						      rigerror(ret));
				statusbar_set("mainstatusbar", str);
				g_free(str);
				continue;
			}
		}

		if (hamlib_qsy) {
			gfloat f = conf_get_float("hamlib/cfreq");

			hamlib_qsy = FALSE;

			G_LOCK(hamlib_mutex);
			ret = rig_set_freq(rig, RIG_VFO_CURR, ((gdouble) freq) + trx_get_freq() - f);
			G_UNLOCK(hamlib_mutex);

			if (ret != RIG_OK) {
				str = g_strdup_printf(_("rig_set_freq failed: %s"),
						      rigerror(ret));
				statusbar_set("mainstatusbar", str);
				g_free(str);
				continue;
			}

			waterfall_set_frequency(waterfall, f);
		}

		if (hamlib_waterfall) {
			waterfall_set_carrier_frequency(waterfall, freq);

			if (mode == RIG_MODE_LSB)
				waterfall_set_lsb(waterfall, TRUE);
			else
				waterfall_set_lsb(waterfall, FALSE);
		}

		if (hamlib_qsodata) {
			gchar *str, *fmt;

			if (mode == RIG_MODE_LSB)
				freq -= trx_get_freq();
			else
				freq += trx_get_freq();

			switch (hamlib_res) {
			case 2:
				fmt = "%.6f";
				break;
			case 1:
				fmt = "%.3f";
				break;
			case 0:
			default:
				fmt = "%.0f";
				break;
			}

			str = g_strdup_printf(fmt, freq / 1000000.0);

			gdk_threads_enter();
			qsodata_set_band_mode(QSODATA_BAND_ENTRY);
			qsodata_set_freq(str);
			gdk_threads_leave();

			g_free(str);
		}

		/* see if we are being canceled */
		if (hamlib_exit)
			break;
	}

	if (hamlib_waterfall) {
		waterfall_set_carrier_frequency(waterfall, 0.0);
		waterfall_set_lsb(waterfall, FALSE);
	}

	if (hamlib_qsodata) {
		gdk_threads_enter();
		qsodata_set_band_mode(QSODATA_BAND_COMBO);
		qsodata_set_freq("");
		gdk_threads_leave();
	}

	/* this will exit the hamlib thread */
	return NULL;
}
Beispiel #21
0
void __fastcall TRigCtlMain::Timer1Timer( TObject */*Sender*/ )
{
   if ( !my_rig )
      return ;

   static in_timer = false;
   if ( in_timer )
      return ;
   in_timer = true;

   static freq_t lastFreq = 0;
   freq_t freq;
   shortfreq_t ritfreq;
   shortfreq_t xitfreq;
   static rmode_t last_mode = RIG_MODE_NONE;
   rmode_t mode;
   pbwidth_t width;

   char buff[ 1024 ];
   char fbuff[ 1024 ];

   DWORD t = GetTickCount();

   int ferr = rig_get_freq( my_rig, RIG_VFO_CURR, &freq );
   //  int rerr = rig_get_rit(my_rig, RIG_VFO_CURR, &ritfreq);
   //  int xerr = rig_get_xit(my_rig, RIG_VFO_CURR, &xitfreq);
   int merr = rig_get_mode( my_rig, RIG_VFO_CURR, &mode, &width );

   DWORD t1 = GetTickCount();

   if ( ferr != RIG_OK )
   {
      sprintf( buff, "Time %d rig_getFreq: error = %s", ( int ) ( t1 - t ), rigerror( ferr ) );
      Label2->Caption = buff;
   }
   else
   {
      freq += rigTransConversion;

      sprintf( fbuff, "%lld", ( long long ) freq );
      sprintf( buff, "rig_get_op_params Time %d Freq %s", ( int ) ( t1 - t ), fbuff );
      Label2->Caption = buff;
   }
   // and publish the value...

   if ( freq != lastFreq )
   {
      RPCPubSub::publish( "RigControl", "Frequency", fbuff, psPublished );

      lastFreq = freq;
   }

   if ( merr != RIG_OK )
   {
      sprintf( buff, "Time %d rig_get_mode: error = %s", ( int ) ( t1 - t ), rigerror( ferr ) );
      Label2->Caption = buff;
   }
   else
   {
      if ( mode != last_mode )
      {
         std::string strMode;
         switch ( mode )
         {
            case RIG_MODE_AM:
               strMode = "A3E";
               break;

            case RIG_MODE_CW:
               strMode = "A1A";
               break;

            case RIG_MODE_USB:
               strMode = "J3E";
               break;

            case RIG_MODE_LSB:
               strMode = "J3E";
               break;

            case RIG_MODE_RTTY:
               strMode = "RTTY";
               break;

            case RIG_MODE_FM:
               strMode = "F3E";
               break;

            case RIG_MODE_WFM:
               strMode = "F3E";
               break;

            case RIG_MODE_CWR:
               strMode = "A1A";
               break;

            case RIG_MODE_RTTYR:
               strMode = "RTTY";
               break;

            case RIG_MODE_AMS:
               strMode = "AMS";
               break;

            case RIG_MODE_PKTLSB:
               strMode = "PKT";
               break;

            case RIG_MODE_PKTUSB:
               strMode = "PKT";
               break;

            case RIG_MODE_PKTFM:
               strMode = "PKT";
               break;

            case RIG_MODE_ECSSUSB:
               strMode = "A3E";
               break;

            case RIG_MODE_ECSSLSB:
               strMode = "J3E";
               break;

            case RIG_MODE_FAX:
               strMode = "FAX";
               break;

            case RIG_MODE_NONE:
            default:
               strMode = "UNK";
               break;

         }
         switch ( mode )
         {
            case RIG_MODE_AM:
               ModeRadioGroup->ItemIndex = 0;
               break;

            case RIG_MODE_CW:
               ModeRadioGroup->ItemIndex = 1;
               break;

            case RIG_MODE_USB:
               ModeRadioGroup->ItemIndex = 2;
               break;

            case RIG_MODE_LSB:
               ModeRadioGroup->ItemIndex = 2;
               break;

            case RIG_MODE_RTTY:
               ModeRadioGroup->ItemIndex = 0;
               break;

            case RIG_MODE_FM:
               ModeRadioGroup->ItemIndex = 0;
               break;

            case RIG_MODE_WFM:
               ModeRadioGroup->ItemIndex = 0;
               break;

            case RIG_MODE_CWR:
               ModeRadioGroup->ItemIndex = 1;
               break;

            case RIG_MODE_RTTYR:
               ModeRadioGroup->ItemIndex = 0;
               break;

            case RIG_MODE_AMS:
               ModeRadioGroup->ItemIndex = 0;
               break;

            case RIG_MODE_PKTLSB:
               ModeRadioGroup->ItemIndex = 2;
               break;

            case RIG_MODE_PKTUSB:
               ModeRadioGroup->ItemIndex = 2;
               break;

            case RIG_MODE_PKTFM:
               ModeRadioGroup->ItemIndex = 0;
               break;

            case RIG_MODE_ECSSUSB:
               ModeRadioGroup->ItemIndex = 2;
               break;

            case RIG_MODE_ECSSLSB:
               ModeRadioGroup->ItemIndex = 2;
               break;

            case RIG_MODE_FAX:
               ModeRadioGroup->ItemIndex = 0;
               break;

            case RIG_MODE_NONE:
            default:
               ModeRadioGroup->ItemIndex = 0;
               break;

         }
         last_mode = mode;

         RPCPubSub::publish( "RigControl", "Mode", strMode, psPublished );
      }
   }

   in_timer = false;
}
void hamlib_init(void)
{
	rig_model_t model;
	struct timespec sleep;
	freq_t freq;
	rmode_t mode;
	pbwidth_t width;
	gboolean enable;
	gchar *port, *conf, *spd;
	gint ret, speed;

	if (rig != NULL)
		return;

	enable = conf_get_bool("hamlib/enable");
	model = conf_get_int("hamlib/rig");
	port = conf_get_filename("hamlib/port");
	speed = conf_get_int("hamlib/speed");
	conf = conf_get_string("hamlib/conf");

	if (!enable || !model || port[0] == 0)
		return;

	rig_set_debug(RIG_DEBUG_ERR);

	rig = rig_init(model);

	if (rig == NULL) {
		errmsg(_("Hamlib init: rig_init failed (model=%d)"), model);
		return;
	}

	g_strstrip(conf);
	if (conf[0]) {
		gchar **v, **p, *q;

		v = g_strsplit(conf, ",", 0);

		for (p = v; *p; p++) {
			if ((q = strchr(*p, '=')) == NULL) {
				errmsg(_("Hamlib init: Bad param=value pair: '%s'"), *p);
				break;
			}
			*q++ = 0;

			g_strstrip(*p);
			g_strstrip(q);

			if (hamlib_set_param(*p, q) == FALSE)
				break;
		}

		g_strfreev(v);
	}
	g_free(conf);

	hamlib_set_param("rig_pathname", port);
	g_free(port);

	spd = g_strdup_printf("%d", speed);
	hamlib_set_param("serial_speed", spd);
	g_free(spd);

	ret = rig_open(rig);

	if (ret != RIG_OK) {
		errmsg(_("Hamlib init: rig_open failed: %s"), rigerror(ret));
		rig_cleanup(rig);
		rig = NULL;
		return;
	}

	/* Polling the rig sometimes fails right after opening it */
	sleep.tv_sec = 0;
	sleep.tv_nsec = 100000000L;	/* 100ms */
	nanosleep(&sleep, NULL);

	if (need_freq == TRUE && \
	    (ret = rig_get_freq(rig, RIG_VFO_CURR, &freq)) != RIG_OK) {
		errmsg(_("Hamlib init: rig_get_freq failed: %s"), rigerror(ret));

		hamlib_waterfall = FALSE;
		hamlib_qsodata = FALSE;

		need_freq = FALSE;
		need_mode = FALSE;
	}

	if (need_mode == TRUE &&
	    (ret = rig_get_mode(rig, RIG_VFO_CURR, &mode, &width)) != RIG_OK) {
		errmsg(_("Hamlib init: rig_get_mode failed: %s.\nAssuming USB mode."), rigerror(ret));

		need_mode = FALSE;
	}

	if (hamlib_ptt == TRUE && 
	    (ret = rig_set_ptt(rig, RIG_VFO_CURR, RIG_PTT_OFF)) != RIG_OK) {
		errmsg(_("Hamlib init: rig_set_ptt failed: %s.\nHamlib PTT disabled"), rigerror(ret));

		hamlib_ptt = FALSE;
	}

	/* Don't create the thread if frequency data is not needed */
	if (need_freq == FALSE) {
//		g_warning("Freq data not needed, thread not started.");
		/* If PTT isn't needed either then close everything */
		if (hamlib_ptt == FALSE) {
//			g_warning("PTT not needed, closing rig.");
			rig_close(rig);
			rig_cleanup(rig);
			rig = NULL;
		}
		return;
	}

	if (pthread_create(&hamlib_thread, NULL, hamlib_loop, NULL) < 0) {
		errmsg(_("Hamlib init: pthread_create: %m"));
		rig_close(rig);
		rig_cleanup(rig);
		rig = NULL;
	}
}
Beispiel #23
0
int main(int argc, char *argv[])
{
    RIG *my_rig;        /* handle to rig (nstance) */
    freq_t freq;        /* frequency  */
    rmode_t rmode;      /* radio mode of operation */
    pbwidth_t width;
    vfo_t vfo;          /* vfo selection */
    int strength;       /* S-Meter level */
    int rit = 0;        /* RIT status */
    int xit = 0;        /* XIT status */
    int retcode;        /* generic return code from functions */

    rig_model_t myrig_model;


    printf("testrig: Hello, I am your main() !\n");

    /* Turn off backend debugging ouput */
    rig_set_debug_level(RIG_DEBUG_NONE);

    /*
     * allocate memory, setup & open port
     */

    if (argc < 2)
    {
        hamlib_port_t myport;
        /* may be overriden by backend probe */
        myport.type.rig = RIG_PORT_SERIAL;
        myport.parm.serial.rate = 9600;
        myport.parm.serial.data_bits = 8;
        myport.parm.serial.stop_bits = 1;
        myport.parm.serial.parity = RIG_PARITY_NONE;
        myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
        strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1);

        rig_load_all_backends();
        myrig_model = rig_probe(&myport);
    }
    else
    {
        myrig_model = atoi(argv[1]);
    }

    my_rig = rig_init(myrig_model);

    if (!my_rig)
    {
        fprintf(stderr, "Unknown rig num: %d\n", myrig_model);
        fprintf(stderr, "Please check riglist.h\n");
        exit(1); /* whoops! something went wrong (mem alloc?) */
    }

    strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1);

    retcode = rig_open(my_rig);

    if (retcode != RIG_OK)
    {
        printf("rig_open: error = %s\n", rigerror(retcode));
        exit(2);
    }

    printf("Port %s opened ok\n", SERIAL_PORT);

    /*
     * Below are examples of set/get routines.
     * Must add checking of functionality map prior to command execution -- FS
     *
     */

    /*
     * Example of setting rig paameters
     * and some error checking on the return code.
     */

    retcode = rig_set_vfo(my_rig, RIG_VFO_B);


    if (retcode != RIG_OK)
    {
        printf("rig_set_vfo: error = %s \n", rigerror(retcode));
    }


    /*
     * Lets try some frequencies and modes. Return code is not checked.
     * Examples of checking return code are further down.
     *
     */

    /* 10m FM Narrow */

    printf("\nSetting 10m FM Narrow...\n");

    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 29620000); /* 10m */
    retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
                           rig_passband_narrow(my_rig, RIG_MODE_FM));

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);

    printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
           freq / 1000000,
           rig_strrmode(rmode),
           width / 1000.0);

    sleep(1);       /* so you can see it -- FS */

    /* 15m USB */

    printf("Setting 15m USB...\n");

    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 21235175); /* 15m  */
    retcode = rig_set_mode(my_rig,
                           RIG_VFO_CURR,
                           RIG_MODE_USB,
                           rig_passband_normal(my_rig, RIG_MODE_USB));

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);

    printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
           freq / 1000000, rig_strrmode(rmode), width / 1000.0);
    sleep(1);

    /* 40m LSB */

    printf("Setting 40m LSB...\n");

    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 7250100); /* 40m  */
    retcode = rig_set_mode(my_rig,
                           RIG_VFO_CURR,
                           RIG_MODE_LSB,
                           RIG_PASSBAND_NORMAL);

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);

    printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
           freq / 1000000,
           rig_strrmode(rmode),
           width / 1000.0);
    sleep(1);

    /* 80m AM Narrow */

    printf("Setting 80m AM Narrow...\n");

    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3885000); /* 80m  */
    retcode = rig_set_mode(my_rig,
                           RIG_VFO_CURR,
                           RIG_MODE_AM,
                           rig_passband_narrow(my_rig, RIG_MODE_AM));

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);

    printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n",
           freq / 1000000,
           rig_strrmode(rmode),
           width / 1000.0);

    sleep(1);

    /* 160m CW Normal */

    printf("Setting 160m CW...\n");

    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 1875000); /* 160m  */
    retcode = rig_set_mode(my_rig,
                           RIG_VFO_CURR,
                           RIG_MODE_CW,
                           RIG_PASSBAND_NORMAL);

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);

    printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
           freq / 1000,
           rig_strrmode(rmode),
           width);

    sleep(1);

    /* 160m CW Narrow -- The band is noisy tonight -- FS*/

    printf("Setting 160m CW Narrow...\n");

    retcode = rig_set_mode(my_rig,
                           RIG_VFO_CURR,
                           RIG_MODE_CW,
                           rig_passband_narrow(my_rig, RIG_MODE_CW));

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);

    printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n",
           freq / 1000,
           rig_strrmode(rmode),
           width);

    sleep(1);

    /* AM Broadcast band */

    printf("Setting Medium Wave AM...\n");

    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 770000); /* KAAM */
    retcode = rig_set_mode(my_rig,
                           RIG_VFO_CURR,
                           RIG_MODE_AM,
                           RIG_PASSBAND_NORMAL);

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);

    printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n",
           freq / 1000,
           rig_strrmode(rmode),
           width / 1000.0);

    sleep(1);

    /* 20m USB on VFO_A */

    printf("Setting 20m on VFO A with two functions...\n");

    retcode = rig_set_vfo(my_rig, RIG_VFO_A);
    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_vfo(my_rig, &vfo);

    printf(" Freq: %.6f MHz, VFO: %s\n\n", freq / 1000000, rig_strvfo(vfo));

    sleep(1);

    /* 20m USB on VFO_A , with only 1 call */

    printf("Setting  20m on VFO A with one function...\n");
    retcode = rig_set_freq(my_rig, RIG_VFO_A, 14295125); /* cq de vk3fcs */

    if (retcode != RIG_OK)
    {
        printf("rig_set_freq: error = %s \n", rigerror(retcode));
    }

    rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    rig_get_vfo(my_rig, &vfo);

    printf(" Freq: %.6f MHz, VFO: %s\n\n", freq / 1000000, rig_strvfo(vfo));

    sleep(1);


#if 0
    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 145100000); /* 2m  */
    sleep(2);
    retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 435125000); /* 70cm  */
    sleep(2);
#endif

    printf("Setting rig Mode to LSB.\n");
    retcode = rig_set_mode(my_rig,
                           RIG_VFO_CURR,
                           RIG_MODE_LSB,
                           RIG_PASSBAND_NORMAL);

    if (retcode != RIG_OK)
    {
        printf("rig_set_mode: error = %s \n", rigerror(retcode));
    }

    sleep(1);

    printf("Setting rig PTT ON.\n");
    retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON);  /* stand back ! */

    if (retcode != RIG_OK)
    {
        printf("rig_set_ptt: error = %s \n", rigerror(retcode));
    }

    sleep(1);

    printf("Setting rig PTT OFF.\n");
    retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_OFF);  /* phew ! */

    if (retcode != RIG_OK)
    {
        printf("rig_set_ptt: error = %s \n", rigerror(retcode));
    }

    sleep(1);

    /*
     * Simple examples of getting rig information -- FS
     *
     */

    printf("\nGet various raw rig values:\n");
    retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */

    if (retcode == RIG_OK)
    {
        printf("rig_get_vfo: vfo = %i \n", vfo);
    }
    else
    {
        printf("rig_get_vfo: error =  %s \n", rigerror(retcode));
    }

    retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);

    if (retcode == RIG_OK)
    {
        printf("rig_get_freq: freq = %"PRIfreq"\n", freq);
    }
    else
    {
        printf("rig_get_freq: error =  %s \n", rigerror(retcode));
    }

    retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);

    if (retcode == RIG_OK)
    {
        printf("rig_get_mode: mode = %"PRIll"\n", rmode);
    }
    else
    {
        printf("rig_get_mode: error =  %s \n", rigerror(retcode));
    }

    retcode = rig_get_strength(my_rig, RIG_VFO_CURR, &strength);

    if (retcode == RIG_OK)
    {
        printf("rig_get_strength: strength = %i \n", strength);
    }
    else
    {
        printf("rig_get_strength: error =  %s \n", rigerror(retcode));
    }

    if (rig_has_set_func(my_rig, RIG_FUNC_RIT))
    {
        retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1);
        printf("rig_set_func: Setting RIT ON\n");
    }

    if (rig_has_get_func(my_rig, RIG_FUNC_RIT))
    {
        retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, &rit);
        printf("rig_get_func: RIT: %d\n", rit);
    }

    if (rig_has_set_func(my_rig, RIG_FUNC_XIT))
    {
        retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, 1);
        printf("rig_set_func: Setting XIT ON\n");
    }

    if (rig_has_get_func(my_rig, RIG_FUNC_XIT))
    {
        retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &xit);
        printf("rig_get_func: XIT: %d\n", xit);
    }

    rig_close(my_rig); /* close port */
    rig_cleanup(my_rig); /* if you care about memory */

    printf("port %s closed ok \n", SERIAL_PORT);

    return 0;
}
Beispiel #24
0
int main (int argc, char *argv[])
{
	ROT *my_rot;		/* handle to rot (instance) */
	rot_model_t my_model = ROT_MODEL_DUMMY;

	int retcode;		/* generic return code from functions */
	int exitcode;

	int verbose = 0;
	int show_conf = 0;
	int dump_caps_opt = 0;
#ifdef HAVE_READLINE_HISTORY
	int rd_hist = 0;
	int sv_hist = 0;
	const char *hist_dir = NULL;
	const char hist_file[] = "/.rotctl_history";
	char *hist_path = NULL;
	struct stat hist_dir_stat;
#endif
	const char *rot_file=NULL;
	int serial_rate = 0;
	char conf_parms[MAXCONFLEN] = "";

	while(1) {
		int c;
		int option_index = 0;

		c = getopt_long (argc, argv, SHORT_OPTIONS HST_SHRT_OPTS,
			long_options, &option_index);
		if (c == -1)
			break;

		switch(c) {
			case 'h':
				usage();
				exit(0);
			case 'V':
				version();
				exit(0);
			case 'm':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				my_model = atoi(optarg);
				break;
			case 'r':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				rot_file = optarg;
				break;
			case 's':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				serial_rate = atoi(optarg);
				break;
			case 'C':
				if (!optarg) {
					usage();	/* wrong arg count */
					exit(1);
				}
				if (*conf_parms != '\0')
					strcat(conf_parms, ",");
				strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
				break;
			case 't':
				if (!optarg) {
					usage();        /* wrong arg count */
					exit(1);
				}
				if (strlen(optarg) > 1)
					send_cmd_term = strtol(optarg, NULL, 0);
				else
					send_cmd_term = optarg[0];
				break;
#ifdef HAVE_READLINE_HISTORY
			case 'i':
				rd_hist++;
				break;
			case 'I':
				sv_hist++;
				break;
#endif
			case 'v':
				verbose++;
				break;
			case 'L':
				show_conf++;
				break;
			case 'l':
				rig_set_debug(0);
				list_models();
				exit(0);
			case 'u':
				dump_caps_opt++;
				break;
			default:
				usage();	/* unknown option? */
				exit(1);
		}
	}

	rig_set_debug(verbose);

	rig_debug(RIG_DEBUG_VERBOSE, "rotctl, %s\n", hamlib_version);
	rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
			"<*****@*****.**>\n\n");

	/*
	 * at least one command on command line,
	 * disable interactive mode
	 */
	if (optind < argc)
		interactive = 0;

  	my_rot = rot_init(my_model);

	if (!my_rot) {
		fprintf(stderr, "Unknown rot num %d, or initialization error.\n",
						my_model);
		fprintf(stderr, "Please check with --list option.\n");
		exit(2);
	}

	retcode = set_conf(my_rot, conf_parms);
	if (retcode != RIG_OK) {
		fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
		exit(2);
	}

	if (rot_file)
		strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);

	/* FIXME: bound checking and port type == serial */
	if (serial_rate != 0)
		my_rot->state.rotport.parm.serial.rate = serial_rate;

	/*
	 * print out conf parameters
	 */
	if (show_conf) {
		rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
	}

    /*
     * print out capabilities, and exists immediately
     * We may be interested only in caps, and rig_open may fail.
     */
    if (dump_caps_opt) {
        dumpcaps_rot(my_rot, stdout);
        rot_cleanup(my_rot); /* if you care about memory */
        exit(0);
    }

	retcode = rot_open(my_rot);
	if (retcode != RIG_OK) {
	  	fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode));
		exit(2);
	}

	if (verbose > 0)
		printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model,
						my_rot->caps->model_name);

	rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
			my_rot->caps->version, rig_strstatus(my_rot->caps->status));

	exitcode = 0;

#ifdef HAVE_LIBREADLINE
	if (interactive && prompt && have_rl) {
		rl_readline_name = "rotctl";
#ifdef HAVE_READLINE_HISTORY
		using_history();	/* Initialize Readline History */

		if (rd_hist || sv_hist) {
			if (!(hist_dir = getenv("ROTCTL_HIST_DIR")))
				hist_dir = getenv("HOME");

			if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
				|| !(S_ISDIR(hist_dir_stat.st_mode))) {
				fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
			}

			hist_path = (char *)calloc((sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1)), sizeof(char));

			strncpy(hist_path, hist_dir, strlen(hist_dir));
			strncat(hist_path, hist_file, strlen(hist_file));
		}

		if (rd_hist && hist_path)
			if (read_history(hist_path) == ENOENT)
				fprintf(stderr, "Warning: Could not read history from %s\n", hist_path);
#endif
	}
#endif	/* HAVE_LIBREADLINE */

	do {
		retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc);
		if (retcode == 2)
			exitcode = 2;
	}
	while (retcode == 0 || retcode == 2);

#ifdef HAVE_LIBREADLINE
	if (interactive && prompt && have_rl) {
#ifdef HAVE_READLINE_HISTORY
		if (sv_hist && hist_path)
			if (write_history(hist_path) == ENOENT)
				fprintf(stderr, "\nWarning: Could not write history to %s\n", hist_path);

		if ((rd_hist || sv_hist) && hist_path) {
			free(hist_path);
			hist_path = (char *)NULL;
		}
	}
#endif
#endif
	rot_close(my_rot); /* close port */
	rot_cleanup(my_rot); /* if you care about memory */

	return exitcode;
}