Exemple #1
0
void upsdrv_initups(void)
{
	char	*version;

	version = getval("protocol");
	upsfd = ser_open(device_path);

	ser_set_rts(upsfd, 0);

	/*
	 * Try to autodetect which UPS is connected.
	 */
	for (mode = 0; subdriver[mode] != NULL; mode++) {

		if ((version != NULL) && strcasecmp(version, subdriver[mode]->version)) {
			continue;
		}

		ser_set_dtr(upsfd, 1);
		usleep(10000);

		if (subdriver[mode]->initups() > 0) {
			upslogx(LOG_INFO, "CyberPower UPS with %s protocol on %s detected", subdriver[mode]->version, device_path);
			return;
		}

		ser_set_dtr(upsfd, 0);
		usleep(10000);
	}

	fatalx(EXIT_FAILURE, "CyberPower UPS not found on %s", device_path);
}
Exemple #2
0
void upsdrv_initups(void)
{
	upsfd = ser_open(device_path);
	ser_set_speed(upsfd, device_path, B19200);

	/* dtr and rts setting */
	ser_set_dtr(upsfd, 1);
	ser_set_rts(upsfd, 0);
	
}
Exemple #3
0
static int optoscan_RTS_toggle(RIG *rig)
{
	struct rig_state *rs;
	int state = 0;

	rs = &rig->state;
	ser_get_rts(&rs->rigport, &state);
	ser_set_rts(&rs->rigport, !state);

	return RIG_OK;
}
Exemple #4
0
void upsdrv_initups(void)
{
	upsfd = ser_open(device_path);

	/* Speed should not matter (see comments in upsdrv_updateinfo),
	 * but set it relatively low in case there are problems with higher
	 * speeds. */
	ser_set_speed(upsfd, device_path, B9600);

	/* raise RTS */
	ser_set_rts(upsfd, 1);
}
Exemple #5
0
int upsdrv_initups(void)
{
	struct termios	tio;
	const char	*val;

	upsfd = ser_open(device_path);
	ser_set_speed(upsfd, device_path, B1200);

	if (tcgetattr(upsfd, &tio)) {
		fatal_with_errno(EXIT_FAILURE, "tcgetattr");
	}

	/*
	 * Use canonical mode input processing (to read reply line)
	 */
	tio.c_lflag |= ICANON;	/* Canonical input (erase and kill processing) */
	tio.c_iflag |= IGNCR;	/* Ignore CR */
	tio.c_iflag |= IGNBRK;	/* Ignore break condition */
	tio.c_oflag |= ONLCR;	/* Map NL to CR-NL on output */

	tio.c_cc[VEOF] = _POSIX_VDISABLE;
	tio.c_cc[VEOL] = _POSIX_VDISABLE;
	tio.c_cc[VERASE] = _POSIX_VDISABLE;
	tio.c_cc[VINTR]  = _POSIX_VDISABLE;
	tio.c_cc[VKILL]  = _POSIX_VDISABLE;
	tio.c_cc[VQUIT]  = _POSIX_VDISABLE;
	tio.c_cc[VSUSP]  = _POSIX_VDISABLE;
	tio.c_cc[VSTART] = _POSIX_VDISABLE;
	tio.c_cc[VSTOP]  = _POSIX_VDISABLE;

	if (tcsetattr(upsfd, TCSANOW, &tio)) {
		fatal_with_errno(EXIT_FAILURE, "tcsetattr");
	}

	/*
	 * Set DTR and clear RTS to provide power for the serial interface.
	 */
	ser_set_dtr(upsfd, 1);
	ser_set_rts(upsfd, 0);

	val = dstate_getinfo("battery.voltage.nominal");
	battery.voltage.nom = (val) ? strtod(val, NULL) : 12.00;

	val = dstate_getinfo("battery.voltage.low");
	battery.voltage.low = (val) ? strtod(val, NULL) : 10.80;

	if (battery.voltage.nom <= battery.voltage.low) {
		fatalx(EXIT_FAILURE, "Nominal battery voltage must be higher than low battery voltage!");
	}

	return 1;
}
Exemple #6
0
void upsdrv_initups(void)
{
#ifndef TESTING
	const struct {
		const char	*val;
		const int	dtr;
		const int	rts;
	} cablepower[] = {
		{ "normal",	1, 0 }, /* default */
		{ "reverse",	0, 1 },
		{ "both",	1, 1 },
		{ "none",	0, 0 },
		{ NULL }
	};

	int	i;

	const char	*val;

	struct termios		tio;

	/*
	 * Open and lock the serial port and set the speed to 2400 baud.
	 */
	upsfd = ser_open(device_path);
	ser_set_speed(upsfd, device_path, B2400);

	if (tcgetattr(upsfd, &tio)) {
		fatal_with_errno(EXIT_FAILURE, "tcgetattr");
	}

	/*
	 * Use canonical mode input processing (to read reply line)
	 */
	tio.c_lflag |= ICANON;	/* Canonical input (erase and kill processing) */

	tio.c_cc[VEOF]   = _POSIX_VDISABLE;
	tio.c_cc[VEOL]   = '\r';
	tio.c_cc[VERASE] = _POSIX_VDISABLE;
	tio.c_cc[VINTR]  = _POSIX_VDISABLE;
	tio.c_cc[VKILL]  = _POSIX_VDISABLE;
	tio.c_cc[VQUIT]  = _POSIX_VDISABLE;
	tio.c_cc[VSUSP]  = _POSIX_VDISABLE;
	tio.c_cc[VSTART] = _POSIX_VDISABLE;
	tio.c_cc[VSTOP]  = _POSIX_VDISABLE;

	if (tcsetattr(upsfd, TCSANOW, &tio)) {
		fatal_with_errno(EXIT_FAILURE, "tcsetattr");
	}

	val = getval("cablepower");
	for (i = 0; val && cablepower[i].val; i++) {

		if (!strcasecmp(val, cablepower[i].val)) {
			break;
		}
	}

	if (!cablepower[i].val) {
		fatalx(EXIT_FAILURE, "Value '%s' not valid for 'cablepower'", val);
	}

	ser_set_dtr(upsfd, cablepower[i].dtr);
	ser_set_rts(upsfd, cablepower[i].rts);

	/*
	 * Allow some time to settle for the cablepower
	 */
	usleep(100000);
#endif
	blazer_initups();
}
Exemple #7
0
/* set DTR and RTS lines on a serial port to supply a passive
 * serial interface: DTR to 0 (-V), RTS to 1 (+V)
 */
static void dtr0rts1 (void)
{
	ser_set_dtr(upsfd, 0); 
	ser_set_rts(upsfd, 1); 
	upsdebugx(2, "DTR => 0, RTS => 1");
}
Exemple #8
0
int thd72_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg)
{
  int i, j, ret;
  hamlib_port_t *rp = &rig->state.rigport;
  channel_t *chan;
  chan_t *chan_list = rig->state.chan_list;
  int chan_next = chan_list[0].start;
  char block[BLOCK_SZ];
  char resp[CMD_SZ];

  ret = kenwood_transaction(rig, "0M PROGRAM", resp, CMD_SZ);

  if (ret != RIG_OK)
  {
    return ret;
  }

  if (strlen(resp) != 2 || memcmp(resp, "0M", 2))
  {
    return -RIG_EPROTO;
  }

  rp->parm.serial.rate = 57600;
  serial_setup(rp);


  usleep(100 * 1000); /* let the pcr settle */
  serial_flush(rp); /* flush any remaining data */
  ret = ser_set_rts(rp, 1); /* setRTS or Hardware flow control? */

  if (ret != RIG_OK)
  {
    return ret;
  }

  /*
   * setting chan to NULL means the application
   * has to provide a struct where to store data
   * future data for channel channel_num
   */
  chan = NULL;
  ret = chan_cb(rig, &chan, chan_next, chan_list, arg);

  if (ret != RIG_OK)
  {
    return ret;
  }

  if (chan == NULL)
  {
    return -RIG_ENOMEM;
  }

  for (i = 0; i < BLOCK_COUNT; i++)
  {

    ret = thd72_get_block(rig, i, block);

    if (ret != RIG_OK)
    {
      return ret;
    }

    /*
     * Most probably, there's 64 bytes per channel (256*256 / 1000+)
     */
    for (j = 0; j < CHAN_PER_BLOCK; j++)
    {
      char *block_chan = block + j * (BLOCK_SZ / CHAN_PER_BLOCK);
      memset(chan, 0, sizeof(channel_t));
      chan->vfo = RIG_VFO_MEM;
      chan->channel_num = i * CHAN_PER_BLOCK + j;

      /* What are the extra 64 channels ? */
      if (chan->channel_num >= 1000)
      {
        break;
      }

      /* non-empty channel ? */
      // if (block_chan[0] != 0xff) {
      // since block_chan is *signed* char, this maps to -1
      if (block_chan[0] != -1)
      {

        memcpy(chan->channel_desc, block_chan, 8);
        /* TODO: chop off trailing chars */
        chan->channel_desc[8] = '\0';

        /* TODO: parse block and fill in chan */
      }

      /* notify the end? */
      chan_next = chan_next < chan_list[i].end ? chan_next + 1 : chan_next;

      /*
       * provide application with channel data,
       * and ask for a new channel structure
       */
      chan_cb(rig, &chan, chan_next, chan_list, arg);
    }
  }

  ret = write_block(rp, "E", 1);

  if (ret != RIG_OK)
  {
    return ret;
  }

  ret = read_block(rp, resp, 1);

  if (ret != 1)
  {
    return ret;
  }

  if (resp[0] != 0x06)
  {
    return -RIG_EPROTO;
  }

  /* setRTS?? getCTS needed? */
  ret = ser_set_rts(rp, 1);

  if (ret != RIG_OK)
  {
    return ret;
  }

  return RIG_OK;
}