aboutsummaryrefslogblamecommitdiff
path: root/.gitignore
blob: 764f6fbebb488c178e40a773a5ac154eb179b8ef (plain) (tree)
generated by cgit v1.2.3 (git 2.25.1) at 2024-07-17 08:36:02 +0000
an>check_send_char(END); /* for each byte in the packet, send the appropriate character * sequence */ for (int i = 0; i < len; ++i) { hal_error_t ret; if ((ret = hal_slip_send_char(buf[i])) != HAL_OK) return ret; } /* tell the receiver that we're done sending the packet */ check_send_char(END); return HAL_OK; } #define check_recv_char(c) \ if (hal_serial_recv_char(c) != HAL_OK) \ return perror("hal_serial_recv_char"), HAL_ERROR_RPC_TRANSPORT; /* Receive a single character into a buffer, with SLIP un-escaping */ hal_error_t hal_slip_recv_char(uint8_t * const buf, size_t * const len, const size_t maxlen, int * const complete) { #define buf_push(c) do { if (*len < maxlen) buf[(*len)++] = c; } while (0) static int esc_flag = 0; uint8_t c; hal_error_t ret = hal_serial_recv_char(&c); if (ret != HAL_OK) return perror("hal_slip_recv_char"), ret; *complete = 0; switch (c) { case END: if (*len) *complete = 1; break; case ESC: esc_flag = 1; break; default: if (esc_flag) { esc_flag = 0; switch (c) { case ESC_END: buf_push(END); break; case ESC_ESC: buf_push(ESC); break; default: buf_push(c); } } else { buf_push(c); } break; } return HAL_OK; } /* Receive a message with SLIP framing, blocking mode. */ hal_error_t hal_slip_recv(uint8_t * const buf, size_t * const len, const size_t maxlen) { int complete; hal_error_t ret; while (1) { ret = hal_slip_recv_char(buf, len, maxlen, &complete); if ((ret != HAL_OK) || complete) return ret; } }