Skip to content

Commit

Permalink
Separate CoE protocol in a dedicated header as it starts to grow a lo…
Browse files Browse the repository at this point in the history
…t and others AL protocols will arrive in the future (FoE, EoE) (#184)

Co-authored-by: Philippe Leduc <philippe.leduc@wandercraft.eu>
  • Loading branch information
leducp and Philippe Leduc authored Nov 26, 2024
1 parent 62bb38b commit d5270ec
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 263 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ if (GTest_FOUND)
unit/slave-t.cc
unit/socket-t.cc
unit/Time.cc
unit/CoE/protocol-t.cc
)

target_link_libraries(kickcat_unit kickcat GTest::gmock_main)
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(KICKCAT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/OS/Time.cc

${CMAKE_CURRENT_SOURCE_DIR}/src/CoE/OD.cc
${CMAKE_CURRENT_SOURCE_DIR}/src/CoE/protocol.cc
${CMAKE_CURRENT_SOURCE_DIR}/src/CoE/mailbox/request.cc
${CMAKE_CURRENT_SOURCE_DIR}/src/CoE/mailbox/response.cc
)
Expand Down
13 changes: 13 additions & 0 deletions lib/include/kickcat/CoE/OD.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ namespace kickcat::CoE
}
}

/// ETG1004 extension unit_specification
/// For the textual description of the unit entry, the entry description shall be a definition in the object area
/// 0x0400 … 0x04FF. The entry description itself is defined as a record of the UNIT type (0x2A) which is
/// read-only in the object dictionary.
constexpr uint32_t UNIT_OFFSET = 0x0400;
struct UnitType
{
uint8_t reserved;
uint8_t denominator;
uint8_t numerator;
int8_t prefix;
};

// ETG1000.5 Chapter 6.1.4.2.1 Formal model
// ETG1000.6 Chapter 5.6.3.6.2 Get Entry Description Response
namespace Access
Expand Down
179 changes: 179 additions & 0 deletions lib/include/kickcat/CoE/protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#ifndef KICKCAT_COE_PROTOCOL_H
#define KICKCAT_COE_PROTOCOL_H

#include "kickcat/CoE/OD.h"

namespace kickcat::CoE
{
constexpr uint16_t SM_COM_TYPE = 0x1C00; // each sub-entry described SM[x] com type (mailbox in/out, PDO in/out, not used)
constexpr uint16_t SM_CHANNEL = 0x1C10; // each entry is associated with the mapped PDOs (if in used)

struct Header
{
uint16_t number : 9,
reserved : 3,
service : 4; // i.e. request, response
} __attribute__((__packed__));
std::string toString(Header const* header); // Stringify the whole message, not just the header

struct ServiceData // ETG1000.6 chapter 5.6.2 SDO
{
uint8_t size_indicator : 1,
transfer_type : 1, // expedited or not
block_size : 2,
complete_access : 1,
command : 3; // i.e. upload
uint16_t index;
uint8_t subindex;
} __attribute__((__packed__));

struct ServiceDataInfo // ETG1000.6 chapter 5.6.3 SDO Information
{
uint16_t opcode : 7,
incomplete : 1,
reserved : 8;
uint16_t fragments_left;
} __attribute__((__packed__));

struct Emergency // ETG1000.6 chapter 5.6.4 Emergency
{
uint16_t error_code;
uint8_t error_register;
uint8_t data[5];
} __attribute__((__packed__));
std::string toString(Emergency const& emg);

enum Service
{
EMERGENCY = 0x01,
SDO_REQUEST = 0x02,
SDO_RESPONSE = 0x03,
TxPDO = 0x04,
RxPDO = 0x05,
TxPDO_REMOTE_REQUEST = 0x06,
RxPDO_REMOTE_REQUEST = 0x07,
SDO_INFORMATION = 0x08
};

namespace SDO
{
// Command specifiers depending on SDO request type
namespace request
{
constexpr uint8_t DOWNLOAD_SEGMENTED = 0x00;
constexpr uint8_t DOWNLOAD = 0x01;
constexpr uint8_t UPLOAD = 0x02;
constexpr uint8_t UPLOAD_SEGMENTED = 0x03;
constexpr uint8_t ABORT = 0x04;

char const* toString(uint8_t command);
}

namespace response
{
constexpr uint8_t UPLOAD_SEGMENTED = 0x00;
constexpr uint8_t DOWNLOAD_SEGMENTED = 0x01;
constexpr uint8_t UPLOAD = 0x02;
constexpr uint8_t DOWNLOAD = 0x03;
}

namespace information
{
constexpr uint8_t GET_OD_LIST_REQ = 0x01;
constexpr uint8_t GET_OD_LIST_RESP = 0x02;
constexpr uint8_t GET_OD_REQ = 0x03;
constexpr uint8_t GET_OD_RESP = 0x04;
constexpr uint8_t GET_ED_REQ = 0x05;
constexpr uint8_t GET_ED_RESP = 0x06;
constexpr uint8_t SDO_INFO_ERROR_REQ = 0x07;

// ETG1000.5 chapter 6.1.4.3.9 and ETG1000.6 chapter 5.6.3.3
enum ListType : uint16_t
{
NumberOfObjects = 0x00,
AllObjects = 0x01,
RxPDO = 0x02,
TxPDO = 0x03,
Backup = 0x04,
Settings = 0x05
};

enum ValueInfo : uint8_t
{
UnitType = (1 << 3),
Default = (1 << 4),
Minimum = (1 << 5),
Maximum = (1 << 6)
};

struct EntryDescriptionRequest
{
uint16_t index;
uint8_t subindex;
ValueInfo value_info;
} __attribute__((__packed__));

struct ObjectDescription
{
uint16_t index;
DataType data_type;
uint8_t max_subindex;
ObjectCode object_code;
} __attribute__((__packed__));

struct EntryDescription
{
uint16_t index;
uint8_t subindex;
ValueInfo value_info;
DataType data_type;
uint16_t bit_length;
uint16_t access;
} __attribute__((__packed__));
}

namespace abort
{
constexpr uint32_t TOGGLE_BIT_NOT_ALTERNATED = 0x05030000;
constexpr uint32_t SDO_PROTOCOL_TIMEOUT = 0x05040000;
constexpr uint32_t COMMAND_SPECIFIER_INVALID = 0x05040001;
constexpr uint32_t INVALID_BLOCK_SIZE = 0x05040002;
constexpr uint32_t INVALID_SEQUENCE_NUMBER = 0x05040003;
constexpr uint32_t CRC_ERROR = 0x05040004;
constexpr uint32_t OUT_OF_MEMORY = 0x05040005;
constexpr uint32_t UNSUPPORTED_ACCESS = 0x06010000;
constexpr uint32_t READ_ONLY_ACCESS = 0x06010001;
constexpr uint32_t WRITE_ONLY_ACCESS = 0x06010002;
constexpr uint32_t SUBINDEX0_CANNOT_BE_WRITTEN = 0x06010003;
constexpr uint32_t COMPLETE_ACCESS_UNSUPPORTED = 0x06010004;
constexpr uint32_t OBJECT_TOO_BIG = 0x06010005;
constexpr uint32_t OBJECT_MAPPED = 0x06010006;
constexpr uint32_t OBJECT_DOES_NOT_EXIST = 0x06020000;
constexpr uint32_t OBJECT_CANNOT_BE_MAPPED = 0x06040041;
constexpr uint32_t PDO_LENGTH_EXCEEDED = 0x06040042;
constexpr uint32_t PARAMETER_INCOMPATIBILITY = 0x06040043;
constexpr uint32_t INTERNAL_INCOMPATIBILITY = 0x06040047;
constexpr uint32_t HARDWARE_ERROR = 0x06060000;
constexpr uint32_t DATA_TYPE_LENGTH_MISMATCH = 0x06070010;
constexpr uint32_t DATA_TYPE_LENGTH_TOO_HIGH = 0x06070012;
constexpr uint32_t DATA_TYPE_LENGTH_TOO_LOW = 0x06070013;
constexpr uint32_t SUBINDEX_DOES_NOT_EXIST = 0x06090011;
constexpr uint32_t VALUE_RANGE_EXCEEDED = 0x06090030;
constexpr uint32_t VALUE_TOO_HIGH = 0x06090031;
constexpr uint32_t VALUE_TOO_LOW = 0x06090032;
constexpr uint32_t MODULE_LIST_MISMATCH = 0x06090033;
constexpr uint32_t MAX_LESS_THAN_MIN = 0x06090036;
constexpr uint32_t RESSOURCE_UNAVAILABLE = 0x060A0023;
constexpr uint32_t GENERAL_ERROR = 0x08000000;
constexpr uint32_t TRANSFER_ABORTED_GENERIC = 0x08000020;
constexpr uint32_t TRANSFER_ABORTED_LOCAL_CTRL = 0x08000021;
constexpr uint32_t TRANSFER_ABORTED_ESM_STATE = 0x08000022;
constexpr uint32_t DICTIONARY_GENERTION_FAILURE = 0x08000023;
constexpr uint32_t NO_DATA_AVAILABLE = 0x08000024;
}

char const* abort_to_str(uint32_t abort_code);
}
}

#endif
1 change: 1 addition & 0 deletions lib/include/kickcat/Mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "kickcat/protocol.h"
#include "kickcat/AbstractESC.h"
#include "CoE/OD.h"
#include "CoE/protocol.h"


namespace kickcat
Expand Down
Loading

0 comments on commit d5270ec

Please sign in to comment.