Hello everyone,
I try to use NMRADCC with my own central sation (currentlly operating on esp32). Everything is working well but when I want to use NMRADCC to read the packets for accessories I get an issue. For example, instead of reading the address 167, NMRADCC function reads 665.
I am sending the message 11111111111111111111 0 10100111 0 11011001 0 01111110 1
so 167 = 010100111 (101 is the complement of 010 in the second octet 10100111)
thanks for your help
Please do yourself a favour and please read How to get the best out of this forum and post accordingly (including code tags and necessary documentation for your ask).
Addressing of accessories is a bit tricky, because there are different possibilities to interpret the adressing information in a DCC packet: decoder addressing and output addressing. Decoder addressing is based on the old turnout decoders, that could address 4 turnouts with one decoder. With this decoding the address information is split in two parts: The decoder address, and the turnout address within the decoder. This is what you do with your address computing with the result '167' ( omitting the turnout address within the decoder, bit 1 and 2 of the second octett ).
But when you use the notifyDccAccTurnoutOutput() call back, the address is interpreted differently. This callback uses output addressing. All turnouts are numbered sequentially, independent of a decoder address. The output address is (nearly) 4 times the decoder address. 'Nearly' because most central stations don't use the decoder address '0'. In this case the (binary)turnout addresses 0..3 are not used, therefore the output address is (decoderaddress*4) -3.
And that is what you get: 167*4-3 = 665.
The packet format is always the same. It's only a matter of interpreting it. If you want to use decoder addressing don't set the flag CV29_OUTPUT_ADDRESS_MODE when calling Dcc.init() and use the callback notifyDccAccTurnoutBoard() instead of notifyDccAccTurnoutOutput()
NB: If you have programmed your own central unit, you should use the same addressing scheme for the central unit as for the decoder. This would avoid confusion in the addresses. In my opinion Decoder addressing only makes sense if you also use corresponding decoders with 4 turnout outputs.
Where can I find a detailed explanation for the constant we can use with the library NMRADCC?
FLAGS_DCC_ACCESSORY_DECODER
CV29_OUTPUT_ADDRESS_MODE
...etc
How can weuse them? What are their goals.
Thanks
The only documentation I know of are the comments in the NmraDcc.h file.
Most of the constants set bits in CV29 and thus influence the behaviour of the decoder. The meaning of these bits is described in the NMRA / NEM documents.
Yes, that's it. Bit 7 in CV29 defines wether the decoder is a multifunction decoder ( for locomotives ) or an accessory decoder. The meaning of the other bits is dependent on this bit. Therefore you must tell the lib what type of decoder you want to use.
You can read about that in dokument s-9.2.2 of the NMRA, which defines all the CV values.
#define FLAGS_OUTPUT_ADDRESS_MODE 0x40 // CV 29/541 bit 6
#define FLAGS_DCC_ACCESSORY_DECODER 0x80 // CV 29/541 bit 7
These defines are the same. I would prefer to use the FLAGS_... version, because these defines are meant for use in the init() Method. So you are sure if - for whatever reason - these may be defined differently in the future.
Well, the decoder must know what type it is, to interpret the packets correctly. But you can additionally get every packet as 'raw' packet with the