Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • E EMAM2SomeIP
  • 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
  • EMAM2SomeIP
  • Issues
  • #24
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

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

//Subscriber
#include <math.h>
[...]
component->in1 = (int) round(dataFromMessage);
//Publisher
[...]
//Read data from component
double d = 1.0 * component->out1;
[...]

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

//Subscriber
[...]
component->in1 = (dataFromMessage > 1.0e-10);
//Publisher
[...]
//Read data from component
double d = component->out1 ? 1.0 : 0.0;
[...]

Alternative: Write and read the byteArray of the payload manually without conversions of doubles

Deliverables

Adapt your templates, so that all generated publish and callback methods support the Port Types Q, B, Z, and N.

Assignee
Assign to
Time tracking