uniba-swt / libbidib

A library for communication with a BiDiB (www.bidib.org) system using a serial connection.
GNU General Public License v3.0
10 stars 4 forks source link

Support Kehrschleifenmodul #8

Closed eyip002 closed 2 years ago

eyip002 commented 3 years ago

The state of a Kehrschleifenmodul (reversing loop) is stored on the GBMboost board that it is connected to. We can read the state via the Configuration Value (CV) 51 that is local of the GBM16T it is connected to.

  1. Define the CV of each Kehrschleifenmodule as part of the track configuration file.

    boards:
    - id: master
    reversers:
      - id: reverser1
        cv: 10051
      - id: reverser2
        cv: 20051
  2. Update the track parser to create a new state object for reversers.

  3. Define high-level functions for updating the state of a reverser from a GBM16T into the library.

    
    // Working prototype:
    t_bidib_node_address_query nodeaddr = bidib_get_nodeaddr("master");
    bidib_send_vendor_get(nodeaddr.address, (uint8_t)5, (uint8_t *)&"20051", 0);

// Possible libbidib API: void bidib_update_reverser_state(char reverser_name) { uint8_t reverser = bidib_get_reverser(reverser_name); bidib_send_vendor_get(reverser->nodeaddr, reverser->cv_length, reverser->cv, 0); }


Result of `bidib_send_vendor_get(0.0.0, 5, "20051")`, which asks the for the value of CV 20051 (current state of the Kehrschleifenmodul) from node address 0.0.0 (GBMboost master):

libbidib: Send to: 0x00 0x00 0x00 0x00 seq: 38 type: MSG_VENDOR_GET (0x17) action id: 0 libbidib: Message bytes: 0x09 0x00 0x26 0x17 0x05 0x32 0x30 0x30 0x35 0x31


Response from GBMboost master:

libbidib: Received from: 0x00 0x00 0x00 0x00 seq: 38 type: MSG_VENDOR (0x93) action id: 0 libbidib: Message bytes: 0x0b 0x00 0x26 0x93 0x05 0x32 0x30 0x30 0x35 0x31 0x01 0x31


The value of CV 20051 is "1" (ASCII value 0x31).

Thus, `bidib_transmission_receive.c` needs to look for `MSG_VENDOR` and to check whether the CV matches a reverser. If so, the value is saved into the state.

4. Define high-level functions for querying the state of a reverser. The state should be marked as stale (-1) to indicate that an update is necessary before it can be queried again.
eyip002 commented 2 years ago

Implemented in 4e4c7741ce51feef682976e5f0433ea11b29d39d..c3945df13a5d3ffc043ce35e83ae2354999a0763