/** * @brief Reads a whole line from the input channel. * * @param[in] chp pointer to a @p BaseChannel object * @param[in] line pointer to the line buffer * @param[in] size buffer maximum length * @return The operation status. * @retval TRUE the channel was reset or CTRL-D pressed. * @retval FALSE operation successful. */ bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) { char *p = line; while (TRUE) { short c = (short)chIOGet(chp); if (c < 0) return TRUE; if (c == 4) { chprintf(chp, "^D"); return TRUE; } if (c == 8) { if (p != line) { chIOPut(chp, (uint8_t)c); chIOPut(chp, 0x20); chIOPut(chp, (uint8_t)c); p--; } continue; } if (c == '\r') { chprintf(chp, "\r\n"); *p = 0; return FALSE; } if (c < 0x20) continue; if (p < line + size - 1) { chIOPut(chp, (uint8_t)c); *p++ = (char)c; } } }
static void print_line(void) { unsigned i; for (i = 0; i < 76; i++) chIOPut(chp, '-'); chIOPut(chp, '\r'); chIOPut(chp, '\n'); }
static void printn(uint32_t n) { char buf[16], *p; if (!n) chIOPut(&SD2, '0'); else { p = buf; while (n) *p++ = (n % 10) + '0', n /= 10; while (p > buf) chIOPut(&SD2, *--p); } }
/** * @brief Prints a decimal unsigned number. * * @param[in] n the number to be printed */ void test_printn(uint32_t n) { char buf[16], *p; if (!n) chIOPut(chp, '0'); else { p = buf; while (n) *p++ = (n % 10) + '0', n /= 10; while (p > buf) chIOPut(chp, *--p); } }
static void println(char *p) { while (*p) { chIOPut(&SD2, *p++); } chIOWriteTimeout(&SD2, (uint8_t *)"\r\n", 2, TIME_INFINITE); }
/** * @brief System formatted output function. * @details This function implements a minimal @p printf() like functionality * with output on a @p BaseChannel. * The general parameters format is: %[-][width|*][.precision|*][l|L]p. * The following parameter types (p) are supported: * - <b>x</b> hexadecimal integer. * - <b>X</b> hexadecimal long. * - <b>o</b> octal integer. * - <b>O</b> octal long. * - <b>d</b> decimal signed integer. * - <b>D</b> decimal signed long. * - <b>u</b> decimal unsigned integer. * - <b>U</b> decimal unsigned long. * - <b>c</b> character. * - <b>s</b> string. * . * @note Floating point types are not implemented, this function is meant * as a system utility and not a full implementation. * * @param[in] chp pointer to a @p BaseChannel implementing object * @param[in] fmt formatting string */ void chprintf(BaseChannel *chp, const char *fmt, ...) { va_list ap; char tmpbuf[MAX_FILLER + 1]; char *p, *s, c, filler; int i, precision, width; bool_t is_long, left_align; long l; va_start(ap, fmt); while (TRUE) { c = *fmt++; if (c == 0) { va_end(ap); return; } if (c != '%') { chIOPut(chp, (uint8_t)c); continue; } p = tmpbuf; s = tmpbuf; left_align = FALSE; if (*fmt == '-') { fmt++; left_align = TRUE; } filler = ' '; if (*fmt == '.') { fmt++; filler = '0'; } width = 0; while (TRUE) { c = *fmt++; if (c >= '0' && c <= '9') c -= '0'; else if (c == '*') c = va_arg(ap, int); else break; width = width * 10 + c; } precision = 0; if (c == '.') { while (TRUE) { c = *fmt++; if (c >= '0' && c <= '9') c -= '0'; else if (c == '*') c = va_arg(ap, int); else break; precision *= 10; precision += c; } }
void gps_write_cmd(uint8_t * cmd_buf, uint8_t len) { uint8_t chksum = 0, i, num_len = 0; char num_buf[4]; for (i = 0; i < len; i++) chksum ^= cmd_buf[i]; chIOPut(&GPS_SERIAL, '$'); sdWrite(&GPS_SERIAL, cmd_buf, len); chIOPut(&GPS_SERIAL, '*'); stoh(chksum, num_buf, &num_len); sdWrite(&GPS_SERIAL, num_buf, num_len - 1); chIOPut(&GPS_SERIAL, '\r'); chIOPut(&GPS_SERIAL, '\n'); }
static void printn(int16_t n) { char buf[16], *p; if (n > 0) chIOPut(&SD2, '+'); else{ chIOPut(&SD2, '-'); n = abs(n); } if (!n) chIOPut(&SD2, '0'); else { p = buf; while (n) *p++ = (n % 10) + '0', n /= 10; while (p > buf) chIOPut(&SD2, *--p); } }
static void print(char *p) { while (*p) { chIOPut(&SD2, *p++); } }
static void print_tokens(void) { char *cp = tokens_buffer; while (cp < tokp) chIOPut(chp, *cp++); }
/** * @brief Prints a line. * * @param[in] msgp the message */ void test_println(const char *msgp) { test_print(msgp); chIOPut(chp, '\r'); chIOPut(chp, '\n'); }
/** * @brief Prints a line without final end-of-line. * * @param[in] msgp the message */ void test_print(const char *msgp) { while (*msgp) chIOPut(chp, *msgp++); }
/** * @brief Prints a string. * * @param[in] chp pointer to a @p BaseChannel object * @param[in] msg pointer to the string */ void shellPrint(BaseChannel *chp, const char *msg) { while (*msg) chIOPut(chp, *msg++); }