Protective Stop
Loading...
Searching...
No Matches
machine.h
1// SPDX-FileCopyrightText: 2026 Polymath Robotics, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef PSTOP_MACHINE_H
5#define PSTOP_MACHINE_H
6
7#include "pstop/pstop_msg.h"
8#include "pstop/error.h"
9#include "pstop/pstop_application.h"
10#include "pstop/pstop_remote_data.h"
11
12typedef struct pstop_machine_t pstop_machine_t;
13
17typedef pstop_error_t (* protocol_handle_message_t)(pstop_machine_t *machine, const pstop_msg_t *req, pstop_msg_t *resp);
18
26typedef pstop_error_t (* machine_handle_message_t)(pstop_machine_t *machine, const pstop_msg_t *req, pstop_msg_t *resp);
27
33typedef pstop_error_t (* pstop_check_heartbeats_t)(pstop_machine_t *machine);
34
35#define ROBOT_STATE_OK 0
36#define ROBOT_STATE_STOPPED 1
37
38#define ROBOT_RESTART_STATE_OK 0
39#define ROBOT_RESTART_STATE_NEED_STOP 1
40#define ROBOT_RESTART_STATE_STOP_RECEIVED 2
41
43typedef struct {
44
47
54
61
65 uint64_t stop_time_ms;
67
81
82void machine_init(pstop_machine_t *machine, pstop_application_t *app, pstop_remote_data_t *remotes, uint16_t max_remotes);
83
84pstop_error_t machine_handle_message(pstop_machine_t *machine, const pstop_msg_t *req, pstop_msg_t *resp);
85
86pstop_error_t machine_process_message(pstop_machine_t *machine, const pstop_msg_t *req, pstop_msg_t *resp);
87
88pstop_error_t machine_validate_heartbeats(pstop_machine_t *machine);
89
90void machine_stop_robot(pstop_machine_t *machine);
91
92const pstop_remote_data_t *machine_get_remote_data(const pstop_machine_t *machine, const device_id_t *remote_id);
93const protocol_data_t *machine_get_protocol_data(const pstop_machine_t *machine, const device_id_t *remote_id);
94const robot_state_t *machine_get_robot_state(const pstop_machine_t *machine);
95
96#endif /* PSTOP_MACHINE_H */
Identifier of a pstop device.
Definition device_id.h:12
Per-remote protocol state.
Definition protocol_data.h:12
Callbacks and configuration supplied by the application.
Definition pstop_application.h:102
The machine side of the protocol: connected remotes, application callbacks, and robot state.
Definition machine.h:69
pstop_application_t * application
Application callbacks and configuration; not owned.
Definition machine.h:75
robot_state_t robot_state
Current stop/restart state.
Definition machine.h:78
pstop_remotes_t remotes
Remote slots tracked by this machine.
Definition machine.h:72
A PSTOP message object.
Definition pstop_msg.h:25
State tracked for one remote.
Definition pstop_remote_data.h:26
A fixed-capacity collection of remotes.
Definition pstop_remote_data.h:52
Stop/restart state of the robot.
Definition machine.h:43
int restart_state
0 = everything is OK 1 = need stop message 2 = stop received
Definition machine.h:60
int robot_state
ROBOT_STATE_OK or ROBOT_STATE_STOPPED.
Definition machine.h:46
uint32_t remote_stop_id
The client ID that caused the robot to stop if stopped.
Definition machine.h:53
uint64_t stop_time_ms
Minimum time between a stop and ok message before ok transition.
Definition machine.h:65