ExMaude. IoT. Encoder
(ExMaude v0.2.0)
View Source
Encodes Elixir IoT rule structures into Maude syntax.
This module handles the conversion of Elixir maps and tuples representing IoT rules, triggers, and actions into the corresponding Maude term syntax expected by the CONFLICT-DETECTOR module.
Overview
The encoder transforms Elixir data structures into Maude's term syntax:
| Elixir Type | Maude Syntax |
|---|---|
| Rule map | rule(id, thing, trigger, actions, priority) |
| Thing ID | thing("device-id") |
| Boolean | boolVal(true) or boolVal(false) |
| Integer | intVal("123") |
| String | strVal("value") |
Trigger Encoding
Triggers are encoded into Maude comparison operators:
| Elixir Trigger | Maude Syntax |
|---|---|
{:prop_eq, "temp", 72} | propEq("temp", intVal("72")) |
{:prop_gt, "temp", 80} | propGt("temp", intVal("80")) |
{:env_eq, "time", "night"} | envEq("time", strVal("night")) |
{:always} | always |
{:and, t1, t2} | and(t1, t2) |
{:or, t1, t2} | or(t1, t2) |
{:not, t} | not(t) |
Action Encoding
Actions are encoded and joined with ;:
| Elixir Action | Maude Syntax |
|---|---|
{:set_prop, "light", "state", "on"} | setProp(thing("light"), "state", strVal("on")) |
{:set_env, "mode", "away"} | setEnv("mode", strVal("away")) |
{:invoke, "alarm", "trigger"} | invoke(thing("alarm"), "trigger") |
Value Wrapping
All values are wrapped in type constructors per the Maude IoT module:
- Booleans →
boolVal(true)orboolVal(false) - Integers →
intVal("123")(string representation) - Floats →
intVal("3.14")(string representation) - Strings →
strVal("value") - Atoms →
strVal("atom_name")
Usage
This module is typically used internally by ExMaude.IoT.detect_conflicts/2:
# Internal usage
{:ok, maude_syntax} = ExMaude.IoT.Encoder.encode_rules(rules)
# => {:ok, "rule(\"r1\", thing(\"light\"), always, nil, 1)"}See Also
ExMaude.IoT- High-level conflict detection APIExMaude.IoT.Validator- Rule validation before encodingExMaude.IoT.ConflictParser- Parsing Maude output
Summary
Functions
Encodes a single action into Maude syntax.
Encodes a list of actions into Maude syntax.
Encodes a single rule into Maude syntax.
Encodes a list of rules into Maude syntax.
Encodes a string value for Maude (quoted).
Encodes a thing ID into Maude syntax.
Encodes a trigger into Maude syntax.
Encodes a value into Maude's wrapped value syntax.
Functions
@spec encode_action(ExMaude.IoT.action()) :: String.t()
Encodes a single action into Maude syntax.
@spec encode_actions([ExMaude.IoT.action()]) :: String.t()
Encodes a list of actions into Maude syntax.
@spec encode_rule(ExMaude.IoT.rule()) :: String.t()
Encodes a single rule into Maude syntax.
@spec encode_rules([ExMaude.IoT.rule()]) :: {:ok, String.t()}
Encodes a list of rules into Maude syntax.
Returns {:ok, maude_string} on success.
Examples
rules = [%{id: "r1", thing_id: "t1", trigger: {:always}, actions: [], priority: 1}]
{:ok, "rule(\"r1\", thing(\"t1\"), always, nil, 1)"} = encode_rules(rules)
Encodes a string value for Maude (quoted).
Encodes a thing ID into Maude syntax.
@spec encode_trigger(ExMaude.IoT.trigger()) :: String.t()
Encodes a trigger into Maude syntax.
Supports property comparisons, environment checks, logical operators,
and the always trigger.
Encodes a value into Maude's wrapped value syntax.
Values are wrapped as boolVal(), intVal(), or strVal() to match
the Maude type system.