202 lines
6.7 KiB
C
202 lines
6.7 KiB
C
#include "ate_at_process.h"
|
|
#include "ate_cmd_manager.h"
|
|
#include "common_def.h"
|
|
#include "debug_print.h"
|
|
#include "securec.h"
|
|
|
|
#include "ble_cmd_process.h"
|
|
#include "media_cmd_process.h"
|
|
#include "rtc_cmd_process.h"
|
|
#include "tp_cmd_process.h"
|
|
#include "charger_cmd_process.h"
|
|
#include "motor_cmd_process.h"
|
|
#include "gps_cmd_process.h"
|
|
#include "pm_cmd_process.h"
|
|
#include "nor_flash_cmd_process.h"
|
|
#include "app_store_cmd_process.h"
|
|
#include "tencent_test_cmd_process.h"
|
|
|
|
#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
|
|
#define BSP_MEM_ALLOC(y) osal_kmalloc((y), OSAL_GFP_KERNEL)
|
|
#define BSP_MEM_FREE(y) osal_kfree(y)
|
|
|
|
typedef void (*api_init_func)(void);
|
|
typedef struct
|
|
{
|
|
api_init_func init;
|
|
} ate_api_manager_t;
|
|
|
|
/* 需要用到初始化添加处 */
|
|
static ate_api_manager_t g_ate_module_api_manager[] = {
|
|
{tp_cmd_process_init},
|
|
{media_cmd_process_init},
|
|
{rtc_cmd_process_init},
|
|
{charger_cmd_process_init},
|
|
{pm_cmd_process_init},
|
|
};
|
|
|
|
void ate_module_api_init(void)
|
|
{
|
|
for (uint32_t i = 0; i < ARRAY_COUNT(g_ate_module_api_manager); i++) {
|
|
g_ate_module_api_manager[i].init();
|
|
}
|
|
}
|
|
|
|
// clang-format off
|
|
static const ProcessType g_at_funcs[] = {
|
|
/*----------------TP-----------------*/
|
|
{SW_TP_CHIPID, get_chipid},
|
|
{SW_TP_VERSION, get_version},
|
|
{SW_TP_RAWDATA, get_rawdata},
|
|
{SW_TP_UPDATE, test_update},
|
|
{SW_TP_TOUCH, test_touch},
|
|
{HW_TP_POWER, set_power},
|
|
{HW_TP_OPEN, set_open},
|
|
|
|
{SW_MEIDA_INIT, media_demo},
|
|
{SW_MEIDA_CAIL_F0, media_cail_f0},
|
|
{SW_MEIDA_CAIL_RE, media_cail_re},
|
|
{SW_MEIDA_PA_START, media_pa_start},
|
|
{SW_MEIDA_I2S_OUTPUT, media_i2s_output},
|
|
/*---------------LCD-----------------*/
|
|
|
|
/*---------------RTC-----------------*/
|
|
{SW_RTC_TIME, rtc_time},
|
|
{SW_RTC_DIFF_TIME, rtc_diff_time},
|
|
{SW_RTC_TIMESTAMP, rtc_timestamp},
|
|
{SW_RTC_MS_TIMESTAMP, rtc_ms_timestamp},
|
|
{SW_RTC_SYNC_BT_TIME, rtc_sync_bt_time},
|
|
|
|
/*---------------BLE-----------------*/
|
|
{SW_BLE_OPEN, ble_open_start},
|
|
{SW_BLE_CLOSE, ble_close_start},
|
|
{SW_BLE_ENABLE, ble_enable_start},
|
|
{SW_BLE_DISABLE, ble_disable_start},
|
|
{SW_BLE_SET_NAME, ble_set_local_name_start},
|
|
{SW_BLE_GET_NAME, ble_get_local_name_start},
|
|
{SW_BLE_SET_ADDR, ble_set_local_addr_start},
|
|
{SW_BLE_GET_ADDR, ble_get_local_addr_start},
|
|
{SW_BLE_SET_ADV_DATA, ble_get_local_addr_start},
|
|
{SW_BLE_START_ADV, ble_get_local_addr_start},
|
|
{SW_BLE_SEND_MESSAGE, ble_send_message},
|
|
{SW_BLE_SEND_MSG, ble_spp_send_msg},
|
|
{SW_BLE_SHOW_LIST, ble_show_scan_list},
|
|
{SW_BLE_START_SCAN, ble_start_scan},
|
|
{SW_BLE_UPLOAD_FILE, ble_upload_file},
|
|
{SW_BLE_REQUEST_GPS, ble_request_gps},
|
|
{SW_BR_GET_SCAN_MODE, br_get_scan_mode},
|
|
{SW_BLE_REQUEST_FLOVER, ble_request_flover},
|
|
{SW_BLE_RENAME_FILE_NAME, ble_rename_file_name},
|
|
{SW_BLE_CLOSE_BT_ONLY, ble_close_bt_only},
|
|
{SW_BLE_OPEN_BT_ONLY, ble_open_bt_only},
|
|
{SW_BLE_RECOVERY_OTA, ble_ota_recovery_test},
|
|
|
|
/*-------------CHARGER---------------*/
|
|
{SW_CHARGER_INIT, ate_charger_init},
|
|
{SW_CHARGER_TEST, ate_charger_test},
|
|
{SW_CHARGER_GET_BATTERY, ate_charger_get_battery},
|
|
{SW_CHARGER_GET_STATE, ate_charger_get_state},
|
|
|
|
/*-------------MOTOR---------------*/
|
|
{SW_MOTOR_START, ate_motor_start},
|
|
{SW_MOTOR_STOP, ate_motor_stop},
|
|
|
|
/*-----------------GPS------------------*/
|
|
{SW_GPS_OPEN, gps_open},
|
|
{SW_GPS_CLOSE, gps_close},
|
|
{SW_GPS_EPH_EFFECTIVE, gps_ephemeris_effective},
|
|
|
|
/*-----------------PM------------------*/
|
|
{SW_PM_GET_STATUS, pm_get_model_status},
|
|
|
|
/*----------------- NOR_FLASH ------------------*/
|
|
{SW_NOR_FLASH_WRITE, ate_nor_flash_set_mac_addr},
|
|
{SW_NOR_FLASH_READ, ate_nor_flash_get_mac_addr},
|
|
{SW_PM_SET_STATUS, pm_set_model_status},
|
|
|
|
/*----------------- APP_STORT ------------------*/
|
|
{SW_APP_STORE_INSTALL, app_install},
|
|
{SW_APP_STORE_UNINSTALL, app_uninstall},
|
|
{SW_APP_STORE_GET_LIST, app_get_list},
|
|
{SW_APP_STORE_GET_STATE, app_get_app_state},
|
|
|
|
{WECHAT_TEST, wechat_test},
|
|
|
|
};
|
|
// clang-format on
|
|
|
|
int32_t convert_at_param(uint8_t *inParam, uint16_t paramLen, int32_t *outArgc, char **outArgv)
|
|
{
|
|
int ret;
|
|
char *pos;
|
|
uint8_t *strTemp;
|
|
uint32_t paramCnt = 0;
|
|
uint16_t realParamLen = paramLen;
|
|
|
|
*outArgc = 0;
|
|
strTemp = (uint8_t *)BSP_MEM_ALLOC(realParamLen);
|
|
if (strTemp == NULL) {
|
|
PRINT("{%s():%d} malloc failed.\r\n", __FUNCTION__, __LINE__);
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
ret = memset_s(strTemp, realParamLen, 0, realParamLen);
|
|
if (ret != EOK) {
|
|
PRINT("{%s():%d} memset_s failed.\r\n", __FUNCTION__, __LINE__);
|
|
BSP_MEM_FREE(strTemp);
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
ret = memcpy_s(strTemp, realParamLen, inParam, realParamLen);
|
|
if (ret != EOK) {
|
|
PRINT("{%s():%d} memcpy_s failed.\r\n", __FUNCTION__, __LINE__);
|
|
BSP_MEM_FREE(strTemp);
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
pos = strtok((char *)strTemp, " ");
|
|
for (uint32_t i = 0; pos != NULL; i++) {
|
|
outArgv[i] = (char *)BSP_MEM_ALLOC(strlen(pos) + 1);
|
|
if (outArgv[i] == NULL) {
|
|
PRINT("{%s():%d} malloc failed.\r\n", __FUNCTION__, __LINE__);
|
|
BSP_MEM_FREE(strTemp);
|
|
return ERRCODE_FAIL;
|
|
}
|
|
ret = memcpy_s(outArgv[i], strlen(pos) + 1, pos, strlen(pos) + 1);
|
|
if (ret != EOK) {
|
|
PRINT("{%s():%d} memcpy_s failed.\r\n", __FUNCTION__, __LINE__);
|
|
BSP_MEM_FREE(strTemp);
|
|
return ERRCODE_FAIL;
|
|
}
|
|
paramCnt++;
|
|
if (paramCnt >= AT_MAX_PARAM_CNT) {
|
|
PRINT("{%s():%d} invalid argc: %d(max: 64).\r\n", __FUNCTION__, __LINE__, *outArgc);
|
|
BSP_MEM_FREE(strTemp);
|
|
return ERRCODE_FAIL;
|
|
}
|
|
pos = strtok(NULL, " ");
|
|
}
|
|
|
|
*outArgc = paramCnt;
|
|
BSP_MEM_FREE(strTemp);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
void ate_at_process(uint8_t *data, uint32_t data_len)
|
|
{
|
|
unused(data_len);
|
|
if (data == NULL) {
|
|
return;
|
|
}
|
|
|
|
result_t ret = {0};
|
|
ate_msg_info_t *msg = (ate_msg_info_t *)(data);
|
|
|
|
for (uint32_t i = 0; i < ARRAY_COUNT(g_at_funcs); i++) {
|
|
if (msg->id == g_at_funcs[i].msg_id) {
|
|
ret = g_at_funcs[i].func(msg->payload, msg->payload_len);
|
|
process_at_cmd_ret(ret);
|
|
}
|
|
}
|
|
}
|