tmcl_interpreter.h
Go to the documentation of this file.
1 
6 #ifndef TMCL_INTERPRETER_H
7 #define TMCL_INTERPRETER_H
8 
9 #include <future>
10 #include <chrono>
11 #include <vector>
12 #include <algorithm>
13 
14 #include "socket_can_wrapper.h"
15 
27 const uint8_t TMCL_MSG_SZ = 7;
28 const uint8_t TMCL_MSG_VALUE_SZ = 4;
29 
30 /*******************************************************************************/
31 /* Interface related settings */
32 /*******************************************************************************/
33 
34 /* Supported interfaces */
35 typedef enum
36 {
37  TMCL_INTERFACE_CAN = 0, /* 0 - CAN Interface */
38  TMCL_INTERFACE_MAX, /* This should not be used */
40 
41 /* Supported interface's configurations */
42 /* Note: So far, these are all needed for CAN. Once other interfaces are added,
43  convert this tmcl_cfg_t to a union then include different tmcl_cfg_<interface>_t as members. */
44 typedef struct
45 {
47  std::string interface_name;
48  uint16_t tx_id;
49  uint16_t rx_id;
50 } tmcl_cfg_t;
51 
52 /*******************************************************************************/
53 /* TMCL protocol related settings */
54 /*******************************************************************************/
55 
56 /* Possible values for <Command> */
57 typedef enum
58 {
59  TMCL_CMD_ROR = 1, /* 1 - Rotate right */
60  TMCL_CMD_ROL, /* 2 - Rotate left */
61  TMCL_CMD_MST, /* 3 - Motor stop */
62  TMCL_CMD_MVP, /* 4 - Move to position */
63  TMCL_CMD_SAP, /* 5 - Set axis parameter */
64  TMCL_CMD_GAP, /* 6 - Get axis parameter */
65  TMCL_CMD_SGP = 9, /* 9 - Set global parameter */
66  TMCL_CMD_GGP, /* 10 - Get global parameter */
67  TMCL_CMD_APPGFWV = 136, /* 136 - Get firmware version */
68  TMCL_CMD_MAX /* This should not be used */
69 } tmcl_cmd_t;
70 
71 /* Possible values for <Status> */
72 typedef enum
73 {
82  TMCL_STS_MAX /* This should not be used */
83 } tmcl_sts_t;
84 
85 /* Definition for info needed to execute 1 TMCL command */
86 typedef struct
87 {
88  uint16_t tx_id; /* Module Address */
89  uint16_t rx_id; /* <Reply Address */
90  tmcl_cmd_t cmd; /* <Command> */
91  uint8_t type; /* <Type> */
92  uint8_t motor; /* <Motor> */
93  uint8_t value[TMCL_MSG_VALUE_SZ]; /* 4-byte value */
95 } tmcl_msg_t;
96 
97 /* Class definition for TMCL Interpreter */
99 {
100 public:
101  /* Constructor */
102  TmclInterpreter(uint16_t timeout_ms, uint8_t comm_exec_cmd_retries,
103  std::vector<std::string> param_ap_name, std::vector<int> param_ap_type);
104 
105  /* Destructor */
107 
108  /* Reset interface */
109  bool resetInterface();
110 
111  /* Execute command where type is a number */
112  bool executeCmd(tmcl_cmd_t cmd, uint8_t type, uint8_t motor, int32_t *val);
113 
114  /* Execute command where type is a string(only available in ap_name_)*/
115  bool executeCmd(tmcl_cmd_t cmd, std::string type, uint8_t motor, int32_t *val);
116 
117  /* Shutdown interface */
118  bool shutdownInterface();
119 
120  /* Getter b_retries_exceeded variable */
122 
125 
126 private:
128  uint16_t timeout_ms_;
130  std::vector<std::string> param_ap_name_;
131  std::vector<int> param_ap_type_;
132 
134 };
135 
136 #endif /* _TMCL_INTERPRETER_H */
TMCL_INTERFACE_MAX
@ TMCL_INTERFACE_MAX
Definition: tmcl_interpreter.h:38
tmcl_msg_t::type
uint8_t type
Definition: tmcl_interpreter.h:91
TmclInterpreter::tmcl_interface_
tmcl_interface_t tmcl_interface_
Definition: tmcl_interpreter.h:123
tmcl_msg_t::tx_id
uint16_t tx_id
Definition: tmcl_interpreter.h:88
TmclInterpreter::~TmclInterpreter
~TmclInterpreter()
Definition: tmcl_interpreter.cpp:35
tmcl_msg_t::sts
tmcl_sts_t sts
Definition: tmcl_interpreter.h:94
TMCL_STS_ERR_NONE
@ TMCL_STS_ERR_NONE
Definition: tmcl_interpreter.h:80
TmclInterpreter::tmcl_cfg_
tmcl_cfg_t tmcl_cfg_
Definition: tmcl_interpreter.h:124
TMCL_STS_ERR_VAL
@ TMCL_STS_ERR_VAL
Definition: tmcl_interpreter.h:77
TMCL_CMD_GAP
@ TMCL_CMD_GAP
Definition: tmcl_interpreter.h:64
TMCL_CMD_MAX
@ TMCL_CMD_MAX
Definition: tmcl_interpreter.h:68
TmclInterpreter::executeCmd
bool executeCmd(tmcl_cmd_t cmd, uint8_t type, uint8_t motor, int32_t *val)
Definition: tmcl_interpreter.cpp:75
SocketCAN
Definition: socket_can_wrapper.h:9
TMCL_MSG_VALUE_SZ
const uint8_t TMCL_MSG_VALUE_SZ
Definition: tmcl_interpreter.h:28
TmclInterpreter::getRetriesExceededStatus
bool getRetriesExceededStatus()
Definition: tmcl_interpreter.cpp:215
TMCL_INTERFACE_CAN
@ TMCL_INTERFACE_CAN
Definition: tmcl_interpreter.h:37
TmclInterpreter::param_ap_name_
std::vector< std::string > param_ap_name_
Definition: tmcl_interpreter.h:130
TMCL_STS_ERR_CHKSUM
@ TMCL_STS_ERR_CHKSUM
Definition: tmcl_interpreter.h:74
TmclInterpreter::comm_exec_cmd_retries_
uint8_t comm_exec_cmd_retries_
Definition: tmcl_interpreter.h:129
TmclInterpreter::TmclInterpreter
TmclInterpreter(uint16_t timeout_ms, uint8_t comm_exec_cmd_retries, std::vector< std::string > param_ap_name, std::vector< int > param_ap_type)
Definition: tmcl_interpreter.cpp:12
TMCL_STS_ERR_EEPROM_LCK
@ TMCL_STS_ERR_EEPROM_LCK
Definition: tmcl_interpreter.h:78
TMCL_STS_MAX
@ TMCL_STS_MAX
Definition: tmcl_interpreter.h:82
tmcl_cfg_t::interface_name
std::string interface_name
Definition: tmcl_interpreter.h:47
TmclInterpreter::timeout_ms_
uint16_t timeout_ms_
Definition: tmcl_interpreter.h:128
TMCL_CMD_ROL
@ TMCL_CMD_ROL
Definition: tmcl_interpreter.h:60
TmclInterpreter::resetInterface
bool resetInterface()
Definition: tmcl_interpreter.cpp:49
TmclInterpreter::interface_enabled_
bool interface_enabled_
Definition: tmcl_interpreter.h:127
tmcl_interface_t
tmcl_interface_t
Definition: tmcl_interpreter.h:35
tmcl_cfg_t::tx_id
uint16_t tx_id
Definition: tmcl_interpreter.h:48
tmcl_cfg_t::p_socket_can
SocketCAN * p_socket_can
Definition: tmcl_interpreter.h:46
TMCL_CMD_GGP
@ TMCL_CMD_GGP
Definition: tmcl_interpreter.h:66
TmclInterpreter
Definition: tmcl_interpreter.h:98
TMCL_CMD_SGP
@ TMCL_CMD_SGP
Definition: tmcl_interpreter.h:65
tmcl_cmd_t
tmcl_cmd_t
Definition: tmcl_interpreter.h:57
TMCL_STS_ERR_TYPE
@ TMCL_STS_ERR_TYPE
Definition: tmcl_interpreter.h:76
TMCL_STS_CMD_LOADED
@ TMCL_STS_CMD_LOADED
Definition: tmcl_interpreter.h:81
socket_can_wrapper.h
TmclInterpreter::param_ap_type_
std::vector< int > param_ap_type_
Definition: tmcl_interpreter.h:131
tmcl_cfg_t::rx_id
uint16_t rx_id
Definition: tmcl_interpreter.h:49
tmcl_msg_t::rx_id
uint16_t rx_id
Definition: tmcl_interpreter.h:89
tmcl_cfg_t
Definition: tmcl_interpreter.h:44
TMCL_CMD_MVP
@ TMCL_CMD_MVP
Definition: tmcl_interpreter.h:62
tmcl_msg_t::cmd
tmcl_cmd_t cmd
Definition: tmcl_interpreter.h:90
TMCL_CMD_ROR
@ TMCL_CMD_ROR
Definition: tmcl_interpreter.h:59
TMCL_CMD_SAP
@ TMCL_CMD_SAP
Definition: tmcl_interpreter.h:63
TmclInterpreter::shutdownInterface
bool shutdownInterface()
Definition: tmcl_interpreter.cpp:196
tmcl_msg_t
Definition: tmcl_interpreter.h:86
TMCL_STS_ERR_CMD
@ TMCL_STS_ERR_CMD
Definition: tmcl_interpreter.h:75
TmclInterpreter::b_retries_exceeded_
bool b_retries_exceeded_
Definition: tmcl_interpreter.h:133
tmcl_msg_t::motor
uint8_t motor
Definition: tmcl_interpreter.h:92
TMCL_MSG_SZ
const uint8_t TMCL_MSG_SZ
Definition: tmcl_interpreter.h:27
tmcl_sts_t
tmcl_sts_t
Definition: tmcl_interpreter.h:72
TMCL_CMD_APPGFWV
@ TMCL_CMD_APPGFWV
Definition: tmcl_interpreter.h:67
TMCL_CMD_MST
@ TMCL_CMD_MST
Definition: tmcl_interpreter.h:61
TMCL_STS_ERR_CMD_NA
@ TMCL_STS_ERR_CMD_NA
Definition: tmcl_interpreter.h:79


adi_tmcl
Author(s):
autogenerated on Wed Apr 2 2025 02:43:01