Refactor for public API
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "message.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t SET_SYSTEM_LED_CMDID = 0x33;
|
||||
|
||||
enum LEDCOMP {
|
||||
LEDCOMP_BOTTOM_BACK = 0x1,
|
||||
LEDCOMP_BOTTOM_FRONT = 0x2,
|
||||
LEDCOMP_BOTTOM_LEFT = 0x4,
|
||||
LEDCOMP_BOTTOM_RIGHT = 0x8,
|
||||
LEDCOMP_BOTTOM_ALL = 0xf,
|
||||
LEDCOMP_TOP_LEFT = 0x10,
|
||||
LEDCOMP_TOP_RIGHT = 0x20,
|
||||
LEDCOMP_TOP_ALL = 0x30,
|
||||
LEDCOMP_ALL = 0x3f
|
||||
};
|
||||
|
||||
enum LEDEFFECT {
|
||||
LEDEFFECT_OFF = 0,
|
||||
LEDEFFECT_ON = 1,
|
||||
LEDEFFECT_BREATH = 2,
|
||||
LEDEFFECT_FLASH = 3,
|
||||
LEDEFFECT_SCROLLING = 4
|
||||
};
|
||||
|
||||
void set_system_led (
|
||||
Client session,
|
||||
uint8_t red,
|
||||
uint8_t green,
|
||||
uint8_t blue,
|
||||
enum LEDCOMP comp,
|
||||
uint16_t led_mask,
|
||||
enum LEDEFFECT effect,
|
||||
uint16_t t1,
|
||||
uint16_t t2 );
|
||||
@@ -0,0 +1,167 @@
|
||||
#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 SetSdkModeReq 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);
|
||||
+14
-9
@@ -1,17 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Public stuff
|
||||
struct Message;
|
||||
struct Client;
|
||||
typedef struct Client* Client;
|
||||
typedef struct Message* Message;
|
||||
|
||||
Client client_new(void* buffer, size_t size);
|
||||
#include "message.h"
|
||||
#include "led.h"
|
||||
#include "sdk_connection.h"
|
||||
#include "sdk_mode.h"
|
||||
#include "wheel.h"
|
||||
|
||||
// SIMPLE
|
||||
// Create a client
|
||||
// Connect to a drone
|
||||
// Send messages
|
||||
// Poll for responses
|
||||
|
||||
Client client_new();
|
||||
void client_connect(Client client);
|
||||
Message poll_message(Client client);
|
||||
void poll_message(Client client, union Message* message);
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "message.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t SET_SDK_CONNECTION_CMDID = 0xD4;
|
||||
|
||||
enum CONNECTION {
|
||||
CONNECTION_WIFI_AP = 0,
|
||||
CONNECTION_WIFI_STA = 1,
|
||||
CONNECTION_USB_RNDIS = 2
|
||||
};
|
||||
|
||||
void
|
||||
set_sdk_connection(
|
||||
Client session,
|
||||
enum CONNECTION connection_type,
|
||||
uint32_t ip_address,
|
||||
uint16_t port );
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "message.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t SET_SDK_MODE_CMDID = 0xd1;
|
||||
|
||||
void
|
||||
set_sdk_mode(Client session, bool enable);
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "message.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t SET_WHEEL_SPEED_CMDID = 0x20;
|
||||
|
||||
void
|
||||
set_wheel_speed (
|
||||
Client session,
|
||||
int16_t w1,
|
||||
int16_t w2,
|
||||
int16_t w3,
|
||||
int16_t w4 );
|
||||
Reference in New Issue
Block a user