12#ifndef MODDEF_DEVICE_HPP
13#define MODDEF_DEVICE_HPP
25#include "moddef/device.h"
40 if (
auto e = md_dev_init(&d.dev_, doc.
c_doc(),
to_c(device_id), &d.ct_); e != MD_OK)
41 return std::unexpected(
from_c(e));
48 if (
auto e = md_dev_read(&dev_,
to_c(point_id), &v); e != MD_OK)
49 return std::unexpected(
from_c(e));
56 if (
auto e = md_dev_read_string(&dev_,
to_c(point_id), buf.data(), buf.size(), &len);
58 return std::unexpected(
from_c(e));
59 return std::string_view{buf.data(), len};
64 return check(md_dev_write_f64(&dev_,
to_c(point_id), value));
67 return check(md_dev_write_i64(&dev_,
to_c(point_id), value));
70 md_value_t v = md_value_bool(on);
71 return check(md_dev_write(&dev_,
to_c(point_id), &v));
76 Device(
Device&& o) noexcept : dev_(o.dev_), ct_(o.ct_) { dev_.t = &ct_; }
A device bound to a transport: read and write its points by id.
Definition device.hpp:32
Result< void > write_f64(std::string_view point_id, double value)
Encode and write; validates access mode and §11.4 constraints first.
Definition device.hpp:63
static Result< Device > open(const Document &doc, std::string_view device_id, Transport &transport)
Bind transport to the named profile in doc (empty id = first).
Definition device.hpp:36
Device(const Device &)=delete
Device & operator=(Device &&o) noexcept
Definition device.hpp:77
Result< std::string_view > read_string(std::string_view point_id, std::span< char > buf)
Read a string point (§15) into buf; returns a view into buf.
Definition device.hpp:54
Result< void > write_i64(std::string_view point_id, std::int64_t value)
Definition device.hpp:66
Device(Device &&o) noexcept
Definition device.hpp:76
Result< Value > read(std::string_view point_id)
Read and decode a point (numeric / bool / flags / fields / datetime).
Definition device.hpp:46
Result< void > write_bool(std::string_view point_id, bool on)
Definition device.hpp:69
Device & operator=(const Device &)=delete
A parsed ModDef document.
Definition document.hpp:33
const md_doc_t * c_doc() const noexcept
Definition document.hpp:54
Blocking register-level transport.
Definition transport.hpp:28
A decoded point value: a typed view over the C core's md_value_t.
Definition value.hpp:38
A binary .moddef document (spec §4, §27), parsed in place.
Error type and Result<T> (spec §26.3/§26.4, §32).
md_transport_t bind(Transport &t) noexcept
Definition transport.hpp:68
std::expected< T, Error > Result
The canonical result type across the API; Result<void> for actions.
Definition error.hpp:53
Result< void > check(md_err_t e)
Definition error.hpp:62
md_err_t to_c(Error e) noexcept
Definition error.hpp:47
Error from_c(md_err_t e) noexcept
Definition error.hpp:46
Decoded value (spec §8, §13).