43#ifndef PROTOCORE_FOCAS_H
44#define PROTOCORE_FOCAS_H
48#if PROTOCORE_ENABLE_FOCAS
52#define FOCAS_TCP_PORT 8193
53#define FOCAS_FRAME_HDR_LEN 10
54#define FOCAS_PROTO_VERSION 1
55#define FOCAS_FRAME_DST 0x0002
56#define FOCAS_CMD_SEL_LEN 6
57#define FOCAS_CMD_ARGS_LEN 20
58#define FOCAS_REQ_BODY_LEN 26
59#define FOCAS_RESP_HDR_LEN 14
60#define FOCAS_VALUE_LEN 8
61#define FOCAS_SYSINFO_LEN 18
66 FOCAS_FRAME_TYPE_INVALID = 0x0000,
67 FOCAS_FRAME_TYPE_OPEN_REQ = 0x0101,
68 FOCAS_FRAME_TYPE_OPEN_RESP = 0x0102,
69 FOCAS_FRAME_TYPE_CLOSE_REQ = 0x0201,
70 FOCAS_FRAME_TYPE_CLOSE_RESP = 0x0202,
71 FOCAS_FRAME_TYPE_COMMAND_REQ = 0x2101,
72 FOCAS_FRAME_TYPE_COMMAND_RESP = 0x2102
85#define FOCAS_CMD_READ_CNC_PARAM ((FocasCmd){1, 1, 0x0e})
86#define FOCAS_CMD_READ_MACRO ((FocasCmd){1, 1, 0x15})
87#define FOCAS_CMD_SET_MACRO ((FocasCmd){1, 1, 0x16})
88#define FOCAS_CMD_SYS_INFO ((FocasCmd){1, 1, 0x18})
89#define FOCAS_CMD_READ_ALARM ((FocasCmd){1, 1, 0x1a})
90#define FOCAS_CMD_READ_PRG_NUM ((FocasCmd){1, 1, 0x1c})
91#define FOCAS_CMD_READ_SEQ_NUM ((FocasCmd){1, 1, 0x1d})
92#define FOCAS_CMD_READ_ALARM_INFO ((FocasCmd){1, 1, 0x23})
93#define FOCAS_CMD_READ_FEEDRATE ((FocasCmd){1, 1, 0x24})
94#define FOCAS_CMD_READ_SPINDLE ((FocasCmd){1, 1, 0x25})
95#define FOCAS_CMD_READ_POSITION ((FocasCmd){1, 1, 0x26})
96#define FOCAS_CMD_READ_DIAG ((FocasCmd){1, 1, 0x30})
97#define FOCAS_CMD_READ_SPINDLE2 ((FocasCmd){1, 1, 0x40})
98#define FOCAS_CMD_READ_DATETIME ((FocasCmd){1, 1, 0x45})
99#define FOCAS_CMD_READ_SERVO_LOAD ((FocasCmd){1, 1, 0x56})
100#define FOCAS_CMD_READ_AXIS_NAMES ((FocasCmd){1, 1, 0x89})
101#define FOCAS_CMD_READ_SPINDLE_NAMES ((FocasCmd){1, 1, 0x8a})
102#define FOCAS_CMD_READ_CNC_PARAM3 ((FocasCmd){1, 1, 0x8d})
103#define FOCAS_CMD_READ_MACRO_DBL ((FocasCmd){1, 1, 0xa7})
104#define FOCAS_CMD_READ_PMC ((FocasCmd){2, 1, 0x8001})
107#define FOCAS_POS_MACHINE 1
108#define FOCAS_POS_ABSOLUTE 4
109#define FOCAS_POS_RELATIVE 6
110#define FOCAS_POS_DISTANCE 7
111#define FOCAS_POS_SKIP 8
118 const uint8_t *payload;
119 uint16_t payload_len;
161size_t protocore_focas_build_open(uint8_t *buf,
size_t cap);
164size_t protocore_focas_build_close(uint8_t *buf,
size_t cap);
167size_t protocore_focas_build_request(uint8_t *buf,
size_t cap, FocasCmd cmd, int32_t v1, int32_t v2, int32_t v3,
168 int32_t v4, int32_t v5,
const uint8_t *extra,
size_t extra_len);
171size_t protocore_focas_build_sysinfo(uint8_t *buf,
size_t cap);
174size_t protocore_focas_build_read_alarm(uint8_t *buf,
size_t cap);
177size_t protocore_focas_build_read_param(uint8_t *buf,
size_t cap, int32_t first, int32_t last, int32_t axis);
180size_t protocore_focas_build_read_macro(uint8_t *buf,
size_t cap, int32_t first, int32_t last);
183size_t protocore_focas_build_read_position(uint8_t *buf,
size_t cap, int32_t kind, int32_t axis);
186size_t protocore_focas_build_read_feedrate(uint8_t *buf,
size_t cap);
189size_t protocore_focas_build_read_spindle(uint8_t *buf,
size_t cap);
196proto_bool protocore_focas_parse_frame(
const uint8_t *buf,
size_t len, FocasFrame *out);
199proto_bool protocore_focas_parse_response(
const uint8_t *payload,
size_t payload_len, FocasResponse *out);
202proto_bool protocore_focas_parse_command_frame(
const uint8_t *buf,
size_t len, FocasResponse *out);
205proto_bool protocore_focas_parse_sysinfo(
const uint8_t *data,
size_t data_len, FocasSysInfo *out);
208proto_bool protocore_focas_parse_alarm(
const uint8_t *data,
size_t data_len, uint32_t *alarm_status);
212proto_bool protocore_focas_decode8(
const uint8_t *chunk,
size_t len, FocasValue *out);
215float protocore_focas_value_f(
const FocasValue *v);
PROTO_ENUM_PACKED
Application protocol spoken on a listener port or connection slot.
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
_Bool proto_bool
The truth value.
#define PROTOCORE_END_DECLS