diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 12a78f3..94be666 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -97,17 +97,24 @@ void CommandDistributor::broadcastToClients(clientType type) { // If we are broadcasting from a wifi/eth process we need to complete its output // before merging broadcasts in the ring, then reinstate it in case // the process continues to output to its client. - if (ringClient!=NO_CLIENT) ring->commit(); - + if (ringClient!=NO_CLIENT) { + DIAG(F("CD precommit client %d"), ringClient); + ring->commit(); + } /* loop through ring clients */ for (byte clientId=0; clientIdmark(clientId); ring->print(broadcastBufferWriter->getString()); + DIAG(F("CD commit client %d"), clientId); ring->commit(); } } - if (ringClient!=NO_CLIENT) ring->mark(ringClient); + if (ringClient!=NO_CLIENT) { + DIAG(F("CD postmark client %d"), ringClient); + ring->mark(ringClient); + } #endif } diff --git a/RingStream.cpp b/RingStream.cpp index 3197275..4c7176e 100644 --- a/RingStream.cpp +++ b/RingStream.cpp @@ -143,6 +143,7 @@ int RingStream::freeSpace() { // mark start of message with client id (0...9) void RingStream::mark(uint8_t b) { + DIAG(F("RS mark client %d at %d"), b, _pos_write); _mark=_pos_write; write(b); // client id write((uint8_t)0); // count MSB placemarker @@ -170,7 +171,8 @@ bool RingStream::commit() { return false; // commit failed } if (_count==0) { - // ignore empty response + DIAG(F("RS commit count=0 rewind back to %d"), _mark); + // ignore empty response _pos_write=_mark; return true; // true=commit ok } @@ -181,6 +183,11 @@ bool RingStream::commit() { _mark++; if (_mark==_len) _mark=0; _buffer[_mark]=lowByte(_count); + { char s[_count+2]; + strncpy(s, (const char*)&(_buffer[_mark+1]), _count-2); + s[_count-1]=0; + DIAG(F("RS commit count=%d %s"), _count, s); + } return true; // commit worked } void RingStream::flush() { diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 32968a4..61765a4 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -610,10 +610,12 @@ byte WiThrottle::stashClient; char WiThrottle::stashThrottleChar; void WiThrottle::getLocoCallback(int16_t locoid) { + DIAG(F("LocoCallback mark client %d"), stashClient); stashStream->mark(stashClient); if (locoid<=0) { StringFormatter::send(stashStream,F("HMNo loco found on prog track\n")); + DIAG(F("LocoCallback commit (noloco)")); stashStream->commit(); // done here, commit and return return; } @@ -624,6 +626,7 @@ void WiThrottle::getLocoCallback(int16_t locoid) { locoid = locoid ^ LONG_ADDR_MARKER; // remove marker bit to get real long addr if (locoid <= HIGHEST_SHORT_ADDR ) { // out of range for long addr StringFormatter::send(stashStream,F("HMLong addr %d <= %d unsupported\n"), locoid, HIGHEST_SHORT_ADDR); + DIAG(F("LocoCallback commit (error)")); stashStream->commit(); // done here, commit and return return; } @@ -637,6 +640,7 @@ void WiThrottle::getLocoCallback(int16_t locoid) { stashInstance->multithrottle(stashStream, (byte *)addcmd); TrackManager::setMainPower(POWERMODE::ON); TrackManager::setJoin(true); // <1 JOIN> so we can drive loco away + DIAG(F("LocoCallback commit success")); stashStream->commit(); CommandDistributor::broadcastPower();