¿ªÔÆÌåÓý

Locked Re: JMRI and DCC++: Exception with Simple Programmer in Ops Accessory Byte/Extended Byte mode #dccpp #4-18


 

Dave,

What does your modified code look like? Please show us.
Will share the changed pieces tonight once I am at my home computer.
?
My reading (I'm not a C++ speaker) of the code is that the sscanf ?function returns the number of successful matches*, not the number of parameters. So nBytes returns the actual number of parameters (minus 1 for the register parameter).
That is correct. My experience is based on feeding different variants of 'M' command to DCC++ Base Station via serial console, and watching the result. Started with '<M 0 1>', got '<mInvalid packet>' response in accordance with the (unmodified original) code:

nBytes=sscanf(s,"%d %x %x %x %x %x",&nReg,b,b+1,b+2,b+3,b+4)-1;
?
if(nBytes<2 || nBytes>5){ // invalid valid packet
INTERFACE.print("<mInvalid Packet>");
?

Next was the well-behaved '<M 0 1 2 3 4 5>' which went through perfectly silent.

Then I tried '<M 0 1 2 3 4 5 6 7 8'> and did not get error response. By adding debug print of nBytes I learned it is always set to 6, and it is the number of parameters the "%d %x %x %x %x %x"?format string expects (1 decimal for register number, and 5 hexes for parameters). It appears sscanf() just ignores the rest of input once it successfully stuffes all variables in its list.

But I believe it is irrelevant at this point. More important is the knowledge that JMRI always passes the packet bytes to the DCC++ including last checksumbyte. I will need to think this over, too.

Regards
Tim






?
nBytes is the number of bytes specified to loadPacket?


?

Join [email protected] to automatically receive all group messages.