Example #1
0
// SLIP parse a single character
static void ICACHE_FLASH_ATTR
slip_parse_char(char c) {
  if (c == SLIP_END) {
    // either start or end of packet, process whatever we may have accumulated
    DBG("SLIP: start or end len=%d inpkt=%d\n", slip_len, slip_inpkt);
    if (slip_len > 0) {
      if (slip_len > 2 && slip_inpkt) slip_process();
      else console_process(slip_buf, slip_len);
    }
    slip_reset();
  } else if (slip_escaped) {
    // prev char was SLIP_ESC
    if (c == SLIP_ESC_END) c = SLIP_END;
    if (c == SLIP_ESC_ESC) c = SLIP_ESC;
    if (slip_len < SLIP_MAX) slip_buf[slip_len++] = c;
    slip_escaped = false;
  } else if (slip_inpkt && c == SLIP_ESC) {
    slip_escaped = true;
  } else {
    if (slip_len == 1 && slip_printable(slip_buf[0]) && slip_printable(c)) {
      // start of packet and it's a printable character, we're gonna assume that this is console text
      slip_inpkt = false;
    }
    if (slip_len < SLIP_MAX) slip_buf[slip_len++] = c;
  }
}
Example #2
0
// SLIP parse a single character
static void ICACHE_FLASH_ATTR
slip_parse_char(char c) {
  if (!slip_inpkt) {
    if (c == SLIP_START) {
      if (slip_len > 0) console_process(slip_buf, slip_len);
      slip_reset();
      slip_inpkt = true;
      DBG("SLIP: start\n");
      return;
    }
  } else if (slip_escaped) {
    // prev char was SLIP_REPL
    c = SLIP_ESC(c);
    slip_escaped = false;
  } else {
    switch (c) {
    case SLIP_REPL:
      slip_escaped = true;
      return;
    case SLIP_END:
      // end of packet, process it and get ready for next one
      if (slip_len > 0) slip_process();
      slip_reset();
      return;
    case SLIP_START:
      os_printf("SLIP: got SLIP_START while in packet?\n");
      //os_printf("SLIP: rcv %d:", slip_len);
      //for (int i=0; i<slip_len; i++) os_printf(" %02x", slip_buf[i]);
      //os_printf("\n");
      slip_reset();
      return;
    }
  }
  if (slip_len < SLIP_MAX) slip_buf[slip_len++] = c;
}
Example #3
0
// callback with a buffer of characters that have arrived on the uart
void ICACHE_FLASH_ATTR
slip_parse_buf(char *buf, short length) {
  // do SLIP parsing
  for (short i=0; i<length; i++)
    slip_parse_char(buf[i]);

  // if we're in-between packets (debug console) then print it now
  if (!slip_inpkt && length > 0) {
    slip_process();
    slip_reset();
  }
}
Example #4
0
void ktcp_run(void)
{
    fd_set fdset;
    struct timeval timeint, *tv;

    while (1) {
	if (tcp_timeruse > 0 || tcpcb_need_push > 0) {
	    timeint.tv_sec  = 1;
	    timeint.tv_usec = 0;
	    tv = &timeint;
	} else
	    tv = NULL;

	FD_ZERO(&fdset);
	FD_SET(sfd, &fdset);
	FD_SET(tcpdevfd, &fdset);
	select(sfd > tcpdevfd ? sfd + 1 : tcpdevfd + 1,
	       &fdset, NULL, NULL, tv);

	Now = timer_get_time();

	tcp_update();

	if (FD_ISSET(sfd, &fdset))
	    slip_process();

	if (FD_ISSET(tcpdevfd, &fdset))
	    tcpdev_process();

	if (tcp_timeruse > 0)
	    tcp_retrans();

#ifdef DEBUG
	tcpcb_printall();
#endif

    }
}