Écrire et vérifier un modèle › Keep catalogs of layers, tags and types

Écrire et vérifier un modèle

Cette page n’est pas encore traduite : voici la version anglaise.

Catalogs: layers, tags, colours, port types, packages, translations

A project has words of its own: the layers it is drawn in, the tags it files things under, its colours, the kinds of connection its ports offer, the packages its model is split into, and the languages it is written in. Declare them once, and every element uses them by name.

These declarations are the catalogs extension, outside the 1.0 core (archec check --core names each). The kinds of a project are a catalog too, with a page of their own.

A first catalog#

A greenhouse, written in French with its English translation, in two layers, with a tag group, its colours, its own bus and a package:

project Greenhouse "Greenhouse" {
  edition "1.2"
  languages fr, en
}

layer logical "Logique" en "Logical"
layer physical "Physique" en "Physical"

color leaf = "#2e7d32"
color alarm { light "#c62828"; dark "#ef5350" }

tag-group domain "Domaine" en "Domain" { color leaf }
tag safety "Sécurité" en "Safety" { group domain; color alarm }
tag comfort "Confort" en "Comfort" { group domain }

port-type rs485 "RS-485" {
  color leaf
  handling message
  latency 2ms
  bitrate 115200
  wire a "A" inout { signal "RS-485" }
  wire b "B" inout { signal "RS-485" }
}

property ip-rating "Indice IP" en "IP rating" {
  type enum
  values IP54, IP65, IP67
  kinds sensor
  group environment
}

defaults requirement { status draft; method test }

requirement REQ-TEMP "Température bornée" en "Temperature bounded" {
  text "La serre doit rester sous 35 °C." en "The greenhouse shall stay below 35 °C."
  tags safety
}

package climate {
  message READING "Mesure" en "Reading" { temperature: float32 unit °C }

  component Probe "Sonde" en "Probe" {
    kind sensor
    layer physical
    prop ip-rating = IP65
    out bus: rs485 sends READING
  }

  component Controller "Régulateur" en "Controller" {
    layer logical
    satisfies REQ-TEMP
    in bus: rs485 receives READING
  }
}

system Greenhouse "Serre" en "Greenhouse" {
  part probe: climate.Probe
  part ctrl:  climate.Controller
  probe.bus -> ctrl.bus
}

trace involves REQ-TEMP -> Greenhouse.probe "The probe measures what the requirement bounds"
Diagramme : Serre
Ce qu’archec dessine depuis ce code : Serre
Essayer

archec check main.arche checks every name. archec build main.arche writes each catalog to the Arche project: layers.yaml, tags.yaml, tag-types.yaml, colors.yaml, types.yaml (the port types), properties.yaml and traces.yaml. Each name and text carries its English translation beside the French (name.en).

Layers#

A layer is a level the model is drawn at: operational, logical, physical. Declare the most abstract first, since their order is their meaning. A component or a system says its layer with layer physical.

Tags and tag groups#

A tag files elements under a word: tags safety on a requirement, a component or a test plan. A tag-group is a family of tags with its colour, and a tag says its family with group domain. Once the project declares a tag group, a tag whose group names none of them is a warning (unknown-tag-group, with the closest name).

Colours#

A color is a named colour of the palette: one value (color leaf = "#2e7d32"), or one per theme (color alarm { light "#c62828"; dark "#ef5350" }). A value that is not a #rgb or #rrggbb colour is a warning (bad-color). Tags, tag groups, port types and kinds take a colour by its name, or as a literal "#rrggbb". The palette's own names (red, amber, green, blue…) need no declaration.

Port types#

A port's type says what kind of connection it offers. data, can, ethernet, spi, i2c, uart and the other common ones are built in. A port-type declares one of your own:

  • wire lists its conductors, each with its direction and its signal.
  • handling message or handling http says what an in port of this type answers: messages, or HTTP requests.
  • latency, jitter and bitrate are its timing, for the Arche app's simulator.
  • memory-mapped true makes it a bus whose ports are read and written by address (AXI, a register file).
  • potential and flow make it physical: a voltage and a current, a velocity and a force. Its links then join parts with no direction, and archec physics solves the network.

A link between two ports of different types is a warning (Port types differ: rs485 → can, link-type-mismatch). A port type that is used and neither built in nor declared is a warning too (unknown-porttype).

Packages#

A package groups declarations under a name, so a large model reads by part. package climate { … } groups part of a file. package climate alone on the first line puts the whole file in it, as in Go. From outside, write climate::Probe (or climate.Probe). Inside, and anywhere it is the only one, Probe works too.

A package is a namespace: two packages may each declare a READING, and each keeps its package in its id in the Arche project and the generated code. A bare name that two packages have is an error (ambiguous) until it is written with its package or brought in with import climate::* (the spec). A qualified name that the package does not hold is an error: No 'N' in package a.

Defaults#

defaults requirement { status draft; method test } gives every requirement of the file the values it does not set itself. At the top of a file it covers the file; inside a component or a system, that block. The nearest defaults wins, and an element's own value always does. The build is the same as if each requirement had written them.

Property definitions#

A property says what a property of components holds: its type (string, int, float, bool or enum), its unit, the values of an enum, the kinds of component it applies to, the group it is filed under and its default. A component then gives its value with prop ip-rating = IP65.

The definitions go to properties.yaml, and the Arche app checks the values against them (as Capella's property values do). archec itself does not: see the limits below.

Translations#

languages fr, en says the languages of the model, the one it is written in first. A translation follows its text: "Sonde" en "Probe", or en "…" on the next line. To keep the model's files in one language, put the translations in a block of their own:

project Pump "Pompe" { languages fr, en }

requirement REQ-START "Démarrage" {
  text "La pompe doit démarrer en moins de 100 ms."
}

translations en {
  REQ-START "Start"
  REQ-START.text "The pump shall start within 100 ms."
}

Each line names an element (by its id, its path, or package.Name) or one of its texts (REQ-START.text), and gives it in that language. A quoted text on its own ("démarrage" "start-up") is translated wherever it is written. An entry that names nothing is a warning (translation). So is one that says another translation than the text's own en "…".

archec refactor translations main.arche --extract en moves the inline translations into such a block. The Arche app, archec site, archec story export --lang en and a ui's locale show the model in either language. In VS Code, Toggle Dimmed Translations dims the translations in the editor.

Trace lines#

A trace is a typed relation between two elements, for what no property says: derives, refines, allocates, realizes, involves, deploys or traces, with a comment in quotes. It goes to traces.yaml. A link to a requirement is written on its other end instead, as satisfies or verifies. A trace whose end names nothing is an error.

Files of the project#

The build writes the Arche project's files from the model. Three declarations reach into them directly:

  • file "deliverables.yaml" { attr version = 1 } sets a field of a generated file itself.
  • data "plots.yaml" = { version: 1, plots: [] } writes a file the language does not model, from a value that is checked as any value is.
  • raw "plots.yaml" with a fenced YAML block writes the text as it is.

They are the escape hatch: reach for them last.

What is added by itself#

A kind, layer, tag, port type or colour that is used and not declared is added to its catalog by the build, with its name as its label. Once a catalog declares one entry, an undeclared name used beside it is a warning, with the closest declared name: Unknown layer 'logicl'. Did you mean 'logical'? It will be added to the catalog. The quick fix declares it.

auto-catalogs false in the project turns this off: only what is declared is written, and the warning says so. infer-links false writes a link's type and messages only when the link itself says them, not from its ports.

Limits#

  • archec does not check a component's prop values against the property definitions: a value outside an enum's values, or a property on a kind its kinds leaves out, is written as it is. The Arche app checks them.
  • A port type's latency, jitter and bitrate time messages in the Arche app's simulator only. archec sim delays a message by its link's and its ports' own latency, not by its port type's.
  • A tag is checked against its group only when the project declares a tag group. A used tag that no catalog declares is added silently while the catalog is empty.
  • A translation is a text in another language, not a check that the two say the same thing: nothing tells when the French changes and the English is left behind.
  • Packages do not make names local: every id is declared once in the whole project, whatever its package.
  • raw text is written as it is, and nothing checks it.