Welcome to the forum   
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post in this topic Go to first unread post in this topic
Offline fosuna  
#1 Posted : 10 January 2020 07:42:44(UTC)
fosuna

Spain   
Joined: 14/04/2015(UTC)
Posts: 11
Hi everybody!

I'd like to make a program to control my Märklin layout in H0. For this purpose, I have read the Märklin document "CAN CS2 Protokoll -2.0.doc".

Well, I understand it more less, and even I think I could make the commands to send to the CS2 for my purpose.

But I don't know which data must be in the "Hash" filed in the CAN-Bus-Id. The Hash field is a 16-bit / 2-byte filed. In the examples shown in that document, the value of this field is "(0x) 47 11". But I do not know why, neither the value must be entered in each case.

Anyone knows how to manage and use this field?

Thank you very much! And have a nice day.

Francisco


Offline bertc3p0  
#2 Posted : 01 February 2020 01:53:13(UTC)
bertc3p0

Germany   
Joined: 03/03/2014(UTC)
Posts: 10
Location: HESSEN, FRANKFURT
Originally Posted by: fosuna Go to Quoted Post
Hi everybody!

I'd like to make a program to control my Märklin layout in H0. For this purpose, I have read the Märklin document "CAN CS2 Protokoll -2.0.doc".

Well, I understand it more less, and even I think I could make the commands to send to the CS2 for my purpose.

But I don't know which data must be in the "Hash" filed in the CAN-Bus-Id. The Hash field is a 16-bit / 2-byte filed. In the examples shown in that document, the value of this field is "(0x) 47 11". But I do not know why, neither the value must be entered in each case.

Anyone knows how to manage and use this field?

Thank you very much! And have a nice day.

Francisco


Example:
Code:
/*
  CS2 CAN hash generation

  xxxxxxx11 0xxxxxxxx
  ^^^^^^^    ^^^^^^^^
   \\\\\\\   ||||||||
    \\\\\\-- ||||||||
     \\\\\\ \||||||||
  000xxxxxx xxxxxxxxx

 */
uint16_t generateHash(uint32_t uid) {
    uint16_t hash, highword, lowword;

    highword = uid >> 16;
    lowword = uid & 0xFFFF;
    hash = highword ^ lowword;
    hash = (((hash << 3) & 0xFF00) | 0x0300) | (hash & 0x7F);
    return hash;
}

The CAN-ID is a 29bit Value composed the following rule:

0x00cchhhh

where cc ist the command shifted left by one and hhhh ist the hash like 0x4711.

Regards

Gerd
thanks 1 user liked this useful post by bertc3p0
Offline fosuna  
#3 Posted : 24 May 2020 13:38:57(UTC)
fosuna

Spain   
Joined: 14/04/2015(UTC)
Posts: 11
Hello bertc3p0!

Thank you very much for your post. Sorry for the delay, but I read your message a couple of days ago.

Well, let me ask you some questions, just in case you know the answers.

1) In the C code you show for a HASH generation, I understand that a 'x' stands for a '0' or a '1'. But, where come these bits from? How they are generated? In a random way, for example?

2) Why does the high order byte end in '11'? And why the low order byte starts with '0'?

3) Why is it neccesary to make all bits opartions which are made to add three '0' bits to the high order byte, shiftting the bits with a varaible value (as I unsderstand)? I mean, why must it pass from "xxxxxx11 0xxxxxxx" to "000xxxxx xxxxx"?

I saw all of these in the Märklin "CAN CS2 Protokoll 2.0.doc" documment, but I do not understand why all of these.

Thank you very much, and have all a nice day.

Francisco
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

| Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.380 seconds.