feat(wt_system api): get fm_ver and software reboot
This commit is contained in:
parent
b5a4b38c8d
commit
3386a56024
|
@ -7,7 +7,5 @@ sdkconfig
|
|||
.idea/
|
||||
dependencies.lock
|
||||
package-lock.json
|
||||
**/priv_note.md
|
||||
_priv_tools/
|
||||
project_components/wifi_manager/wifi_configuration.h
|
||||
managed_components/
|
||||
managed_components/
|
||||
version.txt
|
|
@ -370,10 +370,10 @@ __STATIC_INLINE uint8_t DAP_GetProductFirmwareVersionString (char *str) {
|
|||
#define PIN_SWDIO _ // SPI MISO
|
||||
#define PIN_SWDIO_MOSI 7 // SPI MOSI
|
||||
#define PIN_SWCLK 6
|
||||
#define PIN_TDO 8 // device TDO -> Host Data Input
|
||||
#define PIN_TDI 9
|
||||
#define PIN_TDO 3 // device TDO -> Host Data Input
|
||||
#define PIN_TDI 5
|
||||
#define PIN_nTRST 4 // optional
|
||||
#define PIN_nRESET 5
|
||||
#define PIN_nRESET 10
|
||||
|
||||
#define PIN_LED_CONNECTED _ // won't be used
|
||||
#define PIN_LED_RUNNING _ // won't be used
|
||||
|
|
|
@ -11,7 +11,7 @@ file(GLOB SOURCES
|
|||
idf_component_register(
|
||||
SRCS ${SOURCES}
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES mdns esp_wifi esp_event api_router wt_storage
|
||||
PRIV_REQUIRES mdns esp_wifi esp_event api_router wt_storage driver
|
||||
)
|
||||
|
||||
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
file(GLOB SOURCES *.c
|
||||
)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCES}
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES
|
||||
global_resource esp_app_format api_router
|
||||
)
|
||||
|
||||
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")
|
||||
add_compile_definitions(FW_UPD_DATE="${CURRENT_DATE}")
|
||||
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 kerms <kerms@niazo.org>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "wt_system.h"
|
||||
#include "wt_system_api.h"
|
||||
#include <esp_app_desc.h>
|
||||
#include <string.h>
|
||||
#include <esp_system.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
#define TAG "WT_SYS"
|
||||
|
||||
void wt_system_get_fm_info(wt_fm_info_t *fm_info)
|
||||
{
|
||||
const esp_app_desc_t *app_desc = esp_app_get_description();
|
||||
strcpy(fm_info->fm_ver, app_desc->version);
|
||||
memcpy(fm_info->upd_date, FW_UPD_DATE, sizeof(fm_info->upd_date) - 1);
|
||||
fm_info->upd_date[sizeof(fm_info->upd_date) - 1] = '\0';
|
||||
}
|
||||
|
||||
static void reboot_task(void *arg)
|
||||
{
|
||||
ESP_LOGW(TAG, "reboot in 2 seconds");
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
void wt_system_reboot()
|
||||
{
|
||||
xTaskCreatePinnedToCore(reboot_task, "reboot", 4096, NULL, 3, NULL, 0);
|
||||
}
|
||||
|
||||
static int wt_system_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const global_module_t module = {
|
||||
.init = wt_system_init,
|
||||
.module_id = SYSTEM_MODULE_ID
|
||||
};
|
||||
|
||||
GLOBAL_MODULE_REGISTER(WT_SYSTEM, &module);
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 kerms <kerms@niazo.org>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef WT_SYSTEM_H_GUARD
|
||||
#define WT_SYSTEM_H_GUARD
|
||||
|
||||
#include "global_module.h"
|
||||
|
||||
typedef struct wt_fm_info_t {
|
||||
char fm_ver[32];
|
||||
char upd_date[11];
|
||||
} wt_fm_info_t;
|
||||
|
||||
void wt_system_get_fm_info(wt_fm_info_t *fm_info);
|
||||
|
||||
/**
|
||||
* Trigger delayed reboot in 2 seconds
|
||||
*/
|
||||
void wt_system_reboot();
|
||||
|
||||
|
||||
#endif //WT_SYSTEM_H_GUARD
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 kerms <kerms@niazo.org>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef WT_SYSTEM_API_H_GUARD
|
||||
#define WT_SYSTEM_API_H_GUARD
|
||||
|
||||
#define SYSTEM_MODULE_ID 6
|
||||
|
||||
typedef enum wt_system_cmd_t {
|
||||
WT_SYS_GET_FM_INFO = 1,
|
||||
WT_SYS_REBOOT = 2,
|
||||
} wt_system_cmd_t;
|
||||
|
||||
|
||||
#endif //WT_SYSTEM_API_H_GUARD
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 kerms <kerms@niazo.org>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "wt_system_api.h"
|
||||
#include "wt_system.h"
|
||||
#include "api_json_module.h"
|
||||
#include "wt_system_json_utils.h"
|
||||
|
||||
|
||||
static int sys_api_json_get_fm_info(api_json_req_t *req)
|
||||
{
|
||||
wt_fm_info_t info;
|
||||
wt_system_get_fm_info(&info);
|
||||
req->out = wt_sys_json_ser_fm_info(&info);
|
||||
return API_JSON_OK;
|
||||
}
|
||||
|
||||
static int on_json_req(uint16_t cmd, api_json_req_t *req, api_json_module_async_t *async)
|
||||
{
|
||||
wt_system_cmd_t ota_cmd = cmd;
|
||||
switch (ota_cmd) {
|
||||
default:
|
||||
break;
|
||||
case WT_SYS_GET_FM_INFO:
|
||||
return sys_api_json_get_fm_info(req);
|
||||
case WT_SYS_REBOOT:
|
||||
wt_system_reboot();
|
||||
return API_JSON_OK;
|
||||
}
|
||||
return API_JSON_UNSUPPORTED_CMD;
|
||||
}
|
||||
|
||||
|
||||
/* ****
|
||||
* register module
|
||||
* */
|
||||
|
||||
static int wt_sys_json_init(api_json_module_cfg_t *cfg)
|
||||
{
|
||||
cfg->on_req = on_json_req;
|
||||
cfg->module_id = SYSTEM_MODULE_ID;
|
||||
return 0;
|
||||
}
|
||||
|
||||
API_JSON_MODULE_REGISTER(wt_sys_json_init)
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 kerms <kerms@niazo.org>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "wt_system_json_utils.h"
|
||||
|
||||
static void wt_sys_json_add_header(cJSON *root, wt_system_cmd_t cmd)
|
||||
{
|
||||
cJSON_AddNumberToObject(root, "cmd", cmd);
|
||||
cJSON_AddNumberToObject(root, "module", SYSTEM_MODULE_ID);
|
||||
}
|
||||
|
||||
cJSON *wt_sys_json_ser_fm_info(wt_fm_info_t *info)
|
||||
{
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
wt_sys_json_add_header(root, WT_SYS_GET_FM_INFO);
|
||||
cJSON_AddStringToObject(root, "fm_ver", info->fm_ver);
|
||||
cJSON_AddStringToObject(root, "upd_date", info->upd_date);
|
||||
return root;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 kerms <kerms@niazo.org>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef WT_SYSTEM_JSON_UTILS_H_GUARD
|
||||
#define WT_SYSTEM_JSON_UTILS_H_GUARD
|
||||
|
||||
#include "wt_system_api.h"
|
||||
#include "wt_system.h"
|
||||
#include <cJSON.h>
|
||||
|
||||
|
||||
cJSON *wt_sys_json_ser_fm_info(wt_fm_info_t *info);
|
||||
|
||||
#endif //WT_SYSTEM_JSON_UTILS_H_GUARD
|
Loading…
Reference in New Issue