Support MCU Get WIFI Module ChipId Protocol
This commit is contained in:
parent
6263b45cec
commit
ff28cf1669
|
@ -185,7 +185,9 @@ void ne_device_frame_process(ne_device_ctx_t *ctx, uint8 *input, uint32 in_len)
|
|||
while(in_len > offset){
|
||||
/* frame filter */
|
||||
msgdir = ctx->ne_device_handler->device_split(NULL, &offset, input , in_len, ctx->frame.rbuf, &ctx->frame.rlen);
|
||||
|
||||
if(msgdir == MSG_DIRECTION_UART_UP || msgdir == MSG_DIRECTION_BDATA_UP){
|
||||
//LOG_EX(LOG_Debug, "Send Protocol\n");
|
||||
/* frame send queue */
|
||||
ne_device_send_queue(ctx->frame.rbuf, ctx->frame.rlen, msgdir);
|
||||
}
|
||||
|
@ -207,7 +209,7 @@ void ne_device_polling_cb(void *arg)
|
|||
/* read uart datas */
|
||||
ret = ctx->ne_device_handler->device_read(NULL, &tbuf, &tlen);
|
||||
if(ret == ERR_OK){
|
||||
LOG_EX(LOG_Info, "polling data tlen=%d\r\n", tlen);
|
||||
//LOG_EX(LOG_Info, "polling data tlen=%d\r\n", tlen);
|
||||
if(tbuf == NULL || tlen <= 0)
|
||||
return;
|
||||
|
||||
|
|
|
@ -377,12 +377,53 @@ static int32 ne_general_local_process(uint8 *input, uint32 ilen)
|
|||
break;
|
||||
case NE_DEVICE_GENERAL_CMD_GET_VERSION:
|
||||
{
|
||||
uint8 mcu_version[5];
|
||||
uint32 slen;
|
||||
uint8 sbuf[NE_GENERAL_MAX_SBUF_LEN];
|
||||
uint32 wifiVer = atoi(FIRMWARE_VERSION);
|
||||
|
||||
slen = ne_general_create_frame(NE_DEVICE_GENERAL_CMD_GET_VERSION,
|
||||
(uint8_t *)&wifiVer, 4,
|
||||
sbuf, NE_GENERAL_MAX_SBUF_LEN);
|
||||
|
||||
memset(mcu_version, 0, sizeof(mcu_version));
|
||||
memcpy(mcu_version, input, 4);
|
||||
GENERAL_LOG_EX(LOG_Info, "mcu version=%s\r\n", mcu_version);
|
||||
if(slen < 0){
|
||||
GENERAL_LOG_EX(LOG_Error, "create frame fail!\r\n");
|
||||
}
|
||||
ne_general_write(NULL, sbuf, slen);
|
||||
}
|
||||
break;
|
||||
case NE_DEVICE_GENERAL_CMD_GET_CHIPID:
|
||||
{
|
||||
uint32 slen;
|
||||
ne_general_rsp_data_t rsp_data;
|
||||
const char* pId = GetPlatformDevId();
|
||||
|
||||
unsigned char* pBuf = (unsigned char*)HAL_Malloc(strlen(pId) + NE_GENERAL_MAX_SBUF_LEN);
|
||||
|
||||
if(pBuf) {
|
||||
slen = ne_general_create_frame(NE_DEVICE_GENERAL_CMD_GET_CHIPID,
|
||||
(uint8_t *)pId,
|
||||
strlen(pId),
|
||||
pBuf,
|
||||
strlen(pId) + NE_GENERAL_MAX_SBUF_LEN);
|
||||
} else {
|
||||
rsp_data.msgtype = NE_DEVICE_GENERAL_CMD_GET_CHIPID;
|
||||
rsp_data.result = NE_GENERAL_FAIL;
|
||||
|
||||
slen = ne_general_create_frame(NE_DEVICE_GENERAL_CMD_GET_CHIPID,
|
||||
(uint8_t *)&rsp_data,
|
||||
sizeof(rsp_data),
|
||||
pBuf,
|
||||
strlen(pId) + NE_GENERAL_MAX_SBUF_LEN);
|
||||
}
|
||||
|
||||
if(slen < 0){
|
||||
GENERAL_LOG_EX(LOG_Error, "create frame fail!\r\n");
|
||||
}
|
||||
ne_general_write(NULL, pBuf, slen);
|
||||
|
||||
HAL_Free(pBuf);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#define SERVER_USED ONLINE_PUBLISH
|
||||
|
||||
#define FIRMWARE_VERSION "00000001"
|
||||
#define FIRMWARE_VERSION "00000002"
|
||||
#define FIRMWARE_VERSION_MCU "00000002"
|
||||
#define USER_CFG_VERSION (0)
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
#define NE_DEVICE_GENERAL_HEAD 0x3c
|
||||
#define NE_GENERAL_MAX_SBUF_LEN 18
|
||||
|
||||
#define GENERAL_DEBUG_ENABLE 0
|
||||
#define GENERAL_DEBUG_ENABLE 1
|
||||
#if GENERAL_DEBUG_ENABLE
|
||||
#define GENERAL_LOG_EX LOG_RAW
|
||||
#define GENERAL_LOG_EX LOG_EX
|
||||
#else
|
||||
#define GENERAL_LOG_EX
|
||||
#endif
|
||||
|
@ -58,7 +58,8 @@ enum{
|
|||
NE_DEVICE_GENERAL_CMD_GET_STATUS,
|
||||
NE_DEVICE_GENERAL_CMD_CLEAR_SSID,
|
||||
NE_DEVICE_GENERAL_CMD_RESET_WIFI,
|
||||
NE_DEVICE_GENERAL_CMD_GET_VERSION
|
||||
NE_DEVICE_GENERAL_CMD_GET_VERSION,
|
||||
NE_DEVICE_GENERAL_CMD_GET_CHIPID,
|
||||
};
|
||||
|
||||
#pragma pack (1)
|
||||
|
|
|
@ -59,6 +59,8 @@ typedef enum {
|
|||
BIT_RATE_921600 = 921600,
|
||||
BIT_RATE_1843200 = 1843200,
|
||||
BIT_RATE_3686400 = 3686400,
|
||||
BIT_RATE_1500000 = 1500000,
|
||||
BIT_RATE_3000000 = 3000000,
|
||||
} UART_BautRate; //you can add any rate you need in this range
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -224,7 +224,6 @@ static int ne_product_init(void)
|
|||
ShowCfgConfigure();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* system server init.
|
||||
*/
|
||||
|
@ -237,6 +236,72 @@ static int ne_server_init(void)
|
|||
user_conn_init();
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void test_aes(void)
|
||||
{
|
||||
int iCount = 0;
|
||||
mbedtls_aes_context aes_ctx;
|
||||
//密钥数值
|
||||
unsigned char key[16] = {'0', '1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
|
||||
unsigned char enAes[16] = {0xA5, 0xF4, 0xDD, 0xC8, 0xE5, 0xCF, 0x4B, 0xB5, 0x98, 0xB4, 0xCB, 0xE2, 0x85, 0x74, 0x71, 0xC6};
|
||||
//明文空间
|
||||
unsigned char plain[16] = "helloworld";
|
||||
//解密后明文的空间
|
||||
unsigned char dec_plain[16]={0};
|
||||
//密文空间
|
||||
unsigned char cipher[16]={0};
|
||||
unsigned char dec[16]={0};
|
||||
unsigned char basecode[128];
|
||||
|
||||
mbedtls_aes_init( &aes_ctx );
|
||||
|
||||
//设置加密密钥
|
||||
mbedtls_aes_setkey_enc( &aes_ctx, key, 128);
|
||||
|
||||
LOG_EX(LOG_Debug, "*********** Before encode: %s\n", plain);
|
||||
mbedtls_aes_crypt_ecb( &aes_ctx, MBEDTLS_AES_ENCRYPT, plain, cipher );
|
||||
|
||||
IHW_LOG_BUF(LOG_Debug, "AES_", cipher, 16);
|
||||
|
||||
memset(basecode, 0, 128);
|
||||
|
||||
mbedtls_base64_encode(basecode, 128, &iCount, cipher, 16);
|
||||
|
||||
LOG_EX(LOG_Debug, "\n*********** Encrypt AES: %s\n", basecode);
|
||||
|
||||
//设置解密密钥
|
||||
mbedtls_aes_setkey_dec(&aes_ctx, key, 128);
|
||||
|
||||
mbedtls_aes_crypt_ecb( &aes_ctx, MBEDTLS_AES_DECRYPT, enAes, dec_plain );
|
||||
LOG_EX(LOG_Debug, "*********** Decode: %s\n", dec_plain);
|
||||
|
||||
IHW_LOG_BUF(LOG_Debug, "CIP_", enAes, 16);
|
||||
IHW_LOG_BUF(LOG_Debug, "DES_", dec_plain, 16);
|
||||
|
||||
mbedtls_aes_free( &aes_ctx );
|
||||
}
|
||||
#endif
|
||||
|
||||
static void __showTimes(void* pvParams)
|
||||
{
|
||||
uint32 cnt = 1;
|
||||
while (TRUE) {
|
||||
uint32 cal = system_rtc_clock_cali_proc();
|
||||
uint32 rtc = system_get_rtc_time();
|
||||
uint32 iVal = ((cal * 1000) >> 12) / 1000;
|
||||
uint32 dVal = ((cal * 1000) >> 12) % 1000;
|
||||
LOG_EX(LOG_Debug, "rtc = %u, cal(%u): %u.%u \n", rtc, cal, iVal, dVal);
|
||||
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
|
||||
if(cnt++ > 25)
|
||||
{
|
||||
system_deep_sleep_instant(30000 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
/*
|
||||
* entry of user application, init user function here.
|
||||
*/
|
||||
|
@ -258,6 +323,9 @@ void ICACHE_FLASH_ATTR user_init(void)
|
|||
|
||||
ne_network_init();
|
||||
|
||||
//xTaskCreate(__dumpHeapSize, "heap_dump", 256, NULL, 1, NULL);
|
||||
//wifi_set_sleep_type(MODEM_SLEEP_T);
|
||||
|
||||
//test_aes();
|
||||
//xTaskCreate(__showTimes, "__showTimes", 256, NULL, 1, NULL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue