Protective Stop
Loading...
Searching...
No Matches
software_backend.hpp
1// SPDX-FileCopyrightText: 2026 Polymath Robotics, Inc.
2// SPDX-License-Identifier: Apache-2.0
3#pragma once
4
5#include <cstdint>
6#include <memory>
7#include <string>
8#include <vector>
9
10#include "protective_stop_machine/backend.hpp"
11
12namespace protective_stop_machine
13{
14
17{
19 std::string bind_addr{"0.0.0.0"};
21 int port{8890};
23 uint32_t machine_id{0x01020304};
27 std::vector<uint32_t> allowlist{};
29 std::vector<uint32_t> denylist{};
30};
31
35inline bool software_remote_admitted(const SoftwareConfig & config, uint32_t remote_id)
36{
37 for (uint32_t listed_id : config.denylist) {
38 if (listed_id == remote_id) {
39 // deny wins
40 return false;
41 }
42 }
43 if (config.allowlist.empty()) {
44 // open mode: no allowlist configured
45 return true;
46 }
47 for (uint32_t listed_id : config.allowlist) {
48 if (listed_id == remote_id) {
49 return true;
50 }
51 }
52 return false;
53}
54
60{
61public:
63 explicit SoftwareMachineBackend(const SoftwareConfig & config);
64 ~SoftwareMachineBackend() override;
65
66 bool start() override;
67 void stop() override;
68 MachineSnapshot snapshot() const override;
69 bool configure(const MachineTiming & timing, std::string & error) override;
70
71 const char * name() const override
72 {
73 return "software";
74 }
75
78 struct Impl;
79
80private:
81 std::unique_ptr<Impl> impl_;
82};
83
84} // namespace protective_stop_machine
Backend seam the node depends on, implemented by SoftwareMachineBackend (hosts pstop_c) and HardwareM...
Definition backend.hpp:113
bool start() override
Begins servicing: software binds UDP and runs the machine loop, hardware starts polling.
const char * name() const override
Backend kind, "software" or "hardware".
Definition software_backend.hpp:71
void stop() override
Stops servicing and leaves the machine in its SAFE state.
SoftwareMachineBackend(const SoftwareConfig &config)
Copies config; no I/O until start().
MachineSnapshot snapshot() const override
Thread-safe copy of the latest state.
bool configure(const MachineTiming &timing, std::string &error) override
Applies an already safety-validated timing change.
One immutable read of machine state, mapped straight onto the ROS messages.
Definition backend.hpp:64
Runtime-settable timing envelope.
Definition backend.hpp:100
Deployment values for the in-process software backend.
Definition software_backend.hpp:17
uint32_t machine_id
Device ID of this machine.
Definition software_backend.hpp:23
MachineTiming timing
Initial timing envelope.
Definition software_backend.hpp:25
std::vector< uint32_t > denylist
Remote IDs refused regardless of the allowlist.
Definition software_backend.hpp:29
std::vector< uint32_t > allowlist
Remote IDs permitted to bond; empty admits any remote.
Definition software_backend.hpp:27
int port
UDP port remotes bond to.
Definition software_backend.hpp:21
std::string bind_addr
Local address the UDP socket binds to.
Definition software_backend.hpp:19