wrps-demo-kit/03-plc/as-built/strucpp_runtime/include/iec_struct.hpp
Clio Liu 55279ca78f docs(plc): as-built copy, versions, and a getting-started guide
Adds what the folder was missing for someone picking it up cold.

as-built/  the STruC++ output copied out of the live container - the C++
           the PLC is actually executing, plus program.st and the Modbus
           buffer config. The running image was made with docker commit
           and exists in no registry, so this is the only other copy of
           the compiled form.

           Verified while copying: the deployed program.st matches
           build/wrps.st generated from src/. Identical POU structure,
           ZERO differences in non-declaration lines. src/ is genuinely
           canonical and the running PLC agrees with it.

VERSIONS.md         every version read from the running system, not from
                    documentation: runtime v4.1.10, STruC++ 0.6.2, Editor
                    4.2.11, Debian 12, g++ 12.2, pymodbus 3.11.2, CI
                    Server R1.03. Plus which plugins are enabled -
                    ethercat is on for no reason - and a v3-vs-v4 table,
                    since most OpenPLC guidance online is for v3 and the
                    %MW HR1024 change silently produces wrong data.

GETTING-STARTED.md  three questions answered in a page: how to modify the
                    program, how to stand up a new PLC container from
                    scratch, how to move this one. Includes the compose
                    file, the Editor steps that are not generated and are
                    always missed, and a symptom-to-document table.
2026-09-02 16:48:30 +10:00

115 lines
2.8 KiB
C++

// SPDX-License-Identifier: GPL-3.0-or-later WITH STruCpp-runtime-exception
// Copyright (C) 2025 Autonomy / OpenPLC Project
// This file is part of the STruC++ Runtime Library and is covered by the
// STruC++ Runtime Library Exception. See COPYING.RUNTIME for details.
/**
* STruC++ Runtime - IEC Structure Support
*
* This header provides infrastructure for IEC 61131-3 STRUCT types.
* Actual struct definitions are generated by the compiler based on user TYPE declarations.
* This file provides the base class and conventions for generated structures.
*
* Structure fields use IECVar<T> wrappers to support individual field forcing.
*/
#pragma once
#include "iec_var.hpp"
namespace strucpp {
/**
* Base class for generated IEC structures.
* Provides a common base for RTTI and potential reflection support.
* Generated structures inherit from this class.
*/
class IEC_STRUCT_Base {
public:
virtual ~IEC_STRUCT_Base() = default;
// Optional: type name for debugging/reflection
// Subclasses can override to return their type name
virtual const char* type_name() const noexcept { return "STRUCT"; }
};
/*
* Example generated structure:
*
* ST Source:
* TYPE Point : STRUCT
* x : REAL;
* y : REAL;
* END_STRUCT;
* END_TYPE
*
* Generated C++:
* struct Point : public IEC_STRUCT_Base {
* IECVar<REAL_t> x;
* IECVar<REAL_t> y;
*
* Point() noexcept : x{}, y{} {}
*
* const char* type_name() const noexcept override { return "Point"; }
* };
*
* Usage:
* Point p;
* p.x = 10.5f;
* p.y = 20.5f;
*
* // Force individual field
* p.x.force(100.0f);
* p.x = 0.0f; // Ignored while forced
* assert(p.x.get() == 100.0f);
*/
/*
* Example nested structure:
*
* ST Source:
* TYPE Rectangle : STRUCT
* topLeft : Point;
* bottomRight : Point;
* END_STRUCT;
* END_TYPE
*
* Generated C++:
* struct Rectangle : public IEC_STRUCT_Base {
* Point topLeft;
* Point bottomRight;
*
* Rectangle() noexcept : topLeft{}, bottomRight{} {}
*
* const char* type_name() const noexcept override { return "Rectangle"; }
* };
*
* Usage:
* Rectangle rect;
* rect.topLeft.x = 0.0f;
* rect.topLeft.y = 0.0f;
* rect.bottomRight.x = 100.0f;
* rect.bottomRight.y = 50.0f;
*/
/*
* Example structure with array:
*
* ST Source:
* TYPE Polygon : STRUCT
* numPoints : INT;
* points : ARRAY[1..10] OF Point;
* END_STRUCT;
* END_TYPE
*
* Generated C++:
* struct Polygon : public IEC_STRUCT_Base {
* IECVar<INT_t> numPoints;
* Array1D<Point, 1, 10> points;
*
* Polygon() noexcept : numPoints{}, points{} {}
*
* const char* type_name() const noexcept override { return "Polygon"; }
* };
*/
} // namespace strucpp