Automatic recognition of mfx id with CS2 & Gleisbox

Märklin Central Station 2

Automatic recognition of mfx id with CS2 & Gleisbox

Postby woodyboy » 19.10.2014, 21:46

Dear forummembers,

After a while of not using my layout, I experienced that my only mfx train did not response to the combination of my booster and the Gleisbox without a MS2 connected. After reconnecting the MS2 the problem was gone, but I was also curious about the possibilities of Rocrail's bind option. I also read the thread in the German forum about the development of this function, really cool. But the thread stopped suddenly after the first successful tests.
Basically it works. But I suppose with a few modifications it can be strongly improved. The discovery is done correctly. A bind is executed, but testing the bind with a verify at the decoder is omitted.
Here begins my journey. I would propose that on the bind acknowledge packet a verify is initiated.
Code: Select all
 00 06 3735 6 FF FA 8C 43 00 05 00 00  ; verify request to the decoder
CAN packet to receive after the request:
 00 07 0300 7 FF FA 8C 43 00 05 ff 00 ;  when the sid is not 00 00 it means the bind was successful at the decoder, ff means the signal quality


When the verification is acknowledged, an improvement can be made by retrieving the stored name id of the loco from the decoder. The name could be requested using the sid:
Code: Select all
00 0e 3735 7 00 00 40 05 04 03 10 00 Asking for the stored name at CV3 and index 1, the index is in the most significant 6 bits of in[9], the two less significant bits of in[9] belong to the cv number together with in[10], together they mean cv3, in[11] contains 10 -> requesting 16 bytes


When asking for the stored loco name with the former CAN packet, the Gleisbox returns (with the CAN id of Rocrail :shock: )with this sequence of packets:
Code: Select all
00 0f 0300 7 00 00 40 05 04 03 56 00 ; after the sid, 04 >> 2 gives the index 1, 03 = cv3, 56 is the hex ASCII 'V'
00 0f 0300 7 00 00 40 05 08 03 54 00 ; index 2, cv3 , 'T'
00 0f 0300 7 00 00 40 05 0c 03 20 00 ; index 3, cv3, space
00 0f 0300 7 00 00 40 05 10 03 37 00 ;etc
00 0f 0300 7 00 00 40 05 14 03 35 00
00 0f 0300 7 00 00 40 05 18 03 20 00
00 0f 0300 7 00 00 40 05 1c 03 39 00
00 0f 0300 7 00 00 40 05 20 03 30 00
00 0f 0300 7 00 00 40 05 24 03 32 00
00 0f 0300 7 00 00 40 05 28 03 20 00
00 0f 0300 7 00 00 40 05 2c 03 44 00
00 0f 0300 7 00 00 40 05 30 03 42 00
00 0f 0300 7 00 00 40 05 34 03 00 00 ; end of string
00 0f 0300 7 00 00 40 05 38 03 00 00
00 0f 0300 7 00 00 40 05 3c 03 00 00
00 0f 0300 7 00 00 40 05 40 03 00 00


But I definitely got stuck reading back the string. The CS2 library has a read config function, but I do not know how and where it is used, and how it stores the cv variables.
My assumption is that it goes stuck at the following line in the __evaluateMCS2ReadConfig function:
Code: Select all
int cv = in[9]*256 + in[10];
To my limited knowledge the computing of the index is missing. My ignorance here could only lead to disaster in this case. I really have no idea how to extract the byte and placing the identifier string in the right object. Hopefully somebody can pick it up here or give me the directions.

I propose the following insertions for improving the bind and verify procedure. BTW Why not change the 0x4711 for the 0x0300 id?
Code: Select all
//*****
static void __evaluateMCS2Bind( iOMCS2Data mcs2, byte* in ) {
/* 00054711 6 FF FA 8C 43 00 05 */
  int uid = (in[5] << 24) + (in[6] << 16) + (in[7] << 8) + in[8];
  int sid = (in[9] << 8) + in[10];
  TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "Bind acknowledged, requesting Verify UID=0x%04X on sid %d", uid, sid );
  if( sid > 0 && wMCS2.isbind(mcs2->mcs2ini) ) {
    iONode loco = __getUID(mcs2, uid);
    if( wProduct.getsid(loco) == sid ) {  // is the sid the same as Rocrail serves it then request the verify?
      byte  buffer[32];
      buffer[0]  = in[5];
      buffer[1]  = in[6];
      buffer[2]  = in[7];
      buffer[3]  = in[8];
      buffer[4]  = (wProduct.getsid(loco) / 256) & 0xFF;
      buffer[5]  = (wProduct.getsid(loco) % 256) & 0xFF;

      ThreadOp.post( mcs2->writer, (obj)__makeMsg(0, CMD_LOCO_VERIFY, 0x4711, False, 6, buffer) );
    }
  }
}
//******

======================
In de __reader function
Code: Select all
    else if( in[1] == (ID_LOCO_BIND + BIT_RESPONSE) ) {
      __evaluateMCS2Discovery( data, in );
    }
Last edited by woodyboy on 13.05.2015, 21:59, edited 2 times in total.
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby rjversluis » 20.10.2014, 09:11

Hi Bert,

I merged your proposal in the sources.
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBus - CAN-GCA ] - [ 0: RocNetNode - GCA-Pi ]
rjversluis
Site Admin
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby woodyboy » 20.10.2014, 09:58

Hi Rob,

Thanks for merging, This morning I realized that the Bind and Verify could also be initiated by a CS2. I do not know if the discovery sequence is also announced by the CAN bridge of a CS2. To prevent erroneous behaviour in case of a connected CS2. my proposal is to call the Verify conditionally only with a found data->gbUID != 0.
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby woodyboy » 20.10.2014, 22:24

Hmm, I think this morning I was not awake, a verify is not disruptive. Maybe the bind, but that is already longer in the source and nobody has complaint.
More painful to me is the wrong copy action in the proposed changes:

Code: Select all
    else if( in[1] == (ID_LOCO_BIND + BIT_RESPONSE) ) {
      __evaluateMCS2Discovery( data, in );
    }


should be:
Code: Select all
    else if( in[1] == (ID_LOCO_BIND + BIT_RESPONSE) ) {
       __evaluateMCS2Bind( data, in );
    }
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby rjversluis » 21.10.2014, 06:14

Hi Bert,

I corrected this in the sources.
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBus - CAN-GCA ] - [ 0: RocNetNode - GCA-Pi ]
rjversluis
Site Admin
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby woodyboy » 21.10.2014, 06:53

Hi Rob,

Thanks! Additional question. Is a function available to configure the server defined protocol for a discovered loco? Now it is created with the DCC protocol. In the discovery packet is the detected protocol reported in the last valid byte of the message.
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby rjversluis » 21.10.2014, 07:28

Hi Bert,
woodyboy wrote:Is a function available to configure the server defined protocol for a discovered loco? Now it is created with the DCC protocol. In the discovery packet is the detected protocol reported in the last valid byte of the message.

If you show me how to decode this byte I can add it as property for generating/modifying a loco object.
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBus - CAN-GCA ] - [ 0: RocNetNode - GCA-Pi ]
rjversluis
Site Admin
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby woodyboy » 21.10.2014, 17:45

Hi Rob,

Thanks for adding the property, I found your changes :P . The loco is now created with the right protocol. I'll try to test if it also functions for discovered DCC loco.
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby rjversluis » 21.10.2014, 17:50

Hi Bert,

discovery of DCC on the main tack is not supported; MCS2 Doc says: Technically impossible.
Also I only query MFX Locos in the mcs2 lib.
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBus - CAN-GCA ] - [ 0: RocNetNode - GCA-Pi ]
rjversluis
Site Admin
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby woodyboy » 21.10.2014, 21:24

Hi Rob,

You are right. The Gleisbox recognizes the decoder by quering by the broadcast address cv29, followed by querying cv1 via the broadcast address. I suppose cv29 is used to determine long/short.
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby woodyboy » 22.10.2014, 19:30

Hi Rob,

As stated in the start of the thread it would be nice if the in the decoder stored name is the same as the Id in the Locomotives tables.

My problem is to read back the id of the loc and therefore also writing back the identifier. I can't find the handle of the loco with the given sid from the CAN frame. Is it possible to read back the id? Do you support the idea and do you want to help or solve this challenge.

After lots of hours this is my last experiment. Looks like reading the id from NULL and writing to NULL....

Code: Select all
static void __evaluateMCS2ReadConfig( iOMCS2Data data, byte* in ) {

  int index = ( in[9] & 0xFC ) >> 2;
  int cv = ( in[9] & 0x03 )*256 + in[10];
  char ident[32] = {'\0'};
  int addr  = ( ( in[7] & 0x0F ) << 8 ) + in[8];
  int value = in[11];
  int i=0;
  int dlc = in[4];
  const char* id;
  if( dlc == 7 ) {
    if( (index != 0) && (cv == 3) && (value != 0)) {
      iONode nodeC = NodeOp.inst( wLoc.name(), NULL, ELEMENT_NODE );
      if( data->iid != NULL )
        wLoc.setiid( nodeC, data->iid );
      wLoc.setaddr( nodeC, addr );

      if (index > 1 ) {
// sprinkle here some magic pixie dust to get the locomotive id string
        id = wLoc.getid(nodeC);
      }
      for (i = 0 ; i < index ; i++)
        ident[i] = id[i];
      ident[index-1] = in[11];
      wLoc.setidentifier(nodeC, ident);
      TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "Decoder address attribute %d constructing readable name to %s", addr, ident );
  }
//**** followed by the original code
    iONode node = NodeOp.inst( wProgram.name(), NULL, ELEMENT_NODE );
    cv = in[9]*256 + in[10];
//    int value = in[11];
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby woodyboy » 26.10.2014, 23:01

Dear forummembers,

The creating of a mfx loco is succesfull, the interface protocol on the interfaceform is correct generated.
But Rocrail is actually sending packets for motorola protocol instead of mfx. :? for the new locs. same with locos who already have earlier a sid before generated. Tested with Rocrail version 8121.
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby rjversluis » 27.10.2014, 16:41

Hi Bert,

I just fixed it.
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBus - CAN-GCA ] - [ 0: RocNetNode - GCA-Pi ]
rjversluis
Site Admin
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby smitt48 » 27.10.2014, 18:59

Hallo Bert,

Just nosy! What is a Gleisbox from Maerklin (60113) do? The documentation at Maerklin is short on particulars! I assume you are trying to use it for something different.

Bedankt

Ps. where near Utrecht, I have family in Zeist!
Kind regards,
Tom Smit
Kralendijk, Bonaire - Dutch Caribbean

Märklin M & K-rails with ECoS2 (4.2.3) - Win10
RoSoft: S88n & WDD switch & SDD signal decoders
Display: Tri-ang from 1950's, Märklin from early 1960's
In build phase
smitt48
 

Re: Automatic recognition of ID on discovery with a Gleisbox

Postby woodyboy » 28.10.2014, 23:20

@ Rob, tested and fix confirmed.

A Gleisbox is very simple unidirectional controller for mfx, motorola, DCC and maybe SX. The normal interface to the user is an MS2. The system lacks feedback control. The combination MS2 and Gleisbox uses a CAN bus to communicate. Most of the CAN commands are in common with the CS2 protocol.
Regards,

Bert

Equipment: Roco WLANMaus, MS2, Gleisbox 2x(separated switch & rollingstock). Ubuntu 16. Edits booster. Arduino: S88 CANbus interface & Ethernet-CANbus gateway
woodyboy
 

Next

Return to CS2