Protective Stop
Loading...
Searching...
No Matches
pstop_msg.h
1// SPDX-FileCopyrightText: 2026 Polymath Robotics, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef PSTOP_PSTOP_MSG_H
5#define PSTOP_PSTOP_MSG_H
6
7#include <stdint.h>
8
9#include "pstop/config.h"
10#include "pstop/device_id.h"
11#include "pstop/error.h"
12
13typedef uint8_t message_type_t;
14
15#define PSTOP_MESSAGE_OK 0x55U
16#define PSTOP_MESSAGE_STOP 0x92U
17#define PSTOP_MESSAGE_BOND 0xADU
18#define PSTOP_MESSAGE_UNBOND 0x6AU
19#define PSTOP_MESSAGE_UNKNOWN 0x0FU
20
25typedef struct {
29 uint8_t version;
30
34 message_type_t message;
35
39 uint64_t stamp;
40
46
51
56
62
66 uint32_t counter;
67
73
77 uint32_t padding1;
78
80 uint32_t padding2;
81
85 uint16_t checksum;
86
92
94
95void pstop_message_init(pstop_msg_t *msg);
96
97uint8_t pstop_message_get_message(const pstop_msg_t *msg);
98uint64_t pstop_message_get_stamp(const pstop_msg_t *msg);
99uint32_t pstop_message_get_counter(const pstop_msg_t *msg);
100
101void pstop_create_generic_message(pstop_msg_t *msg,
102 uint8_t message,
103 uint64_t timestamp, uint64_t received_timestamp,
104 const device_id_t *this_id, const device_id_t *target_id,
105 uint32_t counter, uint32_t received_counter);
106
107void pstop_create_bond_message(pstop_msg_t *msg,
108 uint64_t timestamp,
109 const device_id_t *this_id, const device_id_t *target_id,
110 uint32_t counter);
111
112void pstop_create_ok_message(pstop_msg_t *msg,
113 uint64_t timestamp, uint64_t received_timestamp,
114 const device_id_t *this_id, const device_id_t *target_id,
115 uint32_t counter, uint32_t received_counter);
116
117void pstop_create_stop_message(pstop_msg_t *msg,
118 uint64_t timestamp, uint64_t received_timestamp,
119 const device_id_t *this_id, const device_id_t *target_id,
120 uint32_t counter, uint32_t received_counter);
121
122void pstop_create_unbond_message(pstop_msg_t *msg,
123 uint64_t timestamp, uint64_t received_timestamp,
124 const device_id_t *this_id, const device_id_t *target_id,
125 uint32_t counter, uint32_t received_counter);
126
127pstop_error_t pstop_is_message_valid(const pstop_msg_t *msg);
128
139void pstop_message_decode(pstop_msg_t *msg, const uint8_t *data);
140
151void pstop_message_encode(const pstop_msg_t *msg, uint8_t *data);
152
153#endif /* PSTOP_PSTOP_MSG_H */
Identifier of a pstop device.
Definition device_id.h:12
A PSTOP message object.
Definition pstop_msg.h:25
message_type_t message
Type of message.
Definition pstop_msg.h:34
uint16_t checksum
a CRC-16 checksum of the above values.
Definition pstop_msg.h:85
device_id_t id
The UUID of this device.
Definition pstop_msg.h:50
uint64_t stamp
The timestamp (in milliseconds) of this message.
Definition pstop_msg.h:39
uint32_t counter
An incrementing counter.
Definition pstop_msg.h:66
uint64_t received_stamp
The last timestamp that we received from the client.
Definition pstop_msg.h:45
uint16_t calculated_checksum
The checksum that is calculated when a PSTOP message is decoded from an array of bytes.
Definition pstop_msg.h:91
uint32_t received_counter
The last counter we received from the client.
Definition pstop_msg.h:72
uint32_t padding1
extra padding bytes
Definition pstop_msg.h:77
uint8_t version
Version of this message.
Definition pstop_msg.h:29
uint32_t heartbeat_timeout
A timeout in milliseconds that we expect to receive heartbeats from this machine.
Definition pstop_msg.h:61
uint32_t padding2
Reserved.
Definition pstop_msg.h:80
device_id_t receiver_id
Unique ID of the device we are sending this message to.
Definition pstop_msg.h:55