Motion Master 6.0.0-alpha.111
Next-generation motion control software
Loading...
Searching...
No Matches
spoe_frame.h
Go to the documentation of this file.
1#pragma once
2
3// The SPoE wire format: a 7-byte header and a data part. Pure functions with no I/O, so the
4// connection and the tests share one definition of the bytes.
5//
6// The layout follows the netX firmware, `AppSockIf_MessageHandler.h`, `msg_frame_t`. Every field is
7// little-endian and there is no padding between them.
8
9#include <cstddef>
10#include <cstdint>
11#include <expected>
12#include <optional>
13#include <span>
14#include <string>
15#include <vector>
16
17namespace mm::comm::spoe {
18
20enum class MessageType : uint8_t {
21 kSdoRead = 0x01,
22 kSdoWrite = 0x02,
23 kPdoFrame = 0x03,
24 kPdoControl = 0x04,
25 kSdoBatchRead = 0x06,
26 kFirmwareUpdate = 0x0B,
27 kFileRead = 0x0C,
28 kFileWrite = 0x0D,
29 kStateControl = 0x0E,
30 kStateRead = 0x0F,
31 kParamList = 0x10,
32 kParamDesc = 0x11,
33 kParamSubDesc = 0x12,
34 kParamFullDesc = 0x13,
35 kServerInfo = 0x20,
36 kDeviceLocate = 0x21,
37 kWatchdogTimeout = 0x22,
38};
39
41constexpr std::size_t kHeaderSize = 7;
42
44constexpr std::size_t kMaxDataSize = 512;
45
47 uint8_t type = 0;
48 uint16_t sequenceId = 0;
49 uint16_t status = 0;
50 uint16_t dataLength = 0;
51};
52
55struct Frame {
56 uint8_t type = 0;
57 uint16_t sequenceId = 0;
58 uint16_t status = 0;
59 std::vector<uint8_t> data;
60};
61
63std::expected<std::vector<uint8_t>, std::string> encodeFrame(const Frame& frame);
64
67std::optional<FrameHeader> decodeHeader(std::span<const uint8_t> bytes);
68
69} // namespace mm::comm::spoe
Definition spoe_connection.cc:15
MessageType
The message types the firmware handles. A reply carries the type of its request.
Definition spoe_frame.h:20
std::optional< FrameHeader > decodeHeader(std::span< const uint8_t > bytes)
Definition spoe_frame.cc:36
std::expected< std::vector< uint8_t >, std::string > encodeFrame(const Frame &frame)
Encodes frame. Fails when the data part is larger than kMaxDataSize.
Definition spoe_frame.cc:18
constexpr std::size_t kHeaderSize
Message type u8, sequence id u16, status u16, data length u16.
Definition spoe_frame.h:41
constexpr std::size_t kMaxDataSize
MAX_FRAME_SIZE in the firmware: the size of its buffer for the data part.
Definition spoe_frame.h:44
std::size_t bytes
Definition spoe_connection.cc:24
Definition spoe_frame.h:46
uint16_t sequenceId
Definition spoe_frame.h:48
uint16_t status
Definition spoe_frame.h:49
uint8_t type
Definition spoe_frame.h:47
uint16_t dataLength
Definition spoe_frame.h:50
Definition spoe_frame.h:55
uint16_t sequenceId
Definition spoe_frame.h:57
uint8_t type
Definition spoe_frame.h:56
std::vector< uint8_t > data
Definition spoe_frame.h:59
uint16_t status
Definition spoe_frame.h:58