Skip to content

ogma-core: Adapt cFS backend, template to support messages with multiple fields. Refs #625. - #626

Merged
ivanperez-keera merged 4 commits into
nasa:developfrom
ivanperez-keera:develop-double-subscription
Nov 9, 2026
Merged

ivanperez-keera merged 4 commits into
nasa:developfrom
ivanperez-keera:develop-double-subscription

Conversation

@ivanperez-keera

Copy link
Copy Markdown
Member

Adjust Common.VariableDB so that no error is reported if multiple fields of the same message are used by different variables, and adjust cFS backend and template to support multiple fields for one message, as prescribed in the solution proposed for #625.

@ivanperez-keera
ivanperez-keera force-pushed the develop-double-subscription branch 7 times, most recently from 3457da5 to 87bf836 Compare November 8, 2026 17:35
@ivanperez-keera ivanperez-keera changed the title ogma-core: Adjust cFS backend to support reading multiple fields from the same message. Refs #625. ogma-core: Adapt cFS backend, template to support messages with multiple fields. Refs #625. Nov 8, 2026
…the same message. Refs nasa#625.

When generating cFS applications, if a variable DB references multiple fields
of the same message ID from multiple variables, Ogma incorrectly reports that
they clash:

```
<no location info>: error: Reading variable DBs has failed due to them having
incompatible information for types with the same scopes and from types but
otherwise different.
```

This commit modifies the `ogma-core:Command.VariableDB` module to take fields
into account when determining if two entries in a variable DB are incompatible.
@ivanperez-keera
ivanperez-keera force-pushed the develop-double-subscription branch from 87bf836 to 9502d3e Compare November 8, 2026 22:15
…Refs nasa#625.

When generating cFS applications, if a variable DB references multiple fields
of the same message ID from multiple variables, Ogma incorrectly reports that
they clash:

```
<no location info>: error: Reading variable DBs has failed due to them having
incompatible information for types with the same scopes and from types but
otherwise different.
```

The way that the cFS backend structures information to be expanded in
templates, each message has a unique, optional "from" type and "from" field,
used to populate a variable from a field.

Using this approach means that each subscription to a cFS message can only
populate one subfield at a time, which either limits how many subfields of a
message can be referenced in expressions or introduces an inefficiency where
each variable must declare its own message handler and be called independently.

This commit modifies the cFS backend in `ogma-core` to allow multiple fields of
the same cFS data structure and message to be used, and to make all of them
available in the data structure passed to the template during expansion as
subelements of the same message data, facilitating expanding them as part of
the same handler.
…s. Refs nasa#625.

When generating cFS applications, if a variable DB references multiple fields
of the same message ID from multiple variables, Ogma incorrectly reports that
they clash:

```
<no location info>: error: Reading variable DBs has failed due to them having
incompatible information for types with the same scopes and from types but
otherwise different.
```

A prior commit modified the cFS backend to include, in message data
definitions, information on multiple fields needed from the same cFS message.

This commit adjusts the default cFS template to use that new structure when
defining the message handlers that update global variables from message fields.
@ivanperez-keera
ivanperez-keera force-pushed the develop-double-subscription branch from 9502d3e to f0f1683 Compare November 9, 2026 17:34
@ivanperez-keera

Copy link
Copy Markdown
Member Author

Change Manager: The commit message for the second commit is not clear. It talks about a limitation but that's not the right term.

@ivanperez-keera

Copy link
Copy Markdown
Member Author

Implementor: Fix implemented, review requested.

@ivanperez-keera

Copy link
Copy Markdown
Member Author

Change Manager: Verified that:

  • Solution is implemented:
    • The code proposed compiles and passes all tests. Details:
    • The solution proposed produces the expected result. Details:
      The following Dockerfile checks that the cFS backend can generate a cFS app when two variables refer to different sub-fields of the same cFS message, after which it prints the message "Success":
      --- Dockerfile-verify-625
      FROM ubuntu:22.04
      
      ENV DEBIAN_FRONTEND=noninteractive
      
      SHELL ["/bin/bash", "-c"]
      
      RUN apt-get update
      RUN apt-get install --yes --no-install-recommends \
        cabal-install \
        ca-certificates \
        cmake \
        curl \
        g++ \
        ghc \
        git \
        libbz2-dev \
        libexpat1-dev \
        libz-dev \
        make \
        pkg-config
      
      WORKDIR /root/
      
      ENV PATH=/root/.cabal-sandbox/bin:$PATH
      
      RUN cabal update || true
      RUN sed -ie 's;-- secure: True;secure: False;g' /root/.cabal/config
      RUN cabal update
      RUN cabal v1-sandbox init
      RUN cabal v1-install alex happy
      RUN cabal v1-install BNFC
      RUN cabal v1-install copilot-4.8
      
      ARG GIT_COMMIT=HEAD
      ARG NAME=ogma
      ARG REPO=https://github.com/nasa/ogma
      
      RUN git clone ${REPO} ${NAME}
      RUN cd ${NAME} && git checkout ${GIT_COMMIT}
      RUN cabal v1-install \
            --force-reinstall \
            ${NAME}/ogma-**/
      
      ADD expressions2.json /tmp/
      ADD db2.json /tmp/
      
      RUN ogma cfs --target-dir app/ --input-file /tmp/expressions2.json \
            --input-format ${NAME}/ogma-cli/examples/cfs-001-hello-ogma/json-format.cfg \
            --prop-format literal \
            --variable-db /tmp/db2.json \
            --template-vars ${NAME}/ogma-cli/examples/cfs-001-hello-ogma/extra-vars.json
      
      --- expressions2.json
      {
        "CFSExample": {
          "internal_variables": [],
          "external_variables": [
            {"name": "input_value", "type": "Int32", "meaning": "InputI32"}
          , {"name": "input_value2", "type": "Int32", "meaning": "InputI32"}
          ],
          "properties": [
            {
              "id":      "TestOgma",
              "formula": "input_value <= 0",
              "text":    "input_value shall always be lower than or equal to zero"
            }
          , {
              "id":      "TestOgma2",
              "formula": "input_value2 <= 0",
              "text":    "input_value2 shall always be lower than or equal to zero"
            }
          ]
        }
      }
      
      --- db2.json
      { "inputs":
           [ { "name": "input_value"
             , "type": "int32_t"
             , "active": true
             , "connections":
                 [ { "scope": "cfs"
                   , "topic": "SAMPLE_MID"
                   , "field": "payload"
                   }
                 ]
             }
           , { "name": "input_value2"
             , "type": "int32_t"
             , "active": true
             , "connections":
                 [ { "scope": "cfs"
                   , "topic": "SAMPLE_MID"
                   , "field": "payload2"
                   }
                 ]
             }
           ]
      , "topics":
           [ { "scope": "cfs"
             , "topic": "SAMPLE_MID"
             , "type":  "sample_msg_t"
             }
           ]
      , "types": [
             { "fromScope": "cfs"
             , "fromType":  "sample_msg_t"
             , "fromField": "payload"
             , "toScope":   "C"
             , "toType":    "int32_t"
             }
           , { "fromScope": "cfs"
             , "fromType":  "sample_msg_t"
             , "fromField": "payload2"
             , "toScope":   "C"
             , "toType":    "int32_t"
             }
           ]
      }
      
      Command (substitute variables based on new path after merge):
      $ docker build --build-arg "REPO=https://github.com/ivanperez-keera/ogma" --build-arg "NAME=ogma" --build-arg "GIT_COMMIT=f0f1683bae64f1f14ddd99de471446a1ef9dfff3" -t ogma-verify-625 -f Dockerfile-verify-625 .
      
  • Implementation is documented. Details:
    All new top-level functions and data structures have documentation.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates needed; change does not affect existing examples.
  • Author is internal or has provided signed CLA.
  • Required version bumps are evaluated. Details:
    Bump needed; change alters public API of ogma-core due to a change in the structure of the result produced by the cFS backend.

@ivanperez-keera
ivanperez-keera merged commit 1f83557 into nasa:develop Nov 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant