Motion Master 6.0.0-alpha.50
Next-generation motion control software
Loading...
Searching...
No Matches
process_data.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <cstdint>
5#include <memory>
6#include <optional>
7#include <span>
8#include <vector>
9
11#include "node/process_image.h"
12
13namespace mm::node {
14
37 // The currently published image layout, or nullptr when no image is published (exchange is then
38 // a no-op). Loaded lock-free by readers; published with release ordering by the control plane.
39 std::atomic<const ProcessImage*> image{nullptr};
40 // Every image ever published since the last reset(), retained so a lock-free reader can never
41 // dereference a freed image after a re-map republishes a new one.
42 std::vector<std::shared_ptr<const ProcessImage>> generations;
43 // Per-output-object staging slots, one per entry in image->outputs (rebuilt and seeded at each
44 // re-map). A writer stores its object's latest wire bytes (≤8, packed little-endian into the u64)
45 // here lock-free — writers to different objects never contend; the same object is last-writer-
46 // wins. The RT loop reads every slot each cycle and composes the output image (one thread
47 // composing is what keeps bit-packed objects sharing a byte safe without a lock; NEXTGEN Design
48 // B).
49 std::vector<std::atomic<uint64_t>> outputSlots;
50 static_assert(std::atomic<uint64_t>::is_always_lock_free,
51 "output staging slots must be lock-free so the RT path never blocks");
52 // The lossless flight-data recorder: the RT loop appends one record per cycle (raw input + output
53 // IOmap, timestamp, working counter), the source for both the live monitoring stream and point
54 // reads of the freshest value (head()-1). Allocated at configureProcessData (sizes known then),
55 // re-allocated on a layout-changing re-map, retained across teardown, freed by reset()/scan().
57 // RT-thread scratch for the exchange (touched only on the RT thread).
60 // Set by the RT thread while it is inside a driver exchange; lets stopExchange() drain an
61 // in-flight cycle before a re-map or teardown mutates the IOmap.
62 std::atomic<bool> exchanging{false};
63 // Working-counter health. lastWkc is written by the RT thread each cycle; expectedWkc is
64 // recomputed by the control plane from current device states. healthy = last >= expected.
65 std::atomic<int> lastWkc{0};
66 std::atomic<int> expectedWkc{0};
67
74 bool healthy() const {
75 return image.load(std::memory_order_acquire) != nullptr &&
76 lastWkc.load(std::memory_order_relaxed) >= expectedWkc.load(std::memory_order_relaxed);
77 }
78
86 std::optional<std::vector<uint8_t>> readPdo(uint16_t slavePosition, uint16_t index,
87 uint8_t subindex) const;
88
94 bool writePdo(uint16_t slavePosition, uint16_t index, uint8_t subindex,
95 std::span<const uint8_t> bytes);
96};
97
98} // namespace mm::node
A lock-free circular recorder of the raw process image, one record per RT cycle.
Definition process_data_ring.h:34
Definition http_server.h:16
Fixed-capacity byte buffer for one direction of the process image.
Definition process_image.h:24
The live process-data runtime: the published image, the cross-thread exchange buffers,...
Definition process_data.h:36
ProcessBuffer inScratch
Definition process_data.h:59
std::atomic< int > lastWkc
Definition process_data.h:65
bool writePdo(uint16_t slavePosition, uint16_t index, uint8_t subindex, std::span< const uint8_t > bytes)
Stages a PDO output object's bytes into its slot, sent on the next cycle. Lock-free.
Definition device_manager.cc:1010
std::atomic< const ProcessImage * > image
Definition process_data.h:39
std::atomic< bool > exchanging
Definition process_data.h:62
bool healthy() const
True when an image is published and the last working counter meets the expectation.
Definition process_data.h:74
std::atomic< int > expectedWkc
Definition process_data.h:66
std::vector< std::shared_ptr< const ProcessImage > > generations
Definition process_data.h:42
ProcessBuffer outScratch
Definition process_data.h:58
std::vector< std::atomic< uint64_t > > outputSlots
Definition process_data.h:49
ProcessDataRing ring
Definition process_data.h:56
std::optional< std::vector< uint8_t > > readPdo(uint16_t slavePosition, uint16_t index, uint8_t subindex) const
Reads a PDO-mapped object's current bytes from the live image. Lock-free.
Definition device_manager.cc:970