Skip to content

Commit

Permalink
Rpc: implement SystemFactoryReset (flipperdevices#890)
Browse files Browse the repository at this point in the history
* Rpc: update protobuf sources
* Rpc: implement SystemFactoryReset
  • Loading branch information
anna-oake authored and vvzvlad committed Dec 12, 2021
1 parent 2eb0aea commit d6395b5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
13 changes: 13 additions & 0 deletions applications/rpc/rpc_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "status.pb.h"

#include <furi-hal-info.h>
#include <furi-hal-bootloader.h>
#include <power/power_service/power.h>

void rpc_system_system_ping_process(const PB_Main* msg_request, void* context) {
Expand Down Expand Up @@ -98,6 +99,15 @@ void rpc_system_system_device_info_process(const PB_Main* request, void* context
free(response);
}

void rpc_system_system_factory_reset_process(const PB_Main* request, void* context) {
furi_assert(request);
furi_assert(request->which_content == PB_Main_system_factory_reset_request_tag);
furi_assert(context);

furi_hal_bootloader_set_flags(FuriHalBootloaderFlagFactoryReset);
power_reboot(PowerBootModeNormal);
}

void* rpc_system_system_alloc(Rpc* rpc) {
RpcHandler rpc_handler = {
.message_handler = NULL,
Expand All @@ -114,5 +124,8 @@ void* rpc_system_system_alloc(Rpc* rpc) {
rpc_handler.message_handler = rpc_system_system_device_info_process;
rpc_add_handler(rpc, PB_Main_system_device_info_request_tag, &rpc_handler);

rpc_handler.message_handler = rpc_system_system_factory_reset_process;
rpc_add_handler(rpc, PB_Main_system_factory_reset_request_tag, &rpc_handler);

return NULL;
}
6 changes: 5 additions & 1 deletion assets/compiled/flipper.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef struct _PB_Main {
PB_System_RebootRequest system_reboot_request;
PB_System_DeviceInfoRequest system_device_info_request;
PB_System_DeviceInfoResponse system_device_info_response;
PB_System_FactoryResetRequest system_factory_reset_request;
} content;
} PB_Main;

Expand Down Expand Up @@ -147,6 +148,7 @@ extern "C" {
#define PB_Main_system_reboot_request_tag 31
#define PB_Main_system_device_info_request_tag 32
#define PB_Main_system_device_info_response_tag 33
#define PB_Main_system_factory_reset_request_tag 34

/* Struct field encoding specification for nanopb */
#define PB_Empty_FIELDLIST(X, a) \
Expand Down Expand Up @@ -192,7 +194,8 @@ X(a, STATIC, ONEOF, MSG_W_CB, (content,storage_info_response,content.storag
X(a, STATIC, ONEOF, MSG_W_CB, (content,storage_rename_request,content.storage_rename_request), 30) \
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_reboot_request,content.system_reboot_request), 31) \
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_request,content.system_device_info_request), 32) \
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_response,content.system_device_info_response), 33)
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_response,content.system_device_info_response), 33) \
X(a, STATIC, ONEOF, MSG_W_CB, (content,system_factory_reset_request,content.system_factory_reset_request), 34)
#define PB_Main_CALLBACK NULL
#define PB_Main_DEFAULT NULL
#define PB_Main_content_empty_MSGTYPE PB_Empty
Expand Down Expand Up @@ -225,6 +228,7 @@ X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_response,content.
#define PB_Main_content_system_reboot_request_MSGTYPE PB_System_RebootRequest
#define PB_Main_content_system_device_info_request_MSGTYPE PB_System_DeviceInfoRequest
#define PB_Main_content_system_device_info_response_MSGTYPE PB_System_DeviceInfoResponse
#define PB_Main_content_system_factory_reset_request_MSGTYPE PB_System_FactoryResetRequest

extern const pb_msgdesc_t PB_Empty_msg;
extern const pb_msgdesc_t PB_StopSession_msg;
Expand Down
3 changes: 3 additions & 0 deletions assets/compiled/system.pb.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ PB_BIND(PB_System_DeviceInfoRequest, PB_System_DeviceInfoRequest, AUTO)
PB_BIND(PB_System_DeviceInfoResponse, PB_System_DeviceInfoResponse, AUTO)


PB_BIND(PB_System_FactoryResetRequest, PB_System_FactoryResetRequest, AUTO)




14 changes: 14 additions & 0 deletions assets/compiled/system.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ typedef struct _PB_System_DeviceInfoResponse {
char *value;
} PB_System_DeviceInfoResponse;

typedef struct _PB_System_FactoryResetRequest {
char dummy_field;
} PB_System_FactoryResetRequest;

typedef struct _PB_System_PingRequest {
pb_bytes_array_t *data;
} PB_System_PingRequest;
Expand Down Expand Up @@ -54,11 +58,13 @@ extern "C" {
#define PB_System_RebootRequest_init_default {_PB_System_RebootRequest_RebootMode_MIN}
#define PB_System_DeviceInfoRequest_init_default {0}
#define PB_System_DeviceInfoResponse_init_default {NULL, NULL}
#define PB_System_FactoryResetRequest_init_default {0}
#define PB_System_PingRequest_init_zero {NULL}
#define PB_System_PingResponse_init_zero {NULL}
#define PB_System_RebootRequest_init_zero {_PB_System_RebootRequest_RebootMode_MIN}
#define PB_System_DeviceInfoRequest_init_zero {0}
#define PB_System_DeviceInfoResponse_init_zero {NULL, NULL}
#define PB_System_FactoryResetRequest_init_zero {0}

/* Field tags (for use in manual encoding/decoding) */
#define PB_System_DeviceInfoResponse_key_tag 1
Expand Down Expand Up @@ -94,24 +100,32 @@ X(a, POINTER, SINGULAR, STRING, value, 2)
#define PB_System_DeviceInfoResponse_CALLBACK NULL
#define PB_System_DeviceInfoResponse_DEFAULT NULL

#define PB_System_FactoryResetRequest_FIELDLIST(X, a) \

#define PB_System_FactoryResetRequest_CALLBACK NULL
#define PB_System_FactoryResetRequest_DEFAULT NULL

extern const pb_msgdesc_t PB_System_PingRequest_msg;
extern const pb_msgdesc_t PB_System_PingResponse_msg;
extern const pb_msgdesc_t PB_System_RebootRequest_msg;
extern const pb_msgdesc_t PB_System_DeviceInfoRequest_msg;
extern const pb_msgdesc_t PB_System_DeviceInfoResponse_msg;
extern const pb_msgdesc_t PB_System_FactoryResetRequest_msg;

/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define PB_System_PingRequest_fields &PB_System_PingRequest_msg
#define PB_System_PingResponse_fields &PB_System_PingResponse_msg
#define PB_System_RebootRequest_fields &PB_System_RebootRequest_msg
#define PB_System_DeviceInfoRequest_fields &PB_System_DeviceInfoRequest_msg
#define PB_System_DeviceInfoResponse_fields &PB_System_DeviceInfoResponse_msg
#define PB_System_FactoryResetRequest_fields &PB_System_FactoryResetRequest_msg

/* Maximum encoded size of messages (where known) */
/* PB_System_PingRequest_size depends on runtime parameters */
/* PB_System_PingResponse_size depends on runtime parameters */
/* PB_System_DeviceInfoResponse_size depends on runtime parameters */
#define PB_System_DeviceInfoRequest_size 0
#define PB_System_FactoryResetRequest_size 0
#define PB_System_RebootRequest_size 2

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion assets/protobuf
Submodule protobuf updated 2 files
+1 −0 flipper.proto
+3 −0 system.proto

0 comments on commit d6395b5

Please sign in to comment.