コード例 #1
0
ファイル: slip.c プロジェクト: Drummondh/esp-link
// 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;
}
コード例 #2
0
ファイル: slip.c プロジェクト: cskarai/esp-link
// 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;
  }
}
コード例 #3
0
ファイル: slip.c プロジェクト: Ribster/esp-link
// 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();
  }
}