Implement simple SDK API

This commit is contained in:
2023-02-21 14:25:48 -06:00
parent af5a6efdb3
commit d883385d8c
14 changed files with 485 additions and 235 deletions
+8 -4
View File
@@ -8,21 +8,25 @@
static const uint8_t CHASSIS_HOST = 3;
static const uint8_t CHASSIS_INDEX = 6;
static const uint16_t SET_WHEEL_SPEED_CMD = 0x203F;
#define SET_WHEEL_SPEED_CMD 0x203F
void
set_wheel_speed (
Client session,
union Request* req,
uint16_t seq,
bool ack,
int16_t w1,
int16_t w2,
int16_t w3,
int16_t w4 );
static const uint16_t CHASSIS_SPEED_MODE_CMD = 0x213F;
#define CHASSIS_SPEED_MODE_CMD 0x213F
void
chassis_speed_mode (
Client session,
union Request* req,
uint16_t seq,
bool ack,
float x,
float y,
float z );
+13
View File
@@ -0,0 +1,13 @@
#pragma once
struct Connection;
typedef Connection* Connection;
struct Connection*
conn_new (
struct Connection* connection,
unsigned int source_port,
const char* source_ip,
unsigned int dest_port,
const char* dest_ip );
extern const size_t SIZEOF_CONN;
+4 -59
View File
@@ -5,7 +5,10 @@
#define PACKED __attribute__((__packed__))
const uint8_t PREAMBLE = 0x55;
static const uint8_t CLIENT_HOST = 9;
static const uint8_t CLIENT_INDEX = 6;
static const uint8_t PREAMBLE = 0x55;
struct PACKED Header {
@@ -261,61 +264,3 @@ enum MESSAGEERR {
enum MESSAGEERR
message_validate(const union Message* message);
static inline uint8_t host2byte(uint8_t host, uint8_t index) {
return index * 32 + host;
}
static inline void byte2host(uint8_t b, uint8_t* host, uint8_t* index) {
*host = (b & 0x1F);
*index = b >> 5;
}
static
inline
size_t
message_length(uint16_t cmd) {
switch(cmd) {
case SET_SDK_CONNECTION_CMD:
return sizeof(struct SetSdkConnectionReq);
case SDK_HEARTBEAT_CMD:
return sizeof(struct SdkHeartbeatReq);
case SET_SDK_MODE_CMD:
return sizeof(struct SetSdkModeReq);
case SET_SYSTEM_LED_CMD:
return sizeof(struct SetSystemLedReq);
case SET_ROBOT_MODE_CMD:
return sizeof(struct SetRobotModeReq);
case SUBNODE_RESET_CMD:
return sizeof(struct SubNodeResetReq);
case SUBSCRIBE_ADD_NODE_CMD:
return sizeof(struct SubscribeAddNodeReq);
case SET_WHEEL_SPEED_CMD:
return sizeof(struct SetWheelSpeedReq);
case CHASSIS_SPEED_MODE_CMD:
return sizeof(struct ChassisSpeedModeReq);
default:
return 0;
}
}
static
inline
uint8_t
message_module(uint16_t cmd) {
switch(cmd) {
case SET_SDK_CONNECTION_CMD:
case SDK_HEARTBEAT_CMD:
case SET_SDK_MODE_CMD:
case SET_SYSTEM_LED_CMD:
case SET_ROBOT_MODE_CMD:
case SUBNODE_RESET_CMD:
case SUBSCRIBE_ADD_NODE_CMD:
return host2byte(SDK_HOST, SDK_INDEX);
case SET_WHEEL_SPEED_CMD:
case CHASSIS_SPEED_MODE_CMD:
return host2byte(CHASSIS_HOST, CHASSIS_INDEX);
default:
return 0;
}
}
+9
View File
@@ -12,3 +12,12 @@ Client client_new();
void client_connect(Client client);
void poll_message(Client client, union Message* message);
static inline uint8_t host2byte(uint8_t host, uint8_t index) {
return index * 32 + host;
}
static inline void byte2host(uint8_t b, uint8_t* host, uint8_t* index) {
*host = (b & 0x1F);
*index = b >> 5;
}
+30 -14
View File
@@ -8,7 +8,7 @@
static const uint8_t SDK_HOST = 9;
static const uint8_t SDK_INDEX = 0;
static const uint16_t SET_SDK_CONNECTION_CMD = 0xD43F;
#define SET_SDK_CONNECTION_CMD 0xD43F
enum CONNECTION {
CONNECTION_WIFI_AP = 0,
@@ -18,23 +18,31 @@ enum CONNECTION {
void
set_sdk_connection(
Client session,
union Request* req,
uint16_t seq,
bool ack,
enum CONNECTION connection_type,
uint32_t ip_address,
uint16_t port );
static const uint16_t SDK_HEARTBEAT_CMD = 0xD53F;
#define SDK_HEARTBEAT_CMD 0xD53F
void
sdk_heartbeat(
Client session );
union Request* req,
uint16_t seq,
bool ack );
static const uint16_t SET_SDK_MODE_CMD = 0xD13F;
#define SET_SDK_MODE_CMD 0xD13F
void
set_sdk_mode(Client session, bool enable);
set_sdk_mode(
union Request* req,
uint16_t seq,
bool ack,
bool enable );
static const uint16_t SET_SYSTEM_LED_CMD = 0x333F;
#define SET_SYSTEM_LED_CMD 0x333F
enum LEDCOMP {
LEDCOMP_BOTTOM_BACK = 0x1,
@@ -57,7 +65,9 @@ enum LEDEFFECT {
};
void set_system_led (
Client session,
union Request* req,
uint16_t seq,
bool ack,
uint8_t red,
uint8_t green,
uint8_t blue,
@@ -67,7 +77,7 @@ void set_system_led (
uint16_t t1,
uint16_t t2 );
static const uint16_t SET_ROBOT_MODE_CMD = 0x463F;
#define SET_ROBOT_MODE_CMD 0x463F
enum MOVEMENTMODE {
MOVEMENTMODE_FREE,
@@ -77,18 +87,24 @@ enum MOVEMENTMODE {
void
set_robot_mode (
Client session,
union Request* req,
uint16_t seq,
bool ack,
enum MOVEMENTMODE mode );
static const uint16_t SUBNODE_RESET_CMD = 0x0248;
#define SUBNODE_RESET_CMD 0x0248
void
subnode_reset (
Client session );
union Request* req,
uint16_t seq,
bool ack );
static const uint16_t SUBSCRIBE_ADD_NODE_CMD = 0x0148;
#define SUBSCRIBE_ADD_NODE_CMD 0x0148
void
subscribe_add_node (
Client session );
union Request* req,
uint16_t seq,
bool ack );