PCAN sandbox - error requestOutputChannels #3698

improving logging
This commit is contained in:
rusefillc 2021-12-19 00:00:54 -05:00
parent 4bb53f265b
commit 1973b33e13
2 changed files with 24 additions and 4 deletions

View File

@ -164,6 +164,10 @@ int CanStreamerState::receiveFrame(CANRxFrame *rxmsg, uint8_t *buf, int num, can
int CanStreamerState::sendDataTimeout(const uint8_t *txbuf, int numBytes, can_sysinterval_t timeout) { int CanStreamerState::sendDataTimeout(const uint8_t *txbuf, int numBytes, can_sysinterval_t timeout) {
int offset = 0; int offset = 0;
#ifdef SERIAL_CAN_DEBUG
efiPrintf("*** INFO: sendDataTimeout %d", numBytes);
#endif /* SERIAL_CAN_DEBUG */
if (numBytes < 1) if (numBytes < 1)
return 0; return 0;
@ -260,11 +264,20 @@ can_msg_t CanStreamerState::streamAddToTxTimeout(size_t *np, const uint8_t *txbu
int numBytes = *np; int numBytes = *np;
int offset = 0; int offset = 0;
#ifdef SERIAL_CAN_DEBUG
efiPrintf("*** INFO: streamAddToTxTimeout adding %d", numBytes);
#endif /* SERIAL_CAN_DEBUG */
// we send here only if the TX FIFO buffer is getting overflowed // we send here only if the TX FIFO buffer is getting overflowed
while (numBytes >= txFifoBuf.getSize() - txFifoBuf.getCount()) { while (numBytes >= txFifoBuf.getSize() - txFifoBuf.getCount()) {
int numBytesToAdd = txFifoBuf.getSize() - txFifoBuf.getCount(); int numBytesToAdd = txFifoBuf.getSize() - txFifoBuf.getCount();
txFifoBuf.put(txbuf + offset, numBytesToAdd); txFifoBuf.put(txbuf + offset, numBytesToAdd);
int numSent = sendDataTimeout((const uint8_t *)txFifoBuf.getElements(), txFifoBuf.getCount(), timeout); int numSent = sendDataTimeout((const uint8_t *)txFifoBuf.getElements(), txFifoBuf.getCount(), timeout);
#ifdef SERIAL_CAN_DEBUG
efiPrintf("*** INFO: streamAddToTxTimeout numSent %d / numBytes", numSent, numBytes);
#endif /* SERIAL_CAN_DEBUG */
if (numSent < 1) if (numSent < 1)
break; break;
txFifoBuf.clear(); txFifoBuf.clear();
@ -272,6 +285,10 @@ can_msg_t CanStreamerState::streamAddToTxTimeout(size_t *np, const uint8_t *txbu
numBytes -= numSent; numBytes -= numSent;
} }
#ifdef SERIAL_CAN_DEBUG
efiPrintf("*** INFO: streamAddToTxTimeout remaining goes to buffer %d", numBytes);
#endif /* SERIAL_CAN_DEBUG */
// now we put the rest on hold // now we put the rest on hold
txFifoBuf.put(txbuf + offset, numBytes); txFifoBuf.put(txbuf + offset, numBytes);

View File

@ -23,7 +23,7 @@ import static com.rusefi.binaryprotocol.IoHelper.*;
*/ */
@ThreadSafe @ThreadSafe
public class IncomingDataBuffer { public class IncomingDataBuffer {
private static final Logging log = getLogging(IoStream.class); private static final Logging log = getLogging(IncomingDataBuffer.class);
static { static {
log.configureDebugEnabled(false); log.configureDebugEnabled(false);
@ -103,14 +103,14 @@ public class IncomingDataBuffer {
public void addData(byte[] freshData) { public void addData(byte[] freshData) {
synchronized (cbb) { synchronized (cbb) {
if (cbb.size() - cbb.length() < freshData.length) { if (cbb.size() - cbb.length() < freshData.length) {
log.error("IncomingDataBuffer: buffer overflow not expected"); log.error("buffer overflow not expected");
cbb.clear(); cbb.clear();
} }
cbb.put(freshData); cbb.put(freshData);
cbb.notifyAll(); cbb.notifyAll();
} }
if (log.debugEnabled()) if (log.debugEnabled())
log.debug("IncomingDataBuffer: " + freshData.length + " byte(s) arrived, total " + cbb.length()); log.debug(freshData.length + " byte(s) arrived, total " + cbb.length());
} }
/** /**
@ -174,7 +174,10 @@ public class IncomingDataBuffer {
public int getShort() throws EOFException { public int getShort() throws EOFException {
streamStats.onArrived(2); streamStats.onArrived(2);
synchronized (cbb) { synchronized (cbb) {
return cbb.getShort(); int result = cbb.getShort();
if (log.debugEnabled())
log.debug("Consumed some, " + cbb.length() + " remaining");
return result;
} }
} }