Motion Master 6.0.0-alpha.86
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 // The lossless flight-data recorder: the RT loop appends one record per cycle (raw input + output
44 // IOmap, timestamp, working counter), the source for both the live monitoring stream and point
45 // reads of the freshest value (head()-1). Allocated at configureProcessData (sizes known then),
46 // re-allocated on a layout-changing re-map, retained across teardown, freed by reset()/scan().
48 // RT-thread scratch for the exchange (touched only on the RT thread).
51 // How deep the RT thread currently is inside work that reads the device set or the IOmap; lets
52 // stopExchange() drain an in-flight cycle before a re-map or teardown mutates either.
53 //
54 // A depth counter rather than a flag because it is raised at two nesting levels. GameLoop takes a
55 // DeviceManager::CycleGuard around the whole task list, because a task resolves devices and
56 // parameters of its own and must not run while the device set is being replaced. Inside that,
57 // exchangeProcessData raises it again around the exchange, so it stays self-contained for a
58 // caller that invokes it directly. Only the RT thread raises it, so the count is small and
59 // bounded by nesting.
60 std::atomic<int> inCycle{0};
61 // Working-counter health. lastWkc is written by the RT thread each cycle; expectedWkc is
62 // recomputed by the control plane from current device states. healthy = last >= expected.
63 std::atomic<int> lastWkc{0};
64 std::atomic<int> expectedWkc{0};
65 // Cumulative record of the cycles the bus did not fully answer, written by the RT thread and
66 // cleared only by DeviceManager::reset (they run for the life of one bus session).
67 //
68 // Deliberately not per image: a re-map happens whenever anyone brings a device into or out of
69 // SAFE-OP/OP, so clearing per generation erased the history at the moment someone was chasing
70 // a fault, and left the figure describing a window nobody chose.
71 //
72 // A boolean sampled off the RT path cannot see a fault that arrived and cleared between two
73 // samples, and nothing in this process samples continuously — so a count, plus the epoch
74 // nanoseconds of the first and last bad cycle, is what survives to be read afterwards. The
75 // timestamps are the point: they are what lets a process-data fault be lined up against whatever
76 // else the log shows at that moment, which a bare count cannot answer.
77 std::atomic<uint64_t> shortWkcCycles{0};
78 std::atomic<uint64_t> firstShortWkcNs{0};
79 std::atomic<uint64_t> lastShortWkcNs{0};
80
93 struct PauseResult {
95 const ProcessImage* previous = nullptr;
99 bool drained = true;
100 };
102
107 void resumeCycle(const ProcessImage* previous);
108
115 bool healthy() const {
116 return image.load(std::memory_order_acquire) != nullptr &&
117 lastWkc.load(std::memory_order_relaxed) >= expectedWkc.load(std::memory_order_relaxed);
118 }
119
127 std::optional<std::vector<uint8_t>> readPdo(uint16_t slavePosition, uint16_t index,
128 uint8_t subindex) const;
129
138 bool isOutputMapped(uint16_t slavePosition, uint16_t index, uint8_t subindex) const;
139};
140
141} // namespace mm::node
A lock-free circular recorder of the raw process image, one record per RT cycle.
Definition process_data_ring.h:42
uint8_t subindex
Definition esi_entry.cc:283
Definition bus_health_source.h:7
Fixed-capacity byte buffer for one direction of the process image.
Definition process_image.h:25
Control plane: unpublishes the image and waits out the RT cycle already in flight.
Definition process_data.h:93
const ProcessImage * previous
The image that was published, or nullptr if none was.
Definition process_data.h:95
bool drained
Definition process_data.h:99
The live process-data runtime: the published image, the cross-thread exchange buffers,...
Definition process_data.h:36
ProcessBuffer inScratch
Definition process_data.h:50
std::atomic< int > lastWkc
Definition process_data.h:63
std::atomic< const ProcessImage * > image
Definition process_data.h:39
void resumeCycle(const ProcessImage *previous)
Control plane: republishes previous, letting RT work resume.
Definition device_manager.cc:561
PauseResult pauseCycle()
Definition device_manager.cc:529
bool isOutputMapped(uint16_t slavePosition, uint16_t index, uint8_t subindex) const
Whether an object is output-mapped in the published image, and so driven cyclically.
Definition device_manager.cc:1302
std::atomic< uint64_t > shortWkcCycles
Definition process_data.h:77
bool healthy() const
True when an image is published and the last working counter meets the expectation.
Definition process_data.h:115
std::atomic< int > expectedWkc
Definition process_data.h:64
std::vector< std::shared_ptr< const ProcessImage > > generations
Definition process_data.h:42
ProcessBuffer outScratch
Definition process_data.h:49
std::atomic< uint64_t > lastShortWkcNs
Definition process_data.h:79
std::atomic< uint64_t > firstShortWkcNs
Definition process_data.h:78
std::atomic< int > inCycle
Definition process_data.h:60
ProcessDataRing ring
Definition process_data.h:47
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:1261
The whole bus's process-data layout, resolved to absolute positions.
Definition process_image.h:69