diff --git a/src/robomaster.c b/src/robomaster.c index f7f87a9..6dfbd1b 100644 --- a/src/robomaster.c +++ b/src/robomaster.c @@ -4,8 +4,8 @@ #include "robomaster.h" -struct Session* session_new(void* buffer, size_t size) { - struct Session* session = malloc(sizeof(struct Session*)); +struct Client* session_new(void* buffer, size_t size) { + struct Client* session = malloc(sizeof(struct Client*)); if(!buffer) session->buffer = malloc(sizeof(struct Header)); else @@ -18,13 +18,9 @@ struct Session* session_new(void* buffer, size_t size) { return session; } -size_t session_size(Session session) { - return session->size; -} - // private 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; 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 const Message set_sdk_connection_req_new ( - Session session, + Client session, struct SetSdkConnectionReq* msg ) { msg->host = session->hostbyte; @@ -64,7 +60,7 @@ set_sdk_connection_req_new ( const Message set_system_led_req_new ( - Session session, + Client session, struct SetSystemLedReq* msg ) { return message_new(session, 0x3F, SET_SYSTEM_LED_CMDID, sizeof(struct SetSystemLedReq), msg); } diff --git a/src/robomaster.h b/src/robomaster.h index ca4db06..075d3e7 100644 --- a/src/robomaster.h +++ b/src/robomaster.h @@ -73,7 +73,7 @@ struct PACKED Footer { }; // TODO: Rename to Client -struct Session { +struct Client { void* buffer; 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 -typedef struct Session* Session; +typedef struct Client* Client; typedef struct Message* Message; -Session session_new(void* buffer, size_t size); - -size_t session_size(Session session); +Client client_new(void* buffer, size_t size); static const uint8_t CONNECTION_WIFI_AP = 0; static const uint8_t CONNECTION_WIFI_STA = 1; @@ -132,7 +130,7 @@ struct PACKED SetSdkConnectionResp { 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; @@ -146,7 +144,7 @@ struct PACKED GetVersionResp { 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; @@ -189,4 +187,4 @@ struct PACKED SetSystemLedResp { 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); diff --git a/src/robomastersh.c b/src/robomastersh.c index de279c3..5c35d6f 100644 --- a/src/robomastersh.c +++ b/src/robomastersh.c @@ -9,7 +9,7 @@ uint8_t recvbuff[1024] = {0}; int main(int argc, char* argv[]) { - Session session = session_new(buffer, sizeof(buffer)); + Client session = session_new(buffer, sizeof(buffer)); struct SetSdkConnectionReq req = {0}; req.control = 0; req.host = 0;