From dddb316d91eb675264ee2fa117f1019f0e6ed98c Mon Sep 17 00:00:00 2001 From: Pavel Zakopaylo Date: Fri, 1 Dec 2023 15:15:29 +1100 Subject: [PATCH] Small changes for PR --- include/blisp_util.h | 10 +++++++++- lib/blisp.c | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/blisp_util.h b/include/blisp_util.h index f1f4d8f..7307e8c 100644 --- a/include/blisp_util.h +++ b/include/blisp_util.h @@ -20,6 +20,14 @@ static void blisp_dlog(const char* format, ...) fputc('\n', stderr); } +static void blisp_dlog_no_nl(const char* format, ...) { + fflush(stdout); + va_list args; + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); +} + static void sleep_ms(int milliseconds) { #ifdef WIN32 @@ -95,4 +103,4 @@ static uint32_t crc32_calculate(const void *data, size_t data_len) } -#endif \ No newline at end of file +#endif diff --git a/lib/blisp.c b/lib/blisp.c index 28eacc9..2ffacaf 100644 --- a/lib/blisp.c +++ b/lib/blisp.c @@ -234,7 +234,7 @@ blisp_return_t blisp_device_handshake(struct blisp_device* device, if (device->chip->type == BLISP_CHIP_BL808) { sleep_ms(300); - const uint8_t second_handshake[] = { 0x50, 0x00, 0x08, 0x00, 0x38, 0xF0, 0x00, 0x20, 0x00, 0x00, 0x00, 0x18 }; + const static uint8_t second_handshake[] = { 0x50, 0x00, 0x08, 0x00, 0x38, 0xF0, 0x00, 0x20, 0x00, 0x00, 0x00, 0x18 }; ret = sp_blocking_write(serial_port, second_handshake, sizeof(second_handshake), 300); if (ret < 0) { blisp_dlog("Second handshake write failed, ret %d", ret); @@ -250,8 +250,16 @@ blisp_return_t blisp_device_handshake(struct blisp_device* device, } } } + if (!ok) { - blisp_dlog("Received no response from chip."); + blisp_dlog("Received incorrect handshake response from chip."); + blisp_dlog_no_nl("Could not find 0x%02X 0x%02X ('O', 'K') in: ", 'O', 'K'); + if (ret) { + for (uint8_t j=0; j <= ret; j++) { + blisp_dlog_no_nl("0x%02X ", device->rx_buffer[j]); + } + } + blisp_dlog(""); return BLISP_ERR_NO_RESPONSE; }