BiDiB, transmission over network ‐ Draft

The German version is the definitive specification. Any discrepancies between this translation and the original are unintentional.
BiDiB - Bidirectional Bus - Logo

Content

1. General

The intention of BiDiB protocol is to control a model railway. It allows the control of locomotives, accessories and safe transmission of feedback information from the model railway to the controlling computer.

BiDiB can be transported over different transmission media, framing and protection of messages is guaranteed.

The used terms and the basic principles will be explained in the general part of the protocol description. Hints for usage and the license can be found there too.

This document describes the transport by means of a network connection using User Datagram Protocol (UDP).

2. Network connection

UDP is a connectionless network protocol, which can be used to transmit data from a PC to given targets. For this purpose, UDP uses a 'port', the port number is sent with the data.

The Port 62875 is used for BiDiB. (It's in the range of dynamically assigned ports)

2.1. UDP datagram

A UDP datagram is composed of:

2 Byte2 Byte2 Byte2 Byten Bytes
Source portDestination portLengthCRCData

There is no guarantee that UDP packets arrive in the same order as sent, although this is the case in most cases (especially when a local network is used). For BiDiB, the correct packet order is important. Therefore, a sequential number is transmitted together with the data, thus the receiver is able to detect and correct the order.

2.2. Packet definition

A UDP packet (data portion) for BiDiB is built as follows:

PACKET ::= SESSION_KEY  SEQUENCE  MESSAGE_SEQ
MESSAGE_SEQ ::= ε | MESSAGE  MESSAGE_SEQ
SESSION_KEY ::= 16 Bit Integer
SEQUENCE ::= 16 Bit Integer

Data checksum and packet length is guaranteed via the definition of the UDP packet. The maximum packet length for BiDiB is 512 bytes.

SESSION_KEY is a parameter set by the interface during first connection, this number is to be send with all transmissions during the session.

  • 0: only listening access
  • 1…1023: control access
  • 1024 … 65535: reserved

SEQUENCE is a number (16 bit), incremented with every transmission. At 0xFFFF SEQUENCE wraps to 0x0000. SEQUENCE is used to determine the order of the packet. An Inerface must be able to sort up to four packets in order.

2.3. Connection establishment

Establishing a connection with a BiDiB System happens as follows:

  1. The PC program sends a packet consisting exclusively of the message MSG_SYS_GET_MAGIC to the BiDiB system. It has SEQUENCE = 0 and a SESSION_KEY = 0.
  2. The BiDiB system responds with a SYS_MAGIC, a SEQUENCE set to 0 and a SESSION KEY.
    In case the session key is different from 0, controlling the system is allowed and the program may execute the takeover and initialisation of the BiDiB system.
    In case the session key is equal to 0, no control over the system is granted and the program may only evaluate messages in a listening mode (examples: occupancy monitoring, speed step overview).