You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
3.3 KiB
C
168 lines
3.3 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#define PACKED __attribute__((__packed__))
|
|
|
|
struct PACKED Header {
|
|
|
|
// The preamble marks the start of a message and is always 0x55
|
|
uint8_t preamble;
|
|
|
|
// The length of the message includes the preamble and CRC16 at the end
|
|
union {
|
|
uint16_t length;
|
|
struct {
|
|
uint8_t length_l;
|
|
uint8_t length_h;
|
|
};
|
|
};
|
|
|
|
// This is a CRC8 checksum for the preamble and length together
|
|
uint8_t crc;
|
|
|
|
// hostbyte of the message sender
|
|
uint8_t sender;
|
|
|
|
// hostbyte of the message receiver
|
|
uint8_t receiver;
|
|
|
|
// Each message has a sequence ID
|
|
// The Robomaster will respond with the same ID for each request
|
|
// The value of the sequence ID doesn't matter to the Robomaster
|
|
// Repeating sequence IDs are acceptable
|
|
int16_t seq_id;
|
|
|
|
// The message attribute flags designate if a response is needed or if the
|
|
// message is a response.
|
|
union {
|
|
uint8_t attribute;
|
|
struct {
|
|
uint8_t reserved : 6;
|
|
bool ack_needed : 1;
|
|
bool is_ack : 1;
|
|
};
|
|
};
|
|
|
|
// Each command has a cmdset and cmdid that together make a cmd key
|
|
uint8_t cmdset;
|
|
uint8_t cmdid;
|
|
|
|
};
|
|
|
|
struct PACKED Footer {
|
|
uint16_t crc;
|
|
};
|
|
|
|
struct PACKED SetSystemLedReq {
|
|
|
|
struct Header header;
|
|
|
|
// Which LEDs on which component to control
|
|
uint32_t comp_mask;
|
|
uint16_t led_mask;
|
|
|
|
struct {
|
|
// off, on, flashing, etc.
|
|
uint8_t effect_mode : 4;
|
|
// Always 7
|
|
uint8_t control_mode : 4;
|
|
};
|
|
|
|
// RGB values for the LED color
|
|
uint8_t red;
|
|
uint8_t green;
|
|
uint8_t blue;
|
|
|
|
// Always 0
|
|
uint8_t loop;
|
|
|
|
// These time intervals have different meaning depending on effect
|
|
uint16_t t1;
|
|
uint16_t t2;
|
|
|
|
struct Footer footer;
|
|
|
|
};
|
|
|
|
struct PACKED SetSystemLedResp {
|
|
struct Header header;
|
|
uint8_t retcode;
|
|
struct Footer footer;
|
|
};
|
|
|
|
struct PACKED SetWheelSpeedReq
|
|
{
|
|
struct Header header;
|
|
int16_t wheel_speed[4];
|
|
struct Footer footer;
|
|
};
|
|
|
|
struct PACKED SetWheelSpeedResp
|
|
{
|
|
struct Header header;
|
|
int8_t retcode;
|
|
struct Footer footer;
|
|
};
|
|
|
|
struct PACKED SetSdkModeReq {
|
|
struct Header header;
|
|
uint8_t enable;
|
|
struct Footer footer;
|
|
};
|
|
|
|
struct PACKED SetSdkModeResp {
|
|
struct Header header;
|
|
uint8_t retcode;
|
|
struct Footer footer;
|
|
};
|
|
|
|
struct PACKED SetSdkConnectionReq {
|
|
struct Header header;
|
|
uint8_t control;
|
|
uint8_t host;
|
|
uint8_t connection;
|
|
uint8_t protocol;
|
|
uint32_t ip_address;
|
|
uint16_t port;
|
|
struct Footer footer;
|
|
};
|
|
|
|
struct PACKED SetSdkConnectionResp {
|
|
struct Header header;
|
|
uint8_t retcode;
|
|
uint8_t state;
|
|
uint32_t config_ip;
|
|
struct Footer footer;
|
|
};
|
|
|
|
union Request {
|
|
struct Header header;
|
|
struct SetSdkConnectionReq sdkconn;
|
|
struct SetSdkModeReq sdkmode;
|
|
struct SetSystemLedReq led;
|
|
struct SetWheelSpeedReq wheel;
|
|
};
|
|
union Response {
|
|
struct Header header;
|
|
struct SetSdkConnectionResp sdkconn;
|
|
struct SetSdkModeResp sdkmode;
|
|
struct SetSystemLedResp led;
|
|
struct SetWheelSpeedResp wheel;
|
|
};
|
|
union Message {
|
|
struct Header header;
|
|
union Request req;
|
|
union Response resp;
|
|
};
|
|
|
|
enum MESSAGEERR {
|
|
MESSAGEERR_NONE,
|
|
MESSAGEERR_HEADERCRC,
|
|
MESSAGEERR_FOOTERCRC
|
|
};
|
|
|
|
enum MESSAGEERR
|
|
message_validate(const union Message* message);
|