Making OpPanel, Code

This Page is under Construction

 

Overview

    In principle the software should accomodate all the four applications describe in GBM OpPanel Overview
    The software is written in C using the native tools of Atmel Studio 6.2 (based on avrgcc) and simulated by means of AVR-Studio (available at www.atmel.com).
    The real time is managed with a Real Time OS, see Cortos which is a quite simple system, based on the cooperative approach, and is suitable for the needs of embedded applications.
    All is freely available as open source under the GNU license.

    Common modules includes:

    1. Communications: BiDi
    2. Interfaces: Keyboard and LCD display
    3. Xpressnet

    GBM View uses the following module:

    1. Specific Header for communication between GBMMonitor and OpPanel, so called tp_tc_interface, Trackproc_ControlProc interface
    2. Communications: Serial
    3. Menu manager
    4. Database used for loco in GBM monitor

Common modules

    "To be written" menu splash, set up

GBM View

  1. Specific Header

    • They are defined in tp_tc_interface.h. Aim is to define local downstream and upstream messages see webpage for protocol definition.
      Values for OpPanel are:
      #define UpMsg_TYPE_MONITOR 6

      //------------------------------------ Up Message

      #define UpMsg_MONITOR_GET_BOOST_STATE 1 Answer from GBMBoost will be a DownMsg_BOOST_STATE
      #define UpMsg_MONITOR_CS_STATE 2 expecting a byte answer with GENERATOR_STATE
      #define UpMsg_MONITOR_EMERGENCY_STOP 3 key has been pressed
      #define UPMsg_MONITOR_REFRESH_LOK_STATE 4 expecting an answer giving lok state on this GBM
      #define UPMsg_MONITOR_REFRESH_OCCUPANCY 5 expecting an answer giving status for all track on this gbm
      #define UPMsg_MONITOR_QUERY_LOCATION 6 2 bytes (loco addr), control should answer with location
      #define UPMsg_MONITOR_QUERY_MY_IDX 7  
      #define UPMsg_MONITOR_QUERY_TP_STATE 8 control should return actual alive state

      // ---------------------------- Down Message

      #define DownMsg_BOOST_STATE 1 containing boost.state and boost.current, to be displayed on the LCD.
      #define DownMsg_CS_STATE 2  
      #define DownMsg_LOK_STATE 3 dead 0 /alive 1 , address, dir(msb of speed), speed, track
      #define DownMsg_OCCUPANCY 4 notify of occupancy on a trackproc/track
      #define DownMsg_TRACK_OCCUPANCY 5 notify of occupancy for all tracks on a gbm
      #define DownMsg_OCCUPANCY_ADDRESS 6 notify of occupancy addresses
      #define DownMsg_YOUR_IDX 7 notify of currently assigned tp to this port
      #define DownMsg_TP_STATE 8 announce current state
  2. Serial

    • The control_if.c module is in charge of serial communication between GBMBoost and OpPanel.

        At Power up GBMBoost detect which Boards are connected onto the serial tp connectors. They are noted 1 2 on the picture. Third one is the one above. The extreme right is for external stop.

        OpPanel can be connected to any of the three existing tp.

        GBMBoost_tp connectors

      To validate the connection, GBMBoost send:

      1. a PING
      2. to which OpPanel answer by a pong_monitor (UpMsg_SYSQID_PONG_MONITOR I am a monitor) followed by UPMsg_MONITOR_QUERY_MY_IDX ( what is my IDX?)
      3. GBMBoost answer: DownMsg_YOUR_IDX, here is the tp to which you are connected.

      4. The task gbm_monitor_parser is in charge of analyzing messages from GBMBoost. See define DownMsg in the table above.
        Messages relating to occupancy stores the resuts in gbm tables, one per gbm, defined as:
        typedef struct
        {
            uint8_t  status;                        // see bit defines
            int16_t  last_occupied;                 // given in systicks
            struct
            {
                t_dcc_addr addr;                    // 0=unknown, else: addr in this track
                uint16_t speed;
                uint16_t lastseen;                                    
            }loco[NUM_of_ADDR_per_TRACK];
        }  track_t;
        
        typedef struct
        {
            track_t  track[NUM_of_TRACKS];         // we have max. 16 inputs
            uint8_t  alive;
            int16_t  lastalive;                    // timepoint of last rec, given in systicks
        }t_gbm_monitor;
        
        t_gbm_monitor gbm[NUM_of_GBM16T];          // one gbm is the monitor itself
        

        Where infos about locos are held in a database.
  3. Menu manager

  4. The Menu includes:
    1. Navigator
    2. GBM monitor
    3. lok monitor
    4. occupancy monitor
    1. Navigator
        1. a real tiny navigation system. to use the menu system:
          a) run_navigator(); this checks for a new keystroke evalutes hotkeys and navigation keys. Other keys are forwarded to the individual screens
          b) navigation is defined in struct s_Menu.
          To see how navigation is defined look at Using OpPanel, GBM View
    2. GBM monitor
        1. Before displaying the Booster and command Station states, the module menu_gbm_monitor.c call init_GBM_data since data related to loko and occupancy, might not be correctly initialized at power_up.
          Values displayed (see GBM_Monitor) are refreshed every 400mS.
    3. lok monitor
        1. refer to Loco Monitor to see what is displayed.
          After having initialized the display, values are updated every 100mS.
          We need to have at least one GBM alive, if not the message "no gbm alive" is displayed.
          The locos known by OpPanel are held in a database. That base is ordered by use of indices pointing for one to the next loco (locomonitor[index].next) and for the other to the previous loco (locomonitor[index].prev). Inserting and deleting locos in the base is achieved by the module database_monitor.

          1. after 60ms, we assume a trackproc as dead (TP_TIMEOUT)
          2. after 2S we assume a track is not occupied
          3. after 5S we assume a loco is dead (LOK_TIME_OUT)
          Refreshing occupancy is done every 30mS half TP_TIMEOUT, and refreshing loko is done after 2.5S half LOK_TIME_OUT.
    4. occupancy monitor
        1. refer to Occupancy to see what is displayed.
          We need to have at least one GBM alive, if not the message "no gbm alive" is displayed.
          Occupancy display is refreshed every 100mS. Data about occupancy are refreshed every 30mS.

  5. Data Base

    • By the use of pointers in the data base we create an indexed database for the info held in the gbm tables. Access is ordered and faster than Scanning all the GBM tables.
      structure is as follow :

      typedef struct
      {
          unsigned char next;     // pointer to next entry
          unsigned char prev;     // pointer to prev entry
          uint8_t tpm;            // max 2 track proc to display
          uint8_t tr;             // max 16 tracks per proc
          uint8_t lo;             //Max 4 locos on a track
          t_format    format;
      } t_locomonitor;
      

      The base is kept up to date by the module database_monitor.c.