diff --git a/src/robomaster.c b/src/robomaster.c index 6c08b74..520c554 100644 --- a/src/robomaster.c +++ b/src/robomaster.c @@ -49,13 +49,21 @@ message_new(struct Client* session, uint8_t cmdset, uint8_t cmdid, size_t length // public const Message -set_sdk_connection_req_new ( +set_sdk_connection_req_new( Client session, - struct SetSdkConnectionReq* msg ) { + enum CONNECTION connection_type, + uint32_t ip_address, + uint16_t port ) { - msg->host = session->hostbyte; - struct Message* message = message_new(session, 0x3F, SET_SDK_CONNECTION_CMDID, sizeof(struct SetSdkConnectionReq), msg); - return message; + const struct SetSdkConnectionReq msg = { + 0, + session->hostbyte, + connection_type, + 0, + ip_address, + port + }; + return message_new(session, 0x3F, SET_SDK_CONNECTION_CMDID, sizeof(msg), &msg); } const Message diff --git a/src/robomaster.h b/src/robomaster.h index dcb8299..2bf6e18 100644 --- a/src/robomaster.h +++ b/src/robomaster.h @@ -93,10 +93,6 @@ typedef struct Message* Message; Client client_new(void* buffer, size_t size); -static const uint8_t CONNECTION_WIFI_AP = 0; -static const uint8_t CONNECTION_WIFI_STA = 1; -static const uint8_t CONNECTION_USB_RNDIS = 2; - // Not sure what these are for, but they are used for the hostbyte static const uint8_t DEFAULT_CLIENT_HOST = 9; static const uint8_t DEFAULT_CLIENT_INDEX = 6; @@ -115,6 +111,12 @@ static inline void byte2host(uint8_t b, uint8_t* host, uint8_t* index) { static const uint8_t SET_SDK_CONNECTION_CMDID = 0xD4; +enum CONNECTION { + CONNECTION_WIFI_AP = 0, + CONNECTION_WIFI_STA = 1, + CONNECTION_USB_RNDIS = 2 +} + struct PACKED SetSdkConnectionReq { uint8_t control; uint8_t host; @@ -130,7 +132,11 @@ struct PACKED SetSdkConnectionResp { uint32_t config_ip; }; -const Message set_sdk_connection_req_new(Client session, struct SetSdkConnectionReq* msg); +const Message set_sdk_connection_req_new( + Client session, + enum CONNECTION connection_type, + uint32_t ip_address, + uint16_t port ); static const uint8_t GET_VERSION_CMDID = 0x01;