static void ICACHE_FLASH_ATTR CMD_ProtoWrite(uint8_t data) { switch(data){ case SLIP_START: case SLIP_END: case SLIP_REPL: uart0_write_char(SLIP_REPL); uart0_write_char(SLIP_ESC(data)); break; default: uart0_write_char(data); } }
static void ICACHE_FLASH_ATTR cmdProtoWrite(uint8_t data) { switch(data){ case SLIP_END: uart0_write_char(SLIP_ESC); uart0_write_char(SLIP_ESC_END); break; case SLIP_ESC: uart0_write_char(SLIP_ESC); uart0_write_char(SLIP_ESC_ESC); break; default: uart0_write_char(data); } }
int uart0_write_data(u8 *data, int len) { int i = 0; for (i = 0; i <len; i++) { uart0_write_char(*(data + i)); } return i; }
static void ICACHE_FLASH_ATTR log_write_char(char c) { // Uart output unless disabled if (!log_no_uart) { if (log_newline) { char buff[16]; int l = os_sprintf(buff, "%6d> ", (system_get_time()/1000)%1000000); for (int i=0; i<l; i++) uart0_write_char(buff[i]); log_newline = false; } uart0_write_char(c); if (c == '\n') { log_newline = true; uart0_write_char('\r'); } } // Store in log buffer if (c == '\n') log_write('\r'); log_write(c); }
// Start a response, returns the partial CRC void ICACHE_FLASH_ATTR cmdResponseStart(uint16_t cmd, uint32_t value, uint16_t argc) { DBG("cmdResponse: cmd=%d val=%d argc=%d\n", cmd, value, argc); uart0_write_char(SLIP_END); cmdProtoWriteBuf((uint8_t*)&cmd, 2); resp_crc = crc16_data((uint8_t*)&cmd, 2, 0); cmdProtoWriteBuf((uint8_t*)&argc, 2); resp_crc = crc16_data((uint8_t*)&argc, 2, resp_crc); cmdProtoWriteBuf((uint8_t*)&value, 4); resp_crc = crc16_data((uint8_t*)&value, 4, resp_crc); }
// Start a response, returns the partial CRC uint16_t ICACHE_FLASH_ATTR CMD_ResponseStart(uint16_t cmd, uint32_t callback, uint32_t _return, uint16_t argc) { uint16_t crc = 0; uart0_write_char(SLIP_START); CMD_ProtoWriteBuf((uint8_t*)&cmd, 2); crc = crc16_data((uint8_t*)&cmd, 2, crc); CMD_ProtoWriteBuf((uint8_t*)&callback, 4); crc = crc16_data((uint8_t*)&callback, 4, crc); CMD_ProtoWriteBuf((uint8_t*)&_return, 4); crc = crc16_data((uint8_t*)&_return, 4, crc); CMD_ProtoWriteBuf((uint8_t*)&argc, 2); crc = crc16_data((uint8_t*)&argc, 2, crc); return crc; }
// write to the uart designated for logging static void uart_write_char(char c) { if (flashConfig.log_mode == LOG_MODE_ON1) uart1_write_char(c); else uart0_write_char(c); }
// Ends a response void ICACHE_FLASH_ATTR CMD_ResponseEnd(uint16_t crc) { CMD_ProtoWriteBuf((uint8_t*)&crc, 2); uart0_write_char(SLIP_END); }
// Ends a response void ICACHE_FLASH_ATTR cmdResponseEnd() { cmdProtoWriteBuf((uint8_t*)&resp_crc, 2); uart0_write_char(SLIP_END); }