ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
euromap77.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file euromap77.h
6 * @brief EUROMAP 77 / OPC 40077 - OPC UA for injection moulding machines (IMM <-> MES), the
7 * IMM_MES_Interface information model (PROTOCORE_ENABLE_EUROMAP77).
8 *
9 * EUROMAP 77 (published as OPC 40077, ModelUri `http://opcfoundation.org/UA/PlasticsRubber/IMM2MES/`)
10 * standardizes how an injection molding machine (IMM) reports its identity, status, and the active job's
11 * live production counters to a MES, so any OPC UA client reads the same structure across machine vendors.
12 * It builds on EUROMAP 83 (OPC 40083, ModelUri
13 * `http://opcfoundation.org/UA/PlasticsRubber/GeneralTypes/`), the shared plastics/rubber type + enum
14 * library (MachineModeEnumeration, JobStatusEnumeration, ...).
15 *
16 * This module builds the IMM_MES_Interface address space on top of the OPC UA Binary server
17 * (`services/opcua`, PROTOCORE_ENABLE_OPCUA): it registers a Browse + Read resolver that answers for the
18 * IMM_MES_Interface node hierarchy and serves live values out of a caller-owned @ref EmImm struct you
19 * refresh in your loop. Same pattern as `services/umati` / `services/robotics`; no heap, no stdlib - the
20 * model is a fixed node table, the values are pointers/scalars in your struct.
21 *
22 * Model exposed (BrowseNames per the EUROMAP 77 NodeSet), under the Objects folder:
23 *
24 * IMM_MES_Interface
25 * MachineInformation Manufacturer, Model, SerialNumber, ProductCode, HardwareRevision,
26 * SoftwareRevision, DeviceRevision, ManufacturerUri
27 * MachineStatus IsPresent, MachineMode
28 * Jobs
29 * ActiveJob JobName, JobDescription, Material, ProductName, MouldId, ExpectedCycleTime,
30 * NumCavities, NominalParts
31 * ActiveJobValues JobCycleCounter, MachineCycleCounter, LastCycleTime, AverageCycleTime,
32 * JobPartsCounter, JobGoodPartsCounter, JobBadPartsCounter, JobStatus
33 *
34 * The production counters are faithful UInt64 (EUROMAP 77 defines them 64-bit), served through the OPC UA
35 * Variant's UInt64 encoding. The model is read-only (a monitoring model - the machine reports, the MES
36 * observes). Scope note: one IMM with its active job is exposed (the common single-machine MES feed); the
37 * companion-spec TypeDefinitions, methods, file/dataset transfer, and the multi-cardinality arrays
38 * (InjectionUnits, Moulds, MachineConfiguration detail) are a documented follow-on - a generic OPC UA
39 * client still browses the structure and reads every value by BrowseName today.
40 *
41 * Like umati / robotics, this installs the single OPC UA read + browse handler, so one companion model is
42 * active per server build (EUROMAP 77, umati, and robotics are mutually exclusive per OPC UA endpoint).
43 *
44 * @author Douglas Quigg (dstroy0)
45 * @date 2026
46 */
47
48#ifndef PROTOCORE_EUROMAP77_H
49#define PROTOCORE_EUROMAP77_H
50
51#include "protocore_config.h" // the entry point: protocore_types.h for the widths
52
53#if PROTOCORE_ENABLE_EUROMAP77
54
55EMBED_BEGIN_DECLS
56
57// PROTOCORE_EUROMAP77_BORROW - the bytes this module runs out of - is stated in protocore_config.h, which sums
58// it into its arena. A caller takes them once and passes the pointer to every call. How they
59// are carved is this module's and is never named here.
60
61/** @brief The IMM2MES namespace URI: the ModelUri Opc.Ua.PlasticsRubber.IMM2MES.NodeSet2.xml publishes. */
62#define EUROMAP77_NS_URI "http://opcfoundation.org/UA/PlasticsRubber/IMM2MES/"
63
64/** @brief The GeneralTypes namespace URI: the ModelUri Opc.Ua.PlasticsRubber.GeneralTypes.NodeSet2.xml publishes. */
65#define EUROMAP83_NS_URI "http://opcfoundation.org/UA/PlasticsRubber/GeneralTypes/"
66
67/**
68 * @brief Machine mode (EUROMAP 83 MachineModeEnumeration, em83 i=3011). Exposed as Int32; the numeric
69 * values are the companion-spec enumeration.
70 */
71EMBED_ENUM_BYTE(EmMachineMode,
72 EM_MODE_OTHER = 0, ///< a mode outside the ones below.
73 EM_MODE_AUTOMATIC = 1, ///< automatic production.
74 EM_MODE_SEMI_AUTOMATIC = 2, ///< semi-automatic (operator-triggered cycles).
75 EM_MODE_MANUAL = 3, ///< manual / hand operation.
76 EM_MODE_SETUP = 4, ///< set-up / preparation.
77 EM_MODE_SLEEP = 5, ///< energy-saving sleep.
78);
79
80/**
81 * @brief Active-job status (EUROMAP 83 JobStatusEnumeration, em83 i=3017). Exposed as Int32; the numeric
82 * values are the companion-spec enumeration.
83 */
84EMBED_ENUM_BYTE(EmJobStatus,
85 EM_JOB_OTHER = 0, ///< a status outside the ones below.
86 EM_JOB_TRANSFERRED_ASSIGNED = 1, ///< transferred / assigned to the machine.
87 EM_JOB_SET_UP_ACTIVE = 2, ///< set-up in progress.
88 EM_JOB_SET_UP_INTERRUPTED = 3, ///< set-up interrupted.
89 EM_JOB_SET_UP_FINISHED = 4, ///< set-up finished.
90 EM_JOB_START_UP_ACTIVE = 5, ///< start-up in progress.
91 EM_JOB_IN_PRODUCTION = 6, ///< running production.
92 EM_JOB_INTERRUPTED = 7, ///< production interrupted.
93 EM_JOB_FINISHED = 8, ///< job finished.
94 EM_JOB_TEAR_DOWN_ACTIVE = 9, ///< tear-down in progress.
95 EM_JOB_TEAR_DOWN_INTERRUPTED = 10, ///< tear-down interrupted.
96 EM_JOB_TEAR_DOWN_FINISHED = 11, ///< tear-down finished.
97);
98
99/** @brief IMM identity (EUROMAP 77 MachineInformation, common subset; all String). */
100typedef struct
101{
102 const char *manufacturer; ///< Manufacturer.
103 const char *model; ///< Model.
104 const char *serial_number; ///< SerialNumber.
105 const char *product_code; ///< ProductCode.
106 const char *hardware_revision; ///< HardwareRevision.
107 const char *software_revision; ///< SoftwareRevision.
108 const char *device_revision; ///< DeviceRevision.
109 const char *manufacturer_uri; ///< ManufacturerUri.
110} EmMachineInformation;
111
112/** @brief IMM live status (EUROMAP 77 MachineStatus, common subset). */
113typedef struct
114{
115 embed_bool is_present; ///< IsPresent.
116 EmMachineMode machine_mode; ///< MachineMode.
117} EmMachineStatus;
118
119/** @brief The active job's static parameters (EUROMAP 77 Jobs.ActiveJob, common subset). */
120typedef struct
121{
122 const char *job_name; ///< JobName.
123 const char *job_description; ///< JobDescription.
124 const char *material; ///< Material.
125 const char *product_name; ///< ProductName.
126 const char *mould_id; ///< MouldId.
127 double expected_cycle_time; ///< ExpectedCycleTime (Duration, seconds -> Double).
128 uint32_t num_cavities; ///< NumCavities.
129 uint64_t nominal_parts; ///< NominalParts.
130} EmActiveJob;
131
132/** @brief The active job's live production counters (EUROMAP 77 Jobs.ActiveJobValues; counters UInt64). */
133typedef struct
134{
135 uint64_t job_cycle_counter; ///< JobCycleCounter.
136 uint64_t machine_cycle_counter; ///< MachineCycleCounter.
137 double last_cycle_time; ///< LastCycleTime (Duration -> Double).
138 double average_cycle_time; ///< AverageCycleTime (Duration -> Double).
139 uint64_t job_parts_counter; ///< JobPartsCounter.
140 uint64_t job_good_parts_counter; ///< JobGoodPartsCounter.
141 uint64_t job_bad_parts_counter; ///< JobBadPartsCounter.
142 EmJobStatus job_status; ///< JobStatus.
143} EmActiveJobValues;
144
145/**
146 * @brief The whole IMM_MES_Interface the server exposes. Own it in your sketch and refresh its fields
147 * each loop from your machine I/O; the resolvers read straight out of it (no copy). String fields
148 * may be null (served as an empty String).
149 */
150typedef struct
151{
152 const char *name; ///< IMM_MES_Interface BrowseName / DisplayName.
153 EmMachineInformation info; ///< MachineInformation.
154 EmMachineStatus status; ///< MachineStatus.
155 EmActiveJob active_job; ///< Jobs.ActiveJob.
156 EmActiveJobValues active_job_values; ///< Jobs.ActiveJobValues.
157} EmImm;
158
159/** @brief What bind takes: imm. */
160typedef struct
161{
162 const EmImm *imm;
163} Euromap77BindArgs;
164
165/** @brief What install takes: imm. */
166typedef struct
167{
168 const EmImm *imm;
169} Euromap77InstallArgs;
170
171/**
172 * @brief EUROMAP 77 / OPC 40077 - OPC UA for injection moulding machines (IMM <-> MES), the IMM_MES_Interface
173 * information model (PROTOCORE_ENABLE_EUROMAP77).
174 *
175 * A caller sets the members a call takes, invokes it through ::Euromap77 with the bytes it runs
176 * out of, and reads the outcome off the same handle.
177 *
178 * Euromap77.bind_args.imm = ...;
179 * Euromap77.bind(work);
180 *
181 * @var Euromap77Ns::bind_args what bind takes: imm
182 * @var Euromap77Ns::install_args what install takes: imm
183 * @var Euromap77Ns::ok a call's true/false outcome
184 * @var Euromap77Ns::ns the NamespaceIndex the server gave EUROMAP77_NS_URI, once a bind has run
185 * @var Euromap77Ns::bind bind the IMM the resolvers serve. imm must outlive the server (own ...
186 * @var Euromap77Ns::install bind imm and hand the model's Read and Browse resolvers to the OPC ...
187 *
188 * @c work is PROTOCORE_EUROMAP77_BORROW bytes the CALLER took, at an address it knows. It is not held past the call, so
189 * nothing here aliases it. How those bytes are carved is this module's and is never named here.
190 */
191typedef struct
192{
193 Euromap77BindArgs bind_args;
194 Euromap77InstallArgs install_args;
195 embed_bool ok;
196 uint16_t ns;
197} Euromap77Vars;
198
199/** @brief The operands and the outcome. */
200extern Euromap77Vars Euromap77V;
201
202/** @brief The entries. */
203typedef struct
204{
205 void (*const bind)(uint8_t *work);
206 void (*const install)(uint8_t *work);
207} Euromap77Ns;
208
209// What the table binds, defined once in the .c and taking one parameter each: everything
210// else an entry needs is an operand in Euromap77V or a region of the borrow at a fixed offset.
211void protocore_euromap77_bind(uint8_t *work);
212void protocore_euromap77_install(uint8_t *work);
213
214// `static const`, initialised HERE rather than `extern` against a definition in the .c: a
215// const object whose initializer every translation unit can see is a COMPILE-TIME FACT, so
216// `Euromap77.bind(work)` resolves to a named function and becomes a DIRECT call. An extern table
217// leaves the call indirect and the symbol live at every level, -O2 -flto included.
218static const Euromap77Ns Euromap77 __attribute__((unused)) = {
219 .bind = protocore_euromap77_bind,
220 .install = protocore_euromap77_install,
221};
222
223/**
224 * @brief The PROTOCORE_EUROMAP77_BORROW bytes this module's state lives in.
225 *
226 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where
227 * that borrow comes from. Taken once from the end of the pool, which no mark and no release
228 * walks, so the state lasts the life of the program.
229 *
230 * @return the span.
231 */
232uint8_t *protocore_euromap77_span(void);
233
234EMBED_END_DECLS
235
236#endif // PROTOCORE_ENABLE_EUROMAP77
237
238#endif // PROTOCORE_EUROMAP77_H
EMBED_ENUM_BYTE(ProtoConn, PROTO_NONE=0, PROTO_HTTP=1, PROTO_TELNET=2, PROTO_SSH=3, PROTO_MODBUS=4, PROTO_OPCUA=5, PROTO_SSH_RFWD=6, PROTO_RELAY=7, PROTO_BRIDGE=8, PROTO_NTRIP_CASTER=9, PROTO_MESH=10, PROTO_UDP=11,)
Application protocol spoken on a listener port or connection slot.