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 TypeMaude Syntax
Rule maprule(id, thing, trigger, actions, priority)
Thing IDthing("device-id")
BooleanboolVal(true) or boolVal(false)
IntegerintVal("123")
StringstrVal("value")

Trigger Encoding

Triggers are encoded into Maude comparison operators:

Elixir TriggerMaude 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 ActionMaude 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) or boolVal(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

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

encode_action(arg)

@spec encode_action(ExMaude.IoT.action()) :: String.t()

Encodes a single action into Maude syntax.

encode_actions(actions)

@spec encode_actions([ExMaude.IoT.action()]) :: String.t()

Encodes a list of actions into Maude syntax.

encode_rule(rule)

@spec encode_rule(ExMaude.IoT.rule()) :: String.t()

Encodes a single rule into Maude syntax.

encode_rules(rules)

@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)

encode_string(s)

@spec encode_string(String.t() | atom()) :: String.t()

Encodes a string value for Maude (quoted).

encode_thing_id(id)

@spec encode_thing_id(String.t()) :: String.t()

Encodes a thing ID into Maude syntax.

encode_trigger(arg)

@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.

encode_value(v)

@spec encode_value(boolean() | number() | String.t() | atom()) :: String.t()

Encodes a value into Maude's wrapped value syntax.

Values are wrapped as boolVal(), intVal(), or strVal() to match the Maude type system.