Beispiel #1
0
/* Send data from SVC to switch */
inline int i2c_switch_send_msg(uint8_t *buf, unsigned int size)
{
    int ret;

    dbg_verbose("%s()\n", __func__);
    dbg_print_buf(DBG_VERBOSE, buf, size);

    i2c_select_device(I2C_ADDR_SWITCH);

    ret = I2C_WRITE(sw_exp_dev, buf, size);
    if (ret) {
        dbg_error("%s(): Error %d\n", __func__, ret);
        return ERROR;
    }

    return 0;
}
Beispiel #2
0
/* Write data to the IO Expander */
int i2c_ioexp_write(uint8_t *msg, int size, uint8_t addr)
{
    int ret;

    i2c_select_device(addr);

    ret = I2C_WRITE(sw_exp_dev, msg, size);
    if (ret) {
        dbg_error("%s(): Error %d\n", __func__, ret);
        return ERROR;
    }

    dbg_verbose("%s()\n", __func__);
    dbg_print_buf(DBG_VERBOSE, msg, size);

    return ret;
}
Beispiel #3
0
/* Read data from the IO Expander */
int i2c_ioexp_read(uint8_t *msg, int size, uint8_t addr)
{
    int ret;

    dbg_verbose("%s()\n", __func__);
    dbg_print_buf(DBG_VERBOSE, msg, size);

    i2c_select_device(addr);

    /* We need 2 messages (cf. datasheet) */
    struct i2c_msg_s msgv[2] = {
        /* Write the command byte, no restart */
        {
            .addr   = addr,
            .flags  = 0,
            .buffer = msg,
            .length = 1
        },
        /* Read the bytes */
        {
            .addr   = addr,
Beispiel #4
0
Datei: epmd_srv.c Projekt: RJ/otp
static void do_read(EpmdVars *g,Connection *s)
{
  int val, pack_size;

  if (s->open == EPMD_FALSE)
    {
      dbg_printf(g,0,"read on unknown socket");
      return;
    }

  /* Check if we already got the whole packet but we keep the
     connection alive to find out when a node is terminated. We then
     want to check for a close */

  if (s->keep == EPMD_TRUE)
    {
      val = read(s->fd, s->buf, INBUF_SIZE);

      if (val == 0)
	{
	  node_unreg_sock(g,s->fd);
	  epmd_conn_close(g,s);
	}
      else if (val < 0)
	{
	    dbg_tty_printf(g,1,"error on ALIVE socket %d (%d; errno=0x%x)",
			   s->fd, val, errno);
	  node_unreg_sock(g,s->fd);
	  epmd_conn_close(g,s);
	}
      else
	{
	  dbg_tty_printf(g,1,"got more than expected on ALIVE socket %d (%d)",
		 s->fd,val);
	  dbg_print_buf(g,s->buf,val);

	  node_unreg_sock(g,s->fd);
	  epmd_conn_close(g,s);
	}
      return;
    }

  /* If unknown size we request the whole buffer - what we got - 1
     We subtract 1 because we will add a "\0" in "do_request()".
     This is not needed for R3A or higher versions of Erlang,
     because the '\0' is included in the request,
     but is kept for backwards compatibility to allow R2D to use
     this epmd. */

  pack_size = s->want ? s->want : INBUF_SIZE - 1;
  val = read(s->fd, s->buf + s->got, pack_size - s->got);

  if (val == 0)
    {
      /* A close when we haven't got all data */
      dbg_printf(g,0,"got partial packet only on file descriptor %d (%d)",
		 s->fd,s->got);
      epmd_conn_close(g,s);
      return;
    }

  if (val < 0)
    {
      dbg_perror(g,"error in read");
      epmd_conn_close(g,s);
      return;
    }

  dbg_print_buf(g,s->buf,val);

  s->got += val;

  if ((s->want == 0) && (s->got >= 2))
    {
      /* The two byte header that specify the length of the packet
	 doesn't count the header as part of the packet so we add 2
	 to "s->want" to make us talk about all bytes we get. */

      s->want = get_int16(s->buf) + 2;

      if ((s->want < 3) || (s->want >= INBUF_SIZE))
	{
	  dbg_printf(g,0,"invalid packet size (%d)",s->want - 2);
	  epmd_conn_close(g,s);
	  return;
	}

      if (s->got > s->want)
	{
	  dbg_printf(g,0,"got %d bytes in packet, expected %d",
		     s->got - 2, s->want - 2);
	  epmd_conn_close(g,s);
	  return;
	}
    }
  
  s->mod_time = current_time(g); /* Note activity */
  
  if (s->want == s->got)
    {
      /* Do action and close up */
      /* Skip header bytes */

      do_request(g, s->fd, s, s->buf + 2, s->got - 2);

      if (!s->keep)
	epmd_conn_close(g,s);		/* Normal close */
    }
}