ExCEP.Model.Parser (ex_cep v0.1.1)

Copy Markdown

Strict JSON parser, semantic validator, and serializer for CSG CEP TS2.1 Simplified Device Model files (Section 8.3, Tables 27–28, Section 9.2, Appendix B).

Validation Rules Enforced (TS2.1 Section 9.2)

  1. Syntax: valid UTF-8 JSON object with exact hierarchy (schema, profile, services).
  2. Key Whitelist: rejects unknown keys or keys placed at the wrong nesting level across root, profile, services[], and DOs[].
  3. Naming & Constraints:
    • profile.model matches <mfg(1..6)>_<devType(1..12)>_<I|J>_V<x.xx>
    • serviceId is one of parameter | analog | discrete | control | accumulator

    • LDname is 1..6 ASCII characters; LNinst is a positive integer string ("1", "2", ...)
    • datatype is a valid TS2.1 Table 27 datatype
    • deadzonetype is "", "0", or "1"
    • Computed DataRefer (LDname.LNtype.LNinst.DOname) is unique within each service
  4. Filename Check (parse_file/2): when check_filename: true (default), verifies the filename matches <profile.model>.json.

Summary

Functions

Parses and validates a TS2.1 simplified model .json file from disk.

Parses and validates a TS2.1 simplified model JSON binary into %ExCEP.Model{}.

Serializes %ExCEP.Model{} into a TS2.1 Appendix B compliant JSON binary.

Performs TS2.1 Section 9.2.2 semantic validation on %ExCEP.Model{}.

Functions

parse_file(path, opts \\ [])

@spec parse_file(Path.t(), keyword()) :: {:ok, ExCEP.Model.t()} | {:error, term()}

Parses and validates a TS2.1 simplified model .json file from disk.

Options

  • :check_filename - verify filename matches <profile.model>.json (default true)
  • :strict_keys - reject undefined keys per TS2.1 Section 9.2.2 (default true)

parse_json(json, opts \\ [])

@spec parse_json(binary(), keyword()) :: {:ok, ExCEP.Model.t()} | {:error, term()}

Parses and validates a TS2.1 simplified model JSON binary into %ExCEP.Model{}.

Options

  • :strict_keys - reject undefined keys per TS2.1 Section 9.2.2 (default true)

to_json(model, opts \\ [])

@spec to_json(ExCEP.Model.t(), keyword()) :: {:ok, binary()} | {:error, term()}

Serializes %ExCEP.Model{} into a TS2.1 Appendix B compliant JSON binary.

validate(model)

@spec validate(ExCEP.Model.t()) :: :ok | {:error, term()}

Performs TS2.1 Section 9.2.2 semantic validation on %ExCEP.Model{}.