418 lines
12 KiB
C
418 lines
12 KiB
C
#include "ate_cmd_manager.h"
|
|
#include "common_def.h"
|
|
#include "debug_print.h"
|
|
#include <soc_osal.h>
|
|
|
|
#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
|
|
|
|
static void app_at_msg_send(uint8_t *data, uint32_t data_len)
|
|
{
|
|
if (data == NULL) {
|
|
wstp_print("app_at_msg_send data is null!" NEWLINE);
|
|
return;
|
|
}
|
|
|
|
at_cmd_msg_info_t msg;
|
|
msg.payload_len = data_len;
|
|
/* +1是为字符串结束符多申请内存 */
|
|
msg.payload = osal_kmalloc(data_len + 1, OSAL_GFP_KERNEL);
|
|
if (msg.payload == NULL) {
|
|
wstp_print("app_at_msg_send payload memory alloc fail, length is " NEWLINE, data_len);
|
|
return;
|
|
}
|
|
|
|
(void)memset_s(msg.payload, data_len + 1, 0, data_len + 1);
|
|
if (memcpy_s(msg.payload, msg.payload_len, (const void *)data, data_len) != EOK) {
|
|
wstp_print("app_at_msg_send receive data memcpy error!" NEWLINE);
|
|
osal_kfree(msg.payload);
|
|
msg.payload = NULL;
|
|
return;
|
|
}
|
|
|
|
if (osal_msg_queue_write_copy(get_ate_at_queue_id(), (void *)&msg, sizeof(at_cmd_msg_info_t), 0) != OSAL_SUCCESS) {
|
|
wstp_print("app_at_msg_send send msg error!" NEWLINE);
|
|
osal_kfree(msg.payload);
|
|
msg.payload = NULL;
|
|
}
|
|
}
|
|
|
|
static void at_msg_send(uint8_t msg_id, uint8_t *data, uint32_t data_len)
|
|
{
|
|
ate_msg_info_t *msg;
|
|
uint8_t ret;
|
|
msg = (ate_msg_info_t *)osal_kmalloc(sizeof(ate_msg_info_t) + data_len, OSAL_GFP_KERNEL);
|
|
if (msg == NULL) {
|
|
wstp_print("at_msg_send malloc fail!!" NEWLINE);
|
|
return;
|
|
}
|
|
|
|
ret = memset_s(msg, sizeof(ate_msg_info_t) + data_len, 0, sizeof(ate_msg_info_t) + data_len);
|
|
if (ret != EOK) {
|
|
wstp_print("at_msg_send data memset error! ret [%d]" NEWLINE, ret);
|
|
osal_kfree(msg);
|
|
return;
|
|
}
|
|
|
|
msg->id = msg_id;
|
|
msg->payload = (uint8_t *)((uint8_t *)msg + sizeof(ate_msg_info_t));
|
|
msg->payload_len = data_len;
|
|
|
|
if (data_len > 0 && data != NULL) {
|
|
ret = memcpy_s(msg->payload, msg->payload_len, (const void *)data, data_len);
|
|
if (ret != EOK) {
|
|
wstp_print("at_msg_send data memcpy error! ret [%d]" NEWLINE, ret);
|
|
osal_kfree(msg);
|
|
return;
|
|
}
|
|
}
|
|
|
|
app_at_msg_send((uint8_t *)msg, sizeof(ate_msg_info_t) + data_len);
|
|
}
|
|
|
|
static uint32_t tp_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_TP_CHIPID; break;
|
|
case '1': msg = SW_TP_VERSION; break;
|
|
case '2': msg = SW_TP_RAWDATA; break;
|
|
case '3': msg = SW_TP_UPDATE; break;
|
|
case '4': msg = SW_TP_TOUCH; break;
|
|
case '5': msg = HW_TP_POWER; break;
|
|
case '6': msg = HW_TP_OPEN; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t media_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_MEIDA_INIT; break;
|
|
case '1': msg = SW_MEIDA_CAIL_F0; break;
|
|
case '2': msg = SW_MEIDA_CAIL_RE; break;
|
|
case '3': msg = SW_MEIDA_PA_START; break;
|
|
case '4': msg = SW_MEIDA_I2S_OUTPUT; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t rtc_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_RTC_TIME; break;
|
|
case '1': msg = SW_RTC_DIFF_TIME; break;
|
|
case '2': msg = SW_RTC_TIMESTAMP; break;
|
|
case '3': msg = SW_RTC_MS_TIMESTAMP; break;
|
|
case '4': msg = SW_RTC_SYNC_BT_TIME; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t ble_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_BLE_OPEN; break;
|
|
case '1': msg = SW_BLE_CLOSE; break;
|
|
case '2': msg = SW_BLE_ENABLE; break;
|
|
case '3': msg = SW_BLE_DISABLE; break;
|
|
case '4': msg = SW_BLE_SET_NAME; break;
|
|
case '5': msg = SW_BLE_GET_NAME; break;
|
|
case '6': msg = SW_BLE_SET_ADDR; break;
|
|
case '7': msg = SW_BLE_GET_ADDR; break;
|
|
case '8': msg = SW_BLE_SET_ADV_DATA; break;
|
|
case '9': msg = SW_BLE_START_ADV; break;
|
|
case 'a': msg = SW_BLE_SEND_MESSAGE; break;
|
|
case 'b': msg = SW_BLE_SEND_MSG; break;
|
|
case 'c': msg = SW_BLE_SHOW_LIST; break;
|
|
case 'd': msg = SW_BLE_START_SCAN; break;
|
|
case 'e': msg = SW_BLE_UPLOAD_FILE; break;
|
|
case 'f': msg = SW_BLE_REQUEST_GPS; break;
|
|
case 'g': msg = SW_BR_GET_SCAN_MODE; break;
|
|
case 'h': msg = SW_BLE_REQUEST_FLOVER; break;
|
|
case 'i': msg = SW_BLE_RENAME_FILE_NAME; break;
|
|
case 'j': msg = SW_BLE_CLOSE_BT_ONLY; break;
|
|
case 'k': msg = SW_BLE_OPEN_BT_ONLY; break;
|
|
case 'l': msg = SW_BLE_RECOVERY_OTA; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t chgarger_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_CHARGER_INIT; break;
|
|
case '1': msg = SW_CHARGER_TEST; break;
|
|
case '2': msg = SW_CHARGER_GET_BATTERY; break;
|
|
case '3': msg = SW_CHARGER_GET_STATE; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t gps_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_GPS_OPEN; break;
|
|
case '1': msg = SW_GPS_CLOSE; break;
|
|
case '2': msg = SW_GPS_EPH_EFFECTIVE; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t pm_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_PM_GET_STATUS; break;
|
|
case '1': msg = SW_PM_SET_STATUS; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t motor_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_MOTOR_START; break;
|
|
case '1': msg = SW_MOTOR_STOP; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t nor_flash_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_NOR_FLASH_WRITE; break;
|
|
case '1': msg = SW_NOR_FLASH_READ; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t app_stort_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = SW_APP_STORE_INSTALL; break;
|
|
case '1': msg = SW_APP_STORE_UNINSTALL; break;
|
|
case '2': msg = SW_APP_STORE_GET_LIST; break;
|
|
case '3': msg = SW_APP_STORE_GET_STATE; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
static uint32_t wechat_handle(uint8_t *para, uint32_t para_len, char *str_cmd)
|
|
{
|
|
uint8_t msg;
|
|
if (para == NULL) {
|
|
return ERRCODE_FAIL;
|
|
}
|
|
|
|
// clang-format off
|
|
switch (str_cmd[0])
|
|
{
|
|
case '0': msg = WECHAT_TEST; break;
|
|
default:
|
|
return ERRCODE_FAIL;
|
|
}
|
|
// clang-format on
|
|
at_msg_send(msg, para, para_len);
|
|
return ERRCODE_SUCC;
|
|
}
|
|
|
|
/**
|
|
* @note {"AT^SW_TP_CHIPID", tp_handle, "0"},
|
|
* 实际AT命令 处理函数 私有参数
|
|
*/
|
|
// clang-format off
|
|
static const at_cmd_table_t g_ate_cmd_table[] = {
|
|
/*----------------TP-----------------*/
|
|
{"AT^SW_TP_CHIPID", tp_handle, "0"},
|
|
{"AT^SW_TP_VERSION", tp_handle, "1"},
|
|
{"AT^SW_TP_RAWDATA", tp_handle, "2"},
|
|
{"AT^SW_TP_UPDATE", tp_handle, "3"},
|
|
{"AT^SW_TP_TOUCH", tp_handle, "4"},
|
|
{"AT^HW_TP_POWER", tp_handle, "5"},
|
|
{"AT^HW_TP_OPEN", tp_handle, "6"},
|
|
|
|
/*---------------LCD-----------------*/
|
|
{"AT^TEST_MEDIA_INIT", media_handle, "0"},
|
|
{"AT^TEST_MEDIA_CAIL_FO", media_handle, "1"},
|
|
{"AT^TEST_MEDIA_CAIL_RE", media_handle, "2"},
|
|
{"AT^TEST_MEDIA_PA_START", media_handle, "3"},
|
|
{"AT^TEST_MEDIA_I2S_OUTPUT", media_handle, "4"},
|
|
|
|
/*--------------CHARGER---------------*/
|
|
{"AT^CHARGER_INIT", chgarger_handle, "0"},
|
|
{"AT^CHARGER_TEST", chgarger_handle, "1"},
|
|
{"AT^CHARGER_GET_BATTERY", chgarger_handle, "2"},
|
|
{"AT^CHARGER_GET_STATE", chgarger_handle, "3"},
|
|
|
|
/*--------------MOTOR---------------*/
|
|
{"AT^MOTOR_START", motor_handle, "0"},
|
|
{"AT^MOTOR_STOP", motor_handle, "1"},
|
|
|
|
/*---------------RTC-----------------*/
|
|
{"AT^RTC_TIME", rtc_handle, "0"},
|
|
{"AT^RTC_DIFF_TIME", rtc_handle, "1"},
|
|
{"AT^RTC_TIMESTAMP", rtc_handle, "2"},
|
|
{"AT^RTC_MS_TIMESTAMP", rtc_handle, "3"},
|
|
{"AT^RTC_SYNC_BT_TIME", rtc_handle, "4"},
|
|
|
|
/*-------------------BLE----------------------*/
|
|
{"AT^TEST_BLE_OPEN", ble_handle, "0"},
|
|
{"AT^TEST_BLE_CLOSE", ble_handle, "1"},
|
|
{"AT^TEST_BLE_ENABLE", ble_handle, "2"},
|
|
{"AT^TEST_BLE_DISABLE", ble_handle, "3"},
|
|
{"AT^TEST_BLE_SET_NAME", ble_handle, "4"},
|
|
{"AT^TEST_BLE_GET_NAME", ble_handle, "5"},
|
|
{"AT^TEST_BLE_SET_ADDR", ble_handle, "6"},
|
|
{"AT^TEST_BLE_GET_ADDR", ble_handle, "7"},
|
|
{"AT^TEST_BLE_SET_ADV_DATA", ble_handle, "8"},
|
|
{"AT^TEST_BLE_START_ADV", ble_handle, "9"},
|
|
{"AT^TEST_BLE_SEND_MESSAGE", ble_handle, "a"},
|
|
{"AT^TEST_BLE_SEND_MSG", ble_handle, "b"},
|
|
{"AT^TEST_BLE_SHOW_LIST", ble_handle, "c"},
|
|
{"AT^TEST_BLE_START_SCAN", ble_handle, "d"},
|
|
{"AT^TEST_BLE_UPLOAD_FILE", ble_handle, "e"},
|
|
{"AT^TEST_BLE_REQUEST_GPS", ble_handle, "f"},
|
|
{"AT^TEST_BR_GET_SCAN_MODE", ble_handle, "g"},
|
|
{"AT^TEST_BLE_REQUEST_FLOVER", ble_handle, "h"},
|
|
{"AT^RENAME", ble_handle, "i"},
|
|
{"AT^CLOSE_BT_ONLY", ble_handle, "j"},
|
|
{"AT^OPEN_BT_ONLY", ble_handle, "k"},
|
|
{"AT^BLE_RECOVERY_OTA", ble_handle, "l"},
|
|
|
|
/*-----------------GPS------------------*/
|
|
{"AT^GPS_OPEN", gps_handle, "0"},
|
|
{"AT^GPS_CLOSE", gps_handle, "1"},
|
|
{"AT^GPS_EPH_EFFECTIVE",gps_handle, "2"},
|
|
|
|
/*-----------------PM-----------------*/
|
|
{"AT^PM_GET_STATUS", pm_handle, "0"},
|
|
{"AT^PM_SET_STATUS", pm_handle, "1"},
|
|
|
|
/*----------------- NOR_FLASH -----------------*/
|
|
{"AT^SET_MAC_ADDR", nor_flash_handle, "0"},
|
|
{"AT^GET_MAC_ADDR", nor_flash_handle, "1"},
|
|
|
|
/*----------------- APP_STORT -----------------*/
|
|
{"AT^INSTALL", app_stort_handle, "0"},
|
|
{"AT^UNINSTALL", app_stort_handle, "1"},
|
|
{"AT^GET_APP_LIST", app_stort_handle, "2"},
|
|
{"AT^GET_APP_STATE", app_stort_handle, "3"},
|
|
|
|
{"AT^WECHAT_TEST", wechat_handle, "0"},
|
|
};
|
|
// clang-format on
|
|
|
|
uint32_t ate_get_cmd_table(void)
|
|
{
|
|
return at_cmd_add_moudle(g_ate_cmd_table, ARRAY_COUNT(g_ate_cmd_table));
|
|
}
|