Skip to content

Commit

Permalink
adjusted ACK again
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Jan 25, 2025
1 parent c10eea1 commit 8d98882
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions src/ZeDMDComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ bool ZeDMDComm::Handshake(char* pDevice)
sp_nonblocking_write(m_pSerialPort, data, ZEDMD_COMM_MAX_SERIAL_WRITE_AT_ONCE);

// For Linux and macOS, 200ms seem to be sufficient. But some Windows installations require a longer sleep here.
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::this_thread::sleep_for(std::chrono::milliseconds(200));
memset(data, 0, ZEDMD_COMM_MAX_SERIAL_WRITE_AT_ONCE);
sp_blocking_read(m_pSerialPort, data, 20, ZEDMD_COMM_SERIAL_READ_TIMEOUT);
int result = sp_blocking_read(m_pSerialPort, data, 20, ZEDMD_COMM_SERIAL_READ_TIMEOUT);

if (memcmp(data, CTRL_CHARS_HEADER, 4) == 0)
{
Expand Down Expand Up @@ -681,10 +681,9 @@ bool ZeDMDComm::SendChunks(uint8_t* pData, uint16_t size)
(defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || \
defined(__ANDROID__))

uint8_t ack[1] = {0};
uint8_t ack[CTRL_CHARS_HEADER_SIZE + 1] = {0};
int status = 0;
uint16_t sent = 0;
uint8_t numCtrlCharsFound = 0;

while (sent < size && !m_stopFlag.load(std::memory_order_relaxed))
{
Expand Down Expand Up @@ -717,32 +716,17 @@ bool ZeDMDComm::SendChunks(uint8_t* pData, uint16_t size)
}
sent += status;

numCtrlCharsFound = 0;
while (!m_stopFlag.load(std::memory_order_relaxed) && numCtrlCharsFound < CTRL_CHARS_HEADER_SIZE)
{
status = sp_nonblocking_read(m_pSerialPort, ack, 1);
if (status == 1)
{
// Detect 5 consecutive start bits
if (ack[0] == CTRL_CHARS_HEADER[numCtrlCharsFound])
{
numCtrlCharsFound++;
}
else
{
numCtrlCharsFound = 0;
}
}
}
status = sp_blocking_read(m_pSerialPort, ack, CTRL_CHARS_HEADER_SIZE + 1, ZEDMD_COMM_SERIAL_READ_TIMEOUT);

status = sp_blocking_read(m_pSerialPort, ack, 1, ZEDMD_COMM_SERIAL_READ_TIMEOUT);
if (ack[0] == 'F')
if (status < CTRL_CHARS_HEADER_SIZE + 1 || memcmp(ack, CTRL_CHARS_HEADER, CTRL_CHARS_HEADER_SIZE) != 0 ||
ack[CTRL_CHARS_HEADER_SIZE] == 'F')
{
m_fullFrameFlag.store(true, std::memory_order_release);
Log("Full frame requested by ZeDMD because of internal error");
Log("Full frame forced, error %d", status);
return false;
}
else if (ack[0] != 'A')

if (ack[CTRL_CHARS_HEADER_SIZE] != 'A')
{
m_fullFrameFlag.store(true, std::memory_order_release);
Log("Full frame forced, error %d", status);
Expand Down

0 comments on commit 8d98882

Please sign in to comment.