48 lines
1.1 KiB
C
48 lines
1.1 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include "esp_err.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum {
|
|
ROBOT_CMD_UP = 0,
|
|
ROBOT_CMD_DOWN,
|
|
ROBOT_CMD_LEFT,
|
|
ROBOT_CMD_RIGHT,
|
|
ROBOT_CMD_STOP,
|
|
ROBOT_CMD_INVALID,
|
|
} robot_cmd_dir_t;
|
|
|
|
typedef struct {
|
|
bool ok;
|
|
uint32_t seq;
|
|
const char *type; /* "cmd" or "msg" */
|
|
const char *dir; /* for cmd */
|
|
const char *text; /* for msg */
|
|
const char *fwd; /* "ack" now; later "i2c" / "fail" */
|
|
const char *error; /* set when ok=false */
|
|
} robot_ack_t;
|
|
|
|
void robot_link_init(void);
|
|
|
|
robot_cmd_dir_t robot_link_parse_dir(const char *dir);
|
|
|
|
/* Accept a drive command. Fills ack; does not yet talk to RP2040. */
|
|
esp_err_t robot_link_handle_cmd(const char *dir, robot_ack_t *ack);
|
|
|
|
/* Accept a free-text message. Fills ack; does not yet talk to RP2040. */
|
|
esp_err_t robot_link_handle_msg(const char *text, size_t len, robot_ack_t *ack);
|
|
|
|
/* Format ack as a compact JSON object into buf. Returns bytes written (excl NUL). */
|
|
int robot_link_format_ack(const robot_ack_t *ack, char *buf, size_t buflen);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|