Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • E EMAM2MQTT
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • monticore
  • EmbeddedMontiArcEmbeddedMontiArc
  • generators
  • EMAM2MQTT
  • Issues
  • #22
Closed
Open
Issue created Aug 12, 2019 by Alexander David Hellwig@alexander.hellwigOwner

Add support for more Port types

Goal

Until now we assumed that each Port has the type Q, but EMAM supports other basic types:

  • Q for rational numbers, converted to double
  • N for natural numbers, converted to int
  • Z for whole numbers, also converted to int
  • B for boolean values, converted to bool
  • (C for complex, you can ignore this)

You can get the Type-String of a port with port.getTypeReference().getName().

Example code in Freemarker:

<#list model.getOutgoingPorts() as port>
    <#switch  port.getTypeReference().getName()>
        <#case "Q">
        // double
        <#break>
        <#case "N">
        //int
        <#break>
        <#case "Z">
        //int
        <#break>
        <#default>
            //error
    </#switch>
</#list>

Suggestion

Write/parse the values in standard String form

  • Q -> 1.5
  • N -> 1
  • Z -> -1
  • B -> false

Alternative

You can convert the whole number types(Z,N) by rounding a double:

//Subscriber
*port_ = (int) round(value);
//Publisher
string value = to_string(1.0 * component->${pub.getName()});

Make sure that the pointer to port_ has the right type(int* in this case)

You can convert the boolean type(B) by checking a threshold:

//Subscriber
*port_ = (value > 1.0e-10);
//Publisher
string value = to_string(component->${pub.getName()} ? 1.0 : 0.0);

Make sure that the pointer to port_ has the right type(bool* in this case)

Alternative:

Deliverables

Adapt your templates, so that all generated publish and callback methods support the Port Types Q, B, Z, and N. You might have to generated multiple Callback classes(e.g. CallbackQ.cpp/.hpp, CallbackN.cpp/.hpp,...) or think of an other approach.

Assignee
Assign to
Time tracking