Change Session to Client

refactor
PgSocks 2 years ago
parent d4e1817793
commit c1bb243211

@ -4,8 +4,8 @@
#include "robomaster.h" #include "robomaster.h"
struct Session* session_new(void* buffer, size_t size) { struct Client* session_new(void* buffer, size_t size) {
struct Session* session = malloc(sizeof(struct Session*)); struct Client* session = malloc(sizeof(struct Client*));
if(!buffer) if(!buffer)
session->buffer = malloc(sizeof(struct Header)); session->buffer = malloc(sizeof(struct Header));
else else
@ -18,13 +18,9 @@ struct Session* session_new(void* buffer, size_t size) {
return session; return session;
} }
size_t session_size(Session session) {
return session->size;
}
// private // private
struct Message* struct Message*
message_new(struct Session* session, uint8_t cmdset, uint8_t cmdid, size_t length, const void* body) { message_new(struct Client* session, uint8_t cmdset, uint8_t cmdid, size_t length, const void* body) {
struct Message* message = session->buffer + session->size; struct Message* message = session->buffer + session->size;
memcpy((void*)message->body, body, length); memcpy((void*)message->body, body, length);
@ -54,7 +50,7 @@ message_new(struct Session* session, uint8_t cmdset, uint8_t cmdid, size_t lengt
// public // public
const Message const Message
set_sdk_connection_req_new ( set_sdk_connection_req_new (
Session session, Client session,
struct SetSdkConnectionReq* msg ) { struct SetSdkConnectionReq* msg ) {
msg->host = session->hostbyte; msg->host = session->hostbyte;
@ -64,7 +60,7 @@ set_sdk_connection_req_new (
const Message const Message
set_system_led_req_new ( set_system_led_req_new (
Session session, Client session,
struct SetSystemLedReq* msg ) { struct SetSystemLedReq* msg ) {
return message_new(session, 0x3F, SET_SYSTEM_LED_CMDID, sizeof(struct SetSystemLedReq), msg); return message_new(session, 0x3F, SET_SYSTEM_LED_CMDID, sizeof(struct SetSystemLedReq), msg);
} }

@ -73,7 +73,7 @@ struct PACKED Footer {
}; };
// TODO: Rename to Client // TODO: Rename to Client
struct Session { struct Client {
void* buffer; void* buffer;
size_t max_size; size_t max_size;
@ -85,15 +85,13 @@ struct Session {
}; };
struct Message* message_new(struct Session* session, uint8_t cmdset, uint8_t cmdid, size_t length, const void* body); struct Message* message_new(struct Client* session, uint8_t cmdset, uint8_t cmdid, size_t length, const void* body);
// Public stuff // Public stuff
typedef struct Session* Session; typedef struct Client* Client;
typedef struct Message* Message; typedef struct Message* Message;
Session session_new(void* buffer, size_t size); Client client_new(void* buffer, size_t size);
size_t session_size(Session session);
static const uint8_t CONNECTION_WIFI_AP = 0; static const uint8_t CONNECTION_WIFI_AP = 0;
static const uint8_t CONNECTION_WIFI_STA = 1; static const uint8_t CONNECTION_WIFI_STA = 1;
@ -132,7 +130,7 @@ struct PACKED SetSdkConnectionResp {
uint32_t config_ip; uint32_t config_ip;
}; };
const Message set_sdk_connection_req_new(Session session, struct SetSdkConnectionReq* msg); const Message set_sdk_connection_req_new(Client session, struct SetSdkConnectionReq* msg);
static const uint8_t GET_VERSION_CMDID = 0x01; static const uint8_t GET_VERSION_CMDID = 0x01;
@ -146,7 +144,7 @@ struct PACKED GetVersionResp {
uint8_t dd; uint8_t dd;
}; };
const Message get_version_req_new(Session session); const Message get_version_req_new(Client session);
static const uint8_t SET_SYSTEM_LED_CMDID = 0x33; static const uint8_t SET_SYSTEM_LED_CMDID = 0x33;
@ -189,4 +187,4 @@ struct PACKED SetSystemLedResp {
uint8_t retcode; uint8_t retcode;
}; };
const Message set_system_led_req_new(Session session, struct SetSystemLedReq* msg); const Message set_system_led_req_new(Client session, struct SetSystemLedReq* msg);

@ -9,7 +9,7 @@ uint8_t recvbuff[1024] = {0};
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
Session session = session_new(buffer, sizeof(buffer)); Client session = session_new(buffer, sizeof(buffer));
struct SetSdkConnectionReq req = {0}; struct SetSdkConnectionReq req = {0};
req.control = 0; req.control = 0;
req.host = 0; req.host = 0;

Loading…
Cancel
Save