RPC: Add data field to ping request & response (#836)

* Update protobuf
* Send ping data back
* Add check for has_next, more readability
* Fix nullptr dereference

Co-authored-by: Tony Freeman <tonyfreeman@users.noreply.github.com>
Co-authored-by: Albert Kharisov <albkharisov@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
tonyfreeman 2021-11-23 11:30:54 +03:00 committed by GitHub
parent 949079cb74
commit e54e4a6d77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 14 deletions

View File

@ -3,14 +3,27 @@
#include "status.pb.h" #include "status.pb.h"
void rpc_system_status_ping_process(const PB_Main* msg_request, void* context) { void rpc_system_status_ping_process(const PB_Main* msg_request, void* context) {
if(msg_request->has_next) {
rpc_send_and_release_empty(
context, msg_request->command_id, PB_CommandStatus_ERROR_INVALID_PARAMETERS);
return;
}
PB_Main msg_response = PB_Main_init_default; PB_Main msg_response = PB_Main_init_default;
msg_response.has_next = false; msg_response.has_next = false;
msg_response.command_status = PB_CommandStatus_OK; msg_response.command_status = PB_CommandStatus_OK;
msg_response.command_id = msg_request->command_id; msg_response.command_id = msg_request->command_id;
msg_response.which_content = PB_Main_ping_response_tag; msg_response.which_content = PB_Main_ping_response_tag;
const PB_Status_PingRequest* request = &msg_request->content.ping_request;
PB_Status_PingResponse* response = &msg_response.content.ping_response;
if(request->data && (request->data->size > 0)) {
response->data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(request->data->size));
memcpy(response->data->bytes, request->data->bytes, request->data->size);
response->data->size = request->data->size;
}
rpc_send_and_release(context, &msg_response); rpc_send_and_release(context, &msg_response);
pb_release(&PB_Main_msg, &msg_response);
} }
void* rpc_system_status_alloc(Rpc* rpc) { void* rpc_system_status_alloc(Rpc* rpc) {

View File

@ -214,9 +214,9 @@ extern const pb_msgdesc_t PB_Main_msg;
/* Maximum encoded size of messages (where known) */ /* Maximum encoded size of messages (where known) */
#define PB_Empty_size 0 #define PB_Empty_size 0
#define PB_StopSession_size 0 #define PB_StopSession_size 0
#if defined(PB_Storage_ListRequest_size) && defined(PB_Storage_ListResponse_size) && defined(PB_Storage_ReadRequest_size) && defined(PB_Storage_ReadResponse_size) && defined(PB_Storage_WriteRequest_size) && defined(PB_Storage_DeleteRequest_size) && defined(PB_Storage_MkdirRequest_size) && defined(PB_Storage_Md5sumRequest_size) && defined(PB_App_StartRequest_size) && defined(PB_Gui_ScreenFrame_size) && defined(PB_Storage_StatRequest_size) && defined(PB_Storage_StatResponse_size) #if defined(PB_Status_PingRequest_size) && defined(PB_Status_PingResponse_size) && defined(PB_Storage_ListRequest_size) && defined(PB_Storage_ListResponse_size) && defined(PB_Storage_ReadRequest_size) && defined(PB_Storage_ReadResponse_size) && defined(PB_Storage_WriteRequest_size) && defined(PB_Storage_DeleteRequest_size) && defined(PB_Storage_MkdirRequest_size) && defined(PB_Storage_Md5sumRequest_size) && defined(PB_App_StartRequest_size) && defined(PB_Gui_ScreenFrame_size) && defined(PB_Storage_StatRequest_size) && defined(PB_Storage_StatResponse_size)
#define PB_Main_size (10 + sizeof(union PB_Main_content_size_union)) #define PB_Main_size (10 + sizeof(union PB_Main_content_size_union))
union PB_Main_content_size_union {char f7[(6 + PB_Storage_ListRequest_size)]; char f8[(6 + PB_Storage_ListResponse_size)]; char f9[(6 + PB_Storage_ReadRequest_size)]; char f10[(6 + PB_Storage_ReadResponse_size)]; char f11[(6 + PB_Storage_WriteRequest_size)]; char f12[(6 + PB_Storage_DeleteRequest_size)]; char f13[(6 + PB_Storage_MkdirRequest_size)]; char f14[(6 + PB_Storage_Md5sumRequest_size)]; char f16[(7 + PB_App_StartRequest_size)]; char f22[(7 + PB_Gui_ScreenFrame_size)]; char f24[(7 + PB_Storage_StatRequest_size)]; char f25[(7 + PB_Storage_StatResponse_size)]; char f0[36];}; union PB_Main_content_size_union {char f5[(6 + PB_Status_PingRequest_size)]; char f6[(6 + PB_Status_PingResponse_size)]; char f7[(6 + PB_Storage_ListRequest_size)]; char f8[(6 + PB_Storage_ListResponse_size)]; char f9[(6 + PB_Storage_ReadRequest_size)]; char f10[(6 + PB_Storage_ReadResponse_size)]; char f11[(6 + PB_Storage_WriteRequest_size)]; char f12[(6 + PB_Storage_DeleteRequest_size)]; char f13[(6 + PB_Storage_MkdirRequest_size)]; char f14[(6 + PB_Storage_Md5sumRequest_size)]; char f16[(7 + PB_App_StartRequest_size)]; char f22[(7 + PB_Gui_ScreenFrame_size)]; char f24[(7 + PB_Storage_StatRequest_size)]; char f25[(7 + PB_Storage_StatResponse_size)]; char f0[36];};
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -11,11 +11,11 @@
/* Struct definitions */ /* Struct definitions */
typedef struct _PB_Status_PingRequest { typedef struct _PB_Status_PingRequest {
char dummy_field; pb_bytes_array_t *data;
} PB_Status_PingRequest; } PB_Status_PingRequest;
typedef struct _PB_Status_PingResponse { typedef struct _PB_Status_PingResponse {
char dummy_field; pb_bytes_array_t *data;
} PB_Status_PingResponse; } PB_Status_PingResponse;
@ -24,21 +24,23 @@ extern "C" {
#endif #endif
/* Initializer values for message structs */ /* Initializer values for message structs */
#define PB_Status_PingRequest_init_default {0} #define PB_Status_PingRequest_init_default {NULL}
#define PB_Status_PingResponse_init_default {0} #define PB_Status_PingResponse_init_default {NULL}
#define PB_Status_PingRequest_init_zero {0} #define PB_Status_PingRequest_init_zero {NULL}
#define PB_Status_PingResponse_init_zero {0} #define PB_Status_PingResponse_init_zero {NULL}
/* Field tags (for use in manual encoding/decoding) */ /* Field tags (for use in manual encoding/decoding) */
#define PB_Status_PingRequest_data_tag 1
#define PB_Status_PingResponse_data_tag 1
/* Struct field encoding specification for nanopb */ /* Struct field encoding specification for nanopb */
#define PB_Status_PingRequest_FIELDLIST(X, a) \ #define PB_Status_PingRequest_FIELDLIST(X, a) \
X(a, POINTER, SINGULAR, BYTES, data, 1)
#define PB_Status_PingRequest_CALLBACK NULL #define PB_Status_PingRequest_CALLBACK NULL
#define PB_Status_PingRequest_DEFAULT NULL #define PB_Status_PingRequest_DEFAULT NULL
#define PB_Status_PingResponse_FIELDLIST(X, a) \ #define PB_Status_PingResponse_FIELDLIST(X, a) \
X(a, POINTER, SINGULAR, BYTES, data, 1)
#define PB_Status_PingResponse_CALLBACK NULL #define PB_Status_PingResponse_CALLBACK NULL
#define PB_Status_PingResponse_DEFAULT NULL #define PB_Status_PingResponse_DEFAULT NULL
@ -50,8 +52,8 @@ extern const pb_msgdesc_t PB_Status_PingResponse_msg;
#define PB_Status_PingResponse_fields &PB_Status_PingResponse_msg #define PB_Status_PingResponse_fields &PB_Status_PingResponse_msg
/* Maximum encoded size of messages (where known) */ /* Maximum encoded size of messages (where known) */
#define PB_Status_PingRequest_size 0 /* PB_Status_PingRequest_size depends on runtime parameters */
#define PB_Status_PingResponse_size 0 /* PB_Status_PingResponse_size depends on runtime parameters */
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

@ -1 +1 @@
Subproject commit 6be7def6087c4d277386381ff2792fa622933668 Subproject commit 060aead10b80622975b14a077420354d26e0be38