33#ifndef PROTOCORE_SIMATIC_H
34#define PROTOCORE_SIMATIC_H
38#if PROTOCORE_ENABLE_SIMATIC
47#define SIMATIC_STX 0x02
48#define SIMATIC_DLE 0x10
49#define SIMATIC_ETX 0x03
50#define SIMATIC_NAK 0x15
53#define SIMATIC_MAX_BLOCK_RETRY 6
54#define SIMATIC_MAX_CONN_RETRY 6
59 SIMATIC3964_STATE_IDLE,
60 SIMATIC3964_STATE_TX_AWAIT_CONN,
61 SIMATIC3964_STATE_TX_AWAIT_END,
62 SIMATIC3964_STATE_RX_COLLECT
66typedef void (*Simatic3964TxFn)(
void *user, uint8_t byte);
69typedef void (*Simatic3964RxFn)(
void *user,
const uint8_t *data,
size_t len);
77 Simatic3964State state;
89 uint8_t block_retries;
99 RK512_CMD_SEND = 0x00,
100 RK512_CMD_FETCH = 0x01,
101 RK512_CMD_REACTION = 0x02
107 RK512_AREA_DB = 0x01,
108 RK512_AREA_DX = 0x02,
109 RK512_AREA_MB = 0x03,
110 RK512_AREA_EB = 0x04,
111 RK512_AREA_AB = 0x05,
112 RK512_AREA_PB = 0x06,
113 RK512_AREA_ZB = 0x07,
132} SimaticBcc3964rArgs;
142} SimaticBuildBlock3964rArgs;
153} SimaticParseBlock3964rArgs;
164} SimaticInit3964rArgs;
173} SimaticSend3964rArgs;
181} SimaticRxByte3964rArgs;
188} SimaticTick3964rArgs;
193 const Simatic3964Ctx *ctx;
194} SimaticIdle3964rArgs;
204 const uint16_t *words;
206} SimaticBuildSendRk512Args;
217} SimaticBuildFetchRk512Args;
225} SimaticBuildReactionRk512Args;
233} SimaticParseHeaderRk512Args;
241 const uint8_t **data;
243} SimaticParseReactionRk512Args;
292 SimaticBcc3964rArgs bcc_3964r_args;
293 SimaticBuildBlock3964rArgs build_block_3964r_args;
294 SimaticParseBlock3964rArgs parse_block_3964r_args;
295 SimaticInit3964rArgs init_3964r_args;
296 SimaticSend3964rArgs send_3964r_args;
297 SimaticRxByte3964rArgs rx_byte_3964r_args;
298 SimaticTick3964rArgs tick_3964r_args;
299 SimaticIdle3964rArgs idle_3964r_args;
300 SimaticBuildSendRk512Args build_send_rk512_args;
301 SimaticBuildFetchRk512Args build_fetch_rk512_args;
302 SimaticBuildReactionRk512Args build_reaction_rk512_args;
303 SimaticParseHeaderRk512Args parse_header_rk512_args;
304 SimaticParseReactionRk512Args parse_reaction_rk512_args;
311extern SimaticVars SimaticV;
316 void (*
const bcc_3964r)(uint8_t *work);
317 void (*
const build_block_3964r)(uint8_t *work);
318 void (*
const parse_block_3964r)(uint8_t *work);
319 void (*
const init_3964r)(uint8_t *work);
320 void (*
const send_3964r)(uint8_t *work);
321 void (*
const rx_byte_3964r)(uint8_t *work);
322 void (*
const tick_3964r)(uint8_t *work);
323 void (*
const idle_3964r)(uint8_t *work);
324 void (*
const build_send_rk512)(uint8_t *work);
325 void (*
const build_fetch_rk512)(uint8_t *work);
326 void (*
const build_reaction_rk512)(uint8_t *work);
327 void (*
const parse_header_rk512)(uint8_t *work);
328 void (*
const parse_reaction_rk512)(uint8_t *work);
333void protocore_simatic_bcc_3964r(uint8_t *work);
334void protocore_simatic_build_block_3964r(uint8_t *work);
335void protocore_simatic_parse_block_3964r(uint8_t *work);
336void protocore_simatic_init_3964r(uint8_t *work);
337void protocore_simatic_send_3964r(uint8_t *work);
338void protocore_simatic_rx_byte_3964r(uint8_t *work);
339void protocore_simatic_tick_3964r(uint8_t *work);
340void protocore_simatic_idle_3964r(uint8_t *work);
341void protocore_simatic_build_send_rk512(uint8_t *work);
342void protocore_simatic_build_fetch_rk512(uint8_t *work);
343void protocore_simatic_build_reaction_rk512(uint8_t *work);
344void protocore_simatic_parse_header_rk512(uint8_t *work);
345void protocore_simatic_parse_reaction_rk512(uint8_t *work);
351static const SimaticNs Simatic __attribute__((unused)) = {
352 .bcc_3964r = protocore_simatic_bcc_3964r,
353 .build_block_3964r = protocore_simatic_build_block_3964r,
354 .parse_block_3964r = protocore_simatic_parse_block_3964r,
355 .init_3964r = protocore_simatic_init_3964r,
356 .send_3964r = protocore_simatic_send_3964r,
357 .rx_byte_3964r = protocore_simatic_rx_byte_3964r,
358 .tick_3964r = protocore_simatic_tick_3964r,
359 .idle_3964r = protocore_simatic_idle_3964r,
360 .build_send_rk512 = protocore_simatic_build_send_rk512,
361 .build_fetch_rk512 = protocore_simatic_build_fetch_rk512,
362 .build_reaction_rk512 = protocore_simatic_build_reaction_rk512,
363 .parse_header_rk512 = protocore_simatic_parse_header_rk512,
364 .parse_reaction_rk512 = protocore_simatic_parse_reaction_rk512,
376uint8_t *protocore_simatic_span(
void);
PROTO_ENUM_PACKED
Application protocol spoken on a listener port or connection slot.
#define PROTOCORE_SIMATIC_BLOCK_MAX
3964R block-body buffer size (built/received bytes: DLE-stuffed payload + DLE ETX + BCC).
#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