Motion Master 6.0.0-alpha.50
Next-generation motion control software
Loading...
Searching...
No Matches
mailbox_error_codes.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <cstdint>
6#include <nlohmann/json_fwd.hpp>
7#include <string_view>
8
9namespace mm::comm {
10
13 uint16_t code = 0;
14 std::string_view name;
15 std::string_view description;
16};
17
22void to_json(nlohmann::json& j, const MailboxErrorCode& e);
23
31inline constexpr auto kMailboxErrorCodes = std::to_array<MailboxErrorCode>({
32 {0x0001, "MBXERR_SYNTAX", "Syntax of the 6-octet mailbox header is wrong"},
33 {0x0002, "MBXERR_UNSUPPORTEDPROTOCOL", "The mailbox protocol is not supported"},
34 {0x0003, "MBXERR_INVALIDCHANNEL",
35 "Channel field contains a wrong value (a slave may ignore it)"},
36 {0x0004, "MBXERR_SERVICENOTSUPPORTED", "The service in the mailbox protocol is not supported"},
37 {0x0005, "MBXERR_INVALIDHEADER",
38 "The mailbox protocol header is wrong (excluding the 6-octet mailbox header)"},
39 {0x0006, "MBXERR_SIZETOOSHORT", "Length of received mailbox data is too short"},
40 {0x0007, "MBXERR_NOMOREMEMORY",
41 "Mailbox protocol cannot be processed because of limited resources"},
42 {0x0008, "MBXERR_INVALIDSIZE", "The length of data is inconsistent"},
43 {0x0009, "MBXERR_SERVICEINWORK", "Mailbox service already in use"},
44});
45
48constexpr std::string_view mailboxErrorCodeDescription(uint16_t code) {
49 const auto it = std::find_if(kMailboxErrorCodes.begin(), kMailboxErrorCodes.end(),
50 [code](const MailboxErrorCode& e) { return e.code == code; });
51 return it != kMailboxErrorCodes.end() ? it->description : std::string_view{};
52}
53
54} // namespace mm::comm
Definition al_status_codes.cc:5
void to_json(nlohmann::json &j, const AlStatusCode &c)
Serialises an AlStatusCode to JSON.
Definition al_status_codes.cc:7
constexpr std::string_view mailboxErrorCodeDescription(uint16_t code)
Returns the description of code, or an empty view if code is not a known mailbox error code (vendor-s...
Definition mailbox_error_codes.h:48
constexpr auto kMailboxErrorCodes
Catalogue of CoE mailbox error codes.
Definition mailbox_error_codes.h:31
Metadata for a single CoE mailbox error code entry.
Definition mailbox_error_codes.h:12
std::string_view name
Symbolic name (e.g. "MBXERR_SYNTAX").
Definition mailbox_error_codes.h:14
uint16_t code
16-bit Detail code from the mailbox error reply.
Definition mailbox_error_codes.h:13
std::string_view description
Human-readable meaning of the error.
Definition mailbox_error_codes.h:15