From f48d5d711016816b01da10ec12985780b9ae75f2 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Tue, 25 Feb 2025 18:42:31 +0100 Subject: [PATCH] more verbose messages, fixed close() behaviour in case of transport change --- src/ZeDMD.cpp | 4 ++++ src/ZeDMDComm.cpp | 7 +++++++ src/ZeDMDComm.h | 4 ++++ src/client.cpp | 30 +++++++++++++++++++++--------- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/ZeDMD.cpp b/src/ZeDMD.cpp index 68d36a5..6475b0c 100644 --- a/src/ZeDMD.cpp +++ b/src/ZeDMD.cpp @@ -358,11 +358,15 @@ void ZeDMD::DisableDebug() void ZeDMD::EnableVerbose() { m_verbose = true; + m_pZeDMDComm->SetVerbose(true); + m_pZeDMDWiFi->SetVerbose(true); } void ZeDMD::DisableVerbose() { m_verbose = false; + m_pZeDMDComm->SetVerbose(false); + m_pZeDMDWiFi->SetVerbose(false); } void ZeDMD::SetRGBOrder(uint8_t rgbOrder) diff --git a/src/ZeDMDComm.cpp b/src/ZeDMDComm.cpp index 6bcfc77..07f6431 100644 --- a/src/ZeDMDComm.cpp +++ b/src/ZeDMDComm.cpp @@ -844,6 +844,8 @@ bool ZeDMDComm::StreamBytes(ZeDMDFrame* pFrame) uint16_t pos = FRAME_HEADER_SIZE; m_lastKeepAlive = std::chrono::steady_clock::now(); + m_currentCommand = pFrame->command; + if (m_verbose) Log("StreamBytes, command %02X", m_currentCommand); for (auto it = pFrame->data.rbegin(); it != pFrame->data.rend(); ++it) { @@ -988,6 +990,11 @@ bool ZeDMDComm::SendChunks(uint8_t* pData, uint16_t size) memset(ack, 0, CTRL_CHARS_HEADER_SIZE + 2); status = sp_blocking_read(m_pSerialPort, ack, CTRL_CHARS_HEADER_SIZE + 1, ZEDMD_COMM_SERIAL_READ_TIMEOUT); + if (0 == status && ZEDMD_COMM_COMMAND::Reset == m_currentCommand) { + // Sometimes ZeDMD doesn't acknowledge the reset command because the reset of the serial port happens too early on the client side. + continue; + } + if (status < (CTRL_CHARS_HEADER_SIZE + 1) || memcmp(ack, CTRL_CHARS_HEADER, CTRL_CHARS_HEADER_SIZE) != 0 || ack[CTRL_CHARS_HEADER_SIZE] == 'F') { diff --git a/src/ZeDMDComm.h b/src/ZeDMDComm.h index b75d1db..6125cea 100644 --- a/src/ZeDMDComm.h +++ b/src/ZeDMDComm.h @@ -218,6 +218,7 @@ class ZeDMDComm void SoftReset(bool reenableKeepAive = true); void EnableKeepAlive() { m_keepAlive = true; } void DisableKeepAlive() { m_keepAlive = false; } + void SetVerbose(bool verbose) { m_verbose = verbose; }; uint16_t const GetWidth(); uint16_t const GetHeight(); @@ -245,6 +246,7 @@ class ZeDMDComm void ClearFrames(); bool IsQueueEmpty(); + bool m_verbose = false; char m_firmwareVersion[12] = "0.0.0"; uint16_t m_id = 0; uint16_t m_width = 128; @@ -269,6 +271,8 @@ class ZeDMDComm uint8_t m_udpDelay = 5; uint16_t m_writeAtOnce = ZEDMD_COMM_DEFAULT_SERIAL_WRITE_AT_ONCE; + uint8_t m_currentCommand = 0; + private: bool Connect(char* pName); bool Handshake(char* pDevice); diff --git a/src/client.cpp b/src/client.cpp index cec11ce..00eebc6 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -117,6 +117,7 @@ int main(int argc, char* argv[]) { char identifier; cag_option_context cag_context; + bool wifi = false; const char* opt_port = NULL; const char* opt_ip_address = NULL; @@ -420,6 +421,7 @@ int main(int argc, char* argv[]) pZeDMD = nullptr; return -1; } + wifi = true; } else if (opt_port) { @@ -435,12 +437,16 @@ int main(int argc, char* argv[]) } else { - if (!pZeDMD->Open() && !pZeDMD->OpenDefaultWiFi()) + if (!pZeDMD->Open()) { - printf("Unable to open connection to ZeDMD via USB or WiFi.\n"); - delete pZeDMD; - pZeDMD = nullptr; - return -1; + if (!pZeDMD->OpenDefaultWiFi()) + { + printf("Unable to open connection to ZeDMD via USB or WiFi.\n"); + delete pZeDMD; + pZeDMD = nullptr; + return -1; + } + wifi = true; } } @@ -565,15 +571,21 @@ int main(int argc, char* argv[]) if (save) { pZeDMD->SaveSettings(); - pZeDMD->Reset(); + if (wifi) { + pZeDMD->Reset(); + } + else { + pZeDMD->Close(); + } } - - if (opt_led_test) + else if (opt_led_test) { pZeDMD->LedTest(); } + else { + pZeDMD->Close(); + } - pZeDMD->Close(); delete pZeDMD; pZeDMD = nullptr; return 0;