mirror of
https://github.com/ghsecuritylab/ameba_ws2812b.git
synced 2026-03-20 01:24:48 +00:00
first commit
This commit is contained in:
parent
48de61fed7
commit
28cd8da44d
1181 changed files with 784669 additions and 0 deletions
193
component/common/api/at_cmd/atcmd_google.c
Normal file
193
component/common/api/at_cmd/atcmd_google.c
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
#include <lwip_netconf.h>
|
||||
#include <stdio.h>
|
||||
#include "log_service.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/tcpip.h>
|
||||
#include "wifi_conf.h"
|
||||
#include "google_nest.h"
|
||||
#include <cJSON.h>
|
||||
|
||||
#define GN_PORT 443
|
||||
|
||||
|
||||
#define _AT_GOOGLE_NEST_ "ATG0"
|
||||
|
||||
//functions that using Google Nest's API
|
||||
void google_data_retrieve_cb(char *response_buf);
|
||||
|
||||
void googlenest_get(char *host_addr, char *host_file)
|
||||
{
|
||||
unsigned char buffer[512];
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_get(&googlenest, googlenest_uri, buffer, sizeof(buffer)) == 0)
|
||||
printf("\r\n\r\nGet data from googlenest: %s", buffer);
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void google_data_retrieve_cb(char *response_buf) {
|
||||
printf("\r\nResponse_buf:\r\n%s\r\n", response_buf);
|
||||
|
||||
}
|
||||
|
||||
void googlenest_stream(char *host_addr, char *host_file)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
google_retrieve_data_hook_callback(google_data_retrieve_cb);
|
||||
gn_stream(&googlenest, googlenest_uri);
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_delete(char *host_addr, char *host_file)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_delete(&googlenest, googlenest_uri) == 0)
|
||||
printf("\r\n\r\nDelete the data is successful!");
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_put(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_put(&googlenest, googlenest_uri, data) == 0)
|
||||
printf("\r\n\r\nSaving data in firebase is successful!");
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_patch(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_patch(&googlenest, googlenest_uri, data) == 0)
|
||||
printf("\r\n\r\nUpdating data in firebase is successful!");
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_post(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
unsigned char buffer[64];
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_post(&googlenest, googlenest_uri, data, buffer, sizeof(buffer)) == 0)
|
||||
printf("\r\n\r\nInserting data to firebase is successful!\r\n\r\nThe unique name for this list of data is: %s", buffer);
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_googlenest(int argc, char **argv)
|
||||
{
|
||||
if(strcmp(argv[1], "get") == 0) {
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn get address file");
|
||||
else {
|
||||
googlenest_get(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "delete") ==0){
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn delete address file");
|
||||
else {
|
||||
googlenest_delete(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "put") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn put address file data");
|
||||
else {
|
||||
googlenest_put(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "patch") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn patch address file data");
|
||||
else {
|
||||
googlenest_patch(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "post") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn post address file data");
|
||||
else {
|
||||
googlenest_post(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "stream") ==0){
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn stream address file");
|
||||
else {
|
||||
googlenest_stream(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("\n\rUsage: gn method addr file (data)");
|
||||
}
|
||||
|
||||
//AT Command function
|
||||
|
||||
void fATG0(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATG0]: _AT_WLAN_GOOGLENEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATG0]Usage: ATWG=[method,address,file,data] or ATG0=[method,address,file]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "gn";
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_googlenest(argc, argv);
|
||||
}
|
||||
else
|
||||
printf("[ATG0]Usage: ATG0=[method,address,file,data] or ATG0=[method,address,file]\n\r");
|
||||
}
|
||||
|
||||
log_item_t at_google_items[ ] = {
|
||||
|
||||
{"ATG0", fATG0,}
|
||||
|
||||
};
|
||||
|
||||
void at_google_init(void)
|
||||
{
|
||||
log_service_add_table(at_google_items, sizeof(at_google_items)/sizeof(at_google_items[0]));
|
||||
}
|
||||
|
||||
log_module_init(at_google_init);
|
||||
512
component/common/api/at_cmd/atcmd_sys.c
Normal file
512
component/common/api/at_cmd/atcmd_sys.c
Normal file
|
|
@ -0,0 +1,512 @@
|
|||
#include <platform_stdlib.h>
|
||||
#include <platform_opts.h>
|
||||
#include <hal_adc.h>
|
||||
#include <gpio_api.h> // mbed
|
||||
#include <sys_api.h>
|
||||
#include <rtl_lib.h>
|
||||
#include <build_info.h>
|
||||
#include "analogin_api.h"
|
||||
#include "log_service.h"
|
||||
#include "atcmd_sys.h"
|
||||
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
|
||||
extern u32 ConfigDebugErr;
|
||||
extern u32 ConfigDebugInfo;
|
||||
extern u32 ConfigDebugWarn;
|
||||
extern u32 CmdDumpWord(IN u16 argc, IN u8 *argv[]);
|
||||
extern u32 CmdWriteWord(IN u16 argc, IN u8 *argv[]);
|
||||
|
||||
//-------- AT SYS commands ---------------------------------------------------------------
|
||||
|
||||
void fATSD(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSD]: _AT_SYSTEM_DUMP_REGISTER_");
|
||||
if(!arg){
|
||||
AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSD] Usage: ATSD=REGISTER");
|
||||
return;
|
||||
}
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc == 2 || argc == 3)
|
||||
CmdDumpWord(argc-1, (unsigned char**)(argv+1));
|
||||
}
|
||||
|
||||
void fATSE(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_EDIT, AT_DBG_ALWAYS, "[ATSE]: _AT_SYSTEM_EDIT_REGISTER_");
|
||||
if(!arg){
|
||||
AT_DBG_MSG(AT_FLAG_EDIT, AT_DBG_ALWAYS, "[ATSE] Usage: ATSE=REGISTER[VALUE]");
|
||||
return;
|
||||
}
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc == 3)
|
||||
CmdWriteWord(argc-1, (unsigned char**)(argv+1));
|
||||
}
|
||||
|
||||
#if SUPPORT_MP_MODE
|
||||
void fATSA(void *arg)
|
||||
{
|
||||
u32 tConfigDebugInfo = ConfigDebugInfo;
|
||||
int argc = 0, channel;
|
||||
char *argv[MAX_ARGC] = {0}, *ptmp;
|
||||
u16 offset, gain;
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA]: _AT_SYSTEM_ADC_TEST_");
|
||||
if(!arg){
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=CHANNEL(0~2)");
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_get");
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_set[offet(hex),gain(hex)]");
|
||||
return;
|
||||
}
|
||||
|
||||
argc = parse_param(arg, argv);
|
||||
if(strcmp(argv[1], "k_get") == 0){
|
||||
sys_adc_calibration(0, &offset, &gain);
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] offset = 0x%04X, gain = 0x%04X", offset, gain);
|
||||
}else if(strcmp(argv[1], "k_set") == 0){
|
||||
if(argc != 4){
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_set[offet(hex),gain(hex)]");
|
||||
return;
|
||||
}
|
||||
offset = strtoul(argv[2], &ptmp, 16);
|
||||
gain = strtoul(argv[3], &ptmp, 16);
|
||||
sys_adc_calibration(1, &offset, &gain);
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] offset = 0x%04X, gain = 0x%04X", offset, gain);
|
||||
}else{
|
||||
channel = atoi(argv[1]);
|
||||
if(channel < 0 || channel > 2){
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=CHANNEL(0~2)");
|
||||
return;
|
||||
}
|
||||
analogin_t adc;
|
||||
u16 adcdat;
|
||||
|
||||
// Remove debug info massage
|
||||
ConfigDebugInfo = 0;
|
||||
if(channel == 0)
|
||||
analogin_init(&adc, AD_1);
|
||||
else if(channel == 1)
|
||||
analogin_init(&adc, AD_2);
|
||||
else
|
||||
analogin_init(&adc, AD_3);
|
||||
adcdat = analogin_read_u16(&adc)>>4;
|
||||
// Recover debug info massage
|
||||
ConfigDebugInfo = tConfigDebugInfo;
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] A%d = 0x%04X", channel, adcdat);
|
||||
}
|
||||
}
|
||||
|
||||
void fATSG(void *arg)
|
||||
{
|
||||
gpio_t gpio_test;
|
||||
int argc = 0, val;
|
||||
char *argv[MAX_ARGC] = {0}, port, num;
|
||||
PinName pin = NC;
|
||||
u32 tConfigDebugInfo = ConfigDebugInfo;
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG]: _AT_SYSTEM_GPIO_TEST_");
|
||||
if(!arg){
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] Usage: ATSG=PINNAME(ex:A0)");
|
||||
return;
|
||||
}else{
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc != 2){
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] Usage: ATSG=PINNAME(ex:A0)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
port = argv[1][0];
|
||||
num = argv[1][1];
|
||||
if(port >= 'a' && port <= 'z')
|
||||
port -= ('a' - 'A');
|
||||
if(num >= 'a' && num <= 'z')
|
||||
num -= ('a' - 'A');
|
||||
switch(port){
|
||||
case 'A':
|
||||
switch(num){
|
||||
case '0': pin = PA_0; break; case '1': pin = PA_1; break; case '2': pin = PA_2; break; case '3': pin = PA_3; break;
|
||||
case '4': pin = PA_4; break; case '5': pin = PA_5; break; case '6': pin = PA_6; break; case '7': pin = PA_7; break;
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
switch(num){
|
||||
case '0': pin = PB_0; break; case '1': pin = PB_1; break; case '2': pin = PB_2; break; case '3': pin = PB_3; break;
|
||||
case '4': pin = PB_4; break; case '5': pin = PB_5; break; case '6': pin = PB_6; break; case '7': pin = PB_7; break;
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
switch(num){
|
||||
case '0': pin = PC_0; break; case '1': pin = PC_1; break; case '2': pin = PC_2; break; case '3': pin = PC_3; break;
|
||||
case '4': pin = PC_4; break; case '5': pin = PC_5; break; case '6': pin = PC_6; break; case '7': pin = PC_7; break;
|
||||
case '8': pin = PC_8; break; case '9': pin = PC_9; break;
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
switch(num){
|
||||
case '0': pin = PD_0; break; case '1': pin = PD_1; break; case '2': pin = PD_2; break; case '3': pin = PD_3; break;
|
||||
case '4': pin = PD_4; break; case '5': pin = PD_5; break; case '6': pin = PD_6; break; case '7': pin = PD_7; break;
|
||||
case '8': pin = PD_8; break; case '9': pin = PD_9; break;
|
||||
}
|
||||
break;
|
||||
case 'E':
|
||||
switch(num){
|
||||
case '0': pin = PE_0; break; case '1': pin = PE_1; break; case '2': pin = PE_2; break; case '3': pin = PE_3; break;
|
||||
case '4': pin = PE_4; break; case '5': pin = PE_5; break; case '6': pin = PE_6; break; case '7': pin = PE_7; break;
|
||||
case '8': pin = PE_8; break; case '9': pin = PE_9; break; case 'A': pin = PE_A; break;
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
switch(num){
|
||||
case '0': pin = PF_0; break; case '1': pin = PF_1; break; case '2': pin = PF_2; break; case '3': pin = PF_3; break;
|
||||
case '4': pin = PF_4; break; case '5': pin = PF_5; break;
|
||||
}
|
||||
break;
|
||||
case 'G':
|
||||
switch(num){
|
||||
case '0': pin = PG_0; break; case '1': pin = PG_1; break; case '2': pin = PG_2; break; case '3': pin = PG_3; break;
|
||||
case '4': pin = PG_4; break; case '5': pin = PG_5; break; case '6': pin = PG_6; break; case '7': pin = PG_7; break;
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
switch(num){
|
||||
case '0': pin = PH_0; break; case '1': pin = PH_1; break; case '2': pin = PH_2; break; case '3': pin = PH_3; break;
|
||||
case '4': pin = PH_4; break; case '5': pin = PH_5; break; case '6': pin = PH_6; break; case '7': pin = PH_7; break;
|
||||
}
|
||||
break;
|
||||
case 'I':
|
||||
switch(num){
|
||||
case '0': pin = PI_0; break; case '1': pin = PI_1; break; case '2': pin = PI_2; break; case '3': pin = PI_3; break;
|
||||
case '4': pin = PI_4; break; case '5': pin = PI_5; break; case '6': pin = PI_6; break; case '7': pin = PI_7; break;
|
||||
}
|
||||
break;
|
||||
case 'J':
|
||||
switch(num){
|
||||
case '0': pin = PJ_0; break; case '1': pin = PJ_1; break; case '2': pin = PJ_2; break; case '3': pin = PJ_3; break;
|
||||
case '4': pin = PJ_4; break; case '5': pin = PJ_5; break; case '6': pin = PJ_6; break;
|
||||
}
|
||||
break;
|
||||
case 'K':
|
||||
switch(num){
|
||||
case '0': pin = PK_0; break; case '1': pin = PK_1; break; case '2': pin = PK_2; break; case '3': pin = PK_3; break;
|
||||
case '4': pin = PK_4; break; case '5': pin = PK_5; break; case '6': pin = PK_6; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(pin == NC){
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG]: Invalid Pin Name");
|
||||
return;
|
||||
}
|
||||
// Remove debug info massage
|
||||
ConfigDebugInfo = 0;
|
||||
// Initial input control pin
|
||||
gpio_init(&gpio_test, pin);
|
||||
gpio_dir(&gpio_test, PIN_INPUT); // Direction: Input
|
||||
gpio_mode(&gpio_test, PullUp); // Pull-High
|
||||
val = gpio_read(&gpio_test);
|
||||
// Recover debug info massage
|
||||
ConfigDebugInfo = tConfigDebugInfo;
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] %c%c = %d", port, num, val);
|
||||
}
|
||||
|
||||
void fATSC(void *arg)
|
||||
{
|
||||
AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ALWAYS, "[ATSC]: _AT_SYSTEM_CLEAR_OTA_SIGNATURE_");
|
||||
sys_clear_ota_signature();
|
||||
}
|
||||
|
||||
void fATSR(void *arg)
|
||||
{
|
||||
AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ALWAYS, "[ATSR]: _AT_SYSTEM_RECOVER_OTA_SIGNATURE_");
|
||||
sys_recover_ota_signature();
|
||||
}
|
||||
|
||||
void fATSP(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
unsigned long timeout; // ms
|
||||
unsigned long time_begin, time_current;
|
||||
|
||||
gpio_t gpiob_1;
|
||||
int val_old, val_new;
|
||||
|
||||
int expected_zerocount, zerocount;
|
||||
int test_result;
|
||||
|
||||
// parameter check
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: _AT_SYSTEM_POWER_PIN_TEST_");
|
||||
if(!arg) {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
|
||||
} else {
|
||||
argc = parse_param(arg, argv);
|
||||
if (argc < 2) {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( strcmp(argv[1], "gpiob1" ) == 0 ) {
|
||||
if (argc < 4) {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
|
||||
return;
|
||||
}
|
||||
|
||||
// init gpiob1 test
|
||||
test_result = 0;
|
||||
timeout = strtoul(argv[2], NULL, 10);
|
||||
expected_zerocount = atoi(argv[3]);
|
||||
zerocount = 0;
|
||||
val_old = 1;
|
||||
|
||||
sys_log_uart_off();
|
||||
|
||||
gpio_init(&gpiob_1, PB_1);
|
||||
gpio_dir(&gpiob_1, PIN_INPUT);
|
||||
gpio_mode(&gpiob_1, PullDown);
|
||||
|
||||
// gpiob1 test ++
|
||||
time_begin = time_current = xTaskGetTickCount();
|
||||
while (time_current < time_begin + timeout) {
|
||||
val_new = gpio_read(&gpiob_1);
|
||||
|
||||
if (val_new != val_old && val_new == 0) {
|
||||
|
||||
zerocount ++;
|
||||
if (zerocount == expected_zerocount) {
|
||||
test_result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
val_old = val_new;
|
||||
time_current = xTaskGetTickCount();
|
||||
}
|
||||
// gpio test --
|
||||
|
||||
sys_log_uart_on();
|
||||
|
||||
if (test_result == 1) {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: success");
|
||||
} else {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: fail, it only got %d zeros", zerocount);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
void fATSL(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
uint32_t lock_id;
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL]: _AT_SYS_WAKELOCK_TEST_");
|
||||
|
||||
if (!arg) {
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
|
||||
return;
|
||||
} else {
|
||||
argc = parse_param(arg, argv);
|
||||
if (argc < 2) {
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch(argv[1][0]) {
|
||||
case 'a': // acquire
|
||||
{
|
||||
if (argc == 3) {
|
||||
lock_id = strtoul(argv[2], NULL, 16);
|
||||
acquire_wakelock(lock_id);
|
||||
}
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
|
||||
break;
|
||||
}
|
||||
|
||||
case 'r': // release
|
||||
{
|
||||
if (argc == 3) {
|
||||
lock_id = strtoul(argv[2], NULL, 16);
|
||||
release_wakelock(lock_id);
|
||||
}
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
|
||||
break;
|
||||
}
|
||||
|
||||
case '?': // get status
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
|
||||
break;
|
||||
|
||||
default:
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATSs(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
AT_PRINTK("[ATS@]: _AT_SYSTEM_DBG_SETTING_");
|
||||
if(!arg){
|
||||
AT_PRINTK("[ATS@] Usage: ATS@=[LEVLE,FLAG]");
|
||||
}else{
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc == 3){
|
||||
char *ptmp;
|
||||
gDbgLevel = atoi(argv[1]);
|
||||
gDbgFlag = strtoul(argv[2], &ptmp, 16);
|
||||
}
|
||||
}
|
||||
AT_PRINTK("[ATS@] level = %d, flag = 0x%08X", gDbgLevel, gDbgFlag);
|
||||
}
|
||||
|
||||
void fATSc(void *arg)
|
||||
{
|
||||
int argc = 0, config = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
AT_PRINTK("[ATS!]: _AT_SYSTEM_CONFIG_SETTING_");
|
||||
if(!arg){
|
||||
AT_PRINTK("[ATS!] Usage: ATS!=[CONFIG(0,1,2),FLAG]");
|
||||
}else{
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc == 3){
|
||||
char *ptmp;
|
||||
config = atoi(argv[1]);
|
||||
gDbgFlag = strtoul(argv[2], &ptmp, 16);
|
||||
if(config == 0)
|
||||
ConfigDebugErr = strtoul(argv[2], &ptmp, 16);
|
||||
if(config == 1)
|
||||
ConfigDebugInfo = strtoul(argv[2], &ptmp, 16);
|
||||
if(config == 2)
|
||||
ConfigDebugWarn = strtoul(argv[2], &ptmp, 16);
|
||||
}
|
||||
}
|
||||
AT_PRINTK("[ATS!] ConfigDebugErr = 0x%08X", ConfigDebugErr);
|
||||
AT_PRINTK("[ATS!] ConfigDebugInfo = 0x%08X", ConfigDebugInfo);
|
||||
AT_PRINTK("[ATS!] ConfigDebugWarn = 0x%08X", ConfigDebugWarn);
|
||||
}
|
||||
|
||||
void fATSt(void *arg)
|
||||
{
|
||||
AT_PRINTK("[ATS#]: _AT_SYSTEM_TEST_");
|
||||
}
|
||||
|
||||
void fATSx(void *arg)
|
||||
{
|
||||
AT_PRINTK("[ATS?]: _AT_SYSTEM_HELP_");
|
||||
AT_PRINTK("[ATS?]: COMPILE TIME: %s", RTL8195AFW_COMPILE_TIME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fATGR(void *arg) {
|
||||
|
||||
u32 val;
|
||||
|
||||
printf("=== GPIO_REG_BASE ===\n");
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
gpio_t gpio;
|
||||
|
||||
printf("PA_0\n");
|
||||
|
||||
printf("gpio_init\n");
|
||||
gpio_init(&gpio, PA_0);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_dir PIN_OUTPUT\n");
|
||||
gpio_dir(&gpio, PIN_OUTPUT);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_mode PullNone\n");
|
||||
gpio_mode(&gpio, PullNone);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_write 1\n");
|
||||
gpio_write(&gpio, 1);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_write 0\n");
|
||||
gpio_write(&gpio, 0);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_write 1\n");
|
||||
HAL_WRITE32(GPIO_REG_BASE, GPIO_PORTA_DR, 0x00000001);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
log_item_t at_sys_items[] = {
|
||||
{"ATSD", fATSD,}, // Dump register
|
||||
{"ATSE", fATSE,}, // Edit register
|
||||
#if SUPPORT_MP_MODE
|
||||
{"ATSA", fATSA,}, // MP ADC test
|
||||
{"ATSG", fATSG,}, // MP GPIO test
|
||||
{"ATSC", fATSC,}, // Clear OTA signature
|
||||
{"ATSR", fATSR,}, // Recover OTA signature
|
||||
{"ATSP", fATSP,}, // MP Power related test
|
||||
#endif
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
{"ATSL", fATSL,}, // wakelock test
|
||||
#endif
|
||||
{"ATS@", fATSs,}, // Debug message setting
|
||||
{"ATS!", fATSc,}, // Debug config setting
|
||||
{"ATS#", fATSt,}, // test command
|
||||
{"ATS?", fATSx,}, // Help
|
||||
|
||||
|
||||
|
||||
{"ATGR", fATGR,}, // gpio register test
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
void at_sys_init(void)
|
||||
{
|
||||
log_service_add_table(at_sys_items, sizeof(at_sys_items)/sizeof(at_sys_items[0]));
|
||||
}
|
||||
|
||||
log_module_init(at_sys_init);
|
||||
5
component/common/api/at_cmd/atcmd_sys.h
Normal file
5
component/common/api/at_cmd/atcmd_sys.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef __ATCMD_SYS_H__
|
||||
#define __ATCMD_SYS_H__
|
||||
|
||||
|
||||
#endif
|
||||
979
component/common/api/at_cmd/atcmd_wifi.c
Normal file
979
component/common/api/at_cmd/atcmd_wifi.c
Normal file
|
|
@ -0,0 +1,979 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "log_service.h"
|
||||
#include "atcmd_wifi.h"
|
||||
#include <lwip_netconf.h>
|
||||
#include "tcpip.h"
|
||||
#include <dhcp/dhcps.h>
|
||||
#include <wlan/wlan_test_inc.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include <wifi/wifi_util.h>
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
/******************************************************************************/
|
||||
#define _AT_WLAN_SET_SSID_ "ATW0"
|
||||
#define _AT_WLAN_SET_PASSPHRASE_ "ATW1"
|
||||
#define _AT_WLAN_SET_KEY_ID_ "ATW2"
|
||||
#define _AT_WLAN_AP_SET_SSID_ "ATW3"
|
||||
#define _AT_WLAN_AP_SET_SEC_KEY_ "ATW4"
|
||||
#define _AT_WLAN_AP_SET_CHANNEL_ "ATW5"
|
||||
#define _AT_WLAN_AP_ACTIVATE_ "ATWA"
|
||||
#define _AT_WLAN_AP_STA_ACTIVATE_ "ATWB"
|
||||
#define _AT_WLAN_JOIN_NET_ "ATWC"
|
||||
#define _AT_WLAN_DISC_NET_ "ATWD"
|
||||
#define _AT_WLAN_WEB_SERVER_ "ATWE"
|
||||
#define _AT_WLAN_PING_TEST_ "ATWI"
|
||||
#define _AT_WLAN_SSL_CLIENT_ "ATWL"
|
||||
#define _AT_WLAN_WIFI_PROMISC_ "ATWM"
|
||||
#define _AT_WLAN_POWER_ "ATWP"
|
||||
#define _AT_WLAN_SIMPLE_CONFIG_ "ATWQ"
|
||||
#define _AT_WLAN_GET_RSSI_ "ATWR"
|
||||
#define _AT_WLAN_SCAN_ "ATWS"
|
||||
#define _AT_WLAN_TCP_TEST_ "ATWT"
|
||||
#define _AT_WLAN_UDP_TEST_ "ATWU"
|
||||
#define _AT_WLAN_WPS_ "ATWW"
|
||||
#define _AT_WLAN_IWPRIV_ "ATWZ"
|
||||
#define _AT_WLAN_INFO_ "ATW?"
|
||||
|
||||
#ifndef CONFIG_SSL_CLIENT
|
||||
#define CONFIG_SSL_CLIENT 0
|
||||
#endif
|
||||
#ifndef CONFIG_WEBSERVER
|
||||
#define CONFIG_WEBSERVER 0
|
||||
#endif
|
||||
#ifndef CONFIG_OTA_UPDATE
|
||||
#define CONFIG_OTA_UPDATE 0
|
||||
#endif
|
||||
#ifndef CONFIG_BSD_TCP
|
||||
#define CONFIG_BSD_TCP 1
|
||||
#endif
|
||||
#ifndef CONFIG_ENABLE_P2P
|
||||
#define CONFIG_ENABLE_P2P 0
|
||||
#endif
|
||||
#define SCAN_WITH_SSID 0
|
||||
#if CONFIG_WEBSERVER
|
||||
#define CONFIG_READ_FLASH 1
|
||||
extern rtw_wifi_setting_t wifi_setting;
|
||||
#endif
|
||||
#if CONFIG_WLAN
|
||||
|
||||
extern void cmd_promisc(int argc, char **argv);
|
||||
extern void cmd_update(int argc, char **argv);
|
||||
extern void cmd_tcp(int argc, char **argv);
|
||||
extern void cmd_udp(int argc, char **argv);
|
||||
extern void cmd_simple_config(int argc, char **argv);
|
||||
#if CONFIG_ENABLE_WPS
|
||||
extern void cmd_wps(int argc, char **argv);
|
||||
#endif
|
||||
extern void cmd_ssl_client(int argc, char **argv);
|
||||
#ifdef CONFIG_WPS_AP
|
||||
extern void cmd_ap_wps(int argc, char **argv);
|
||||
extern int wpas_wps_dev_config(u8 *dev_addr, u8 bregistrar);
|
||||
#endif //CONFIG_WPS_AP
|
||||
#if CONFIG_ENABLE_P2P
|
||||
extern void cmd_wifi_p2p_start(int argc, char **argv);
|
||||
extern void cmd_wifi_p2p_stop(int argc, char **argv);
|
||||
extern void cmd_p2p_listen(int argc, char **argv);
|
||||
extern void cmd_p2p_find(int argc, char **argv);
|
||||
extern void cmd_p2p_peers(int argc, char **argv);
|
||||
extern void cmd_p2p_info(int argc, char **argv);
|
||||
extern void cmd_p2p_disconnect(int argc, char **argv);
|
||||
extern void cmd_p2p_connect(int argc, char **argv);
|
||||
#endif //CONFIG_ENABLE_P2P
|
||||
#if CONFIG_LWIP_LAYER
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
#endif
|
||||
static rtw_network_info_t wifi = {0};
|
||||
static rtw_ap_info_t ap = {0};
|
||||
static unsigned char password[65] = {0};
|
||||
static void init_wifi_struct(void)
|
||||
{
|
||||
memset(wifi.ssid.val, 0, sizeof(wifi.ssid.val));
|
||||
memset(wifi.bssid.octet, 0, ETH_ALEN);
|
||||
memset(password, 0, sizeof(password));
|
||||
wifi.ssid.len = 0;
|
||||
wifi.password = NULL;
|
||||
wifi.password_len = 0;
|
||||
wifi.key_id = -1;
|
||||
memset(ap.ssid.val, 0, sizeof(ap.ssid.val));
|
||||
ap.ssid.len = 0;
|
||||
ap.password = NULL;
|
||||
ap.password_len = 0;
|
||||
ap.channel = 1;
|
||||
}
|
||||
|
||||
static void print_scan_result( rtw_scan_result_t* record )
|
||||
{
|
||||
RTW_API_INFO( ( "%s\t ", ( record->bss_type == RTW_BSS_TYPE_ADHOC ) ? "Adhoc" : "Infra" ) );
|
||||
RTW_API_INFO( ( MAC_FMT, MAC_ARG(record->BSSID.octet) ) );
|
||||
RTW_API_INFO( ( " %d\t ", record->signal_strength ) );
|
||||
RTW_API_INFO( ( " %d\t ", record->channel ) );
|
||||
RTW_API_INFO( ( " %d\t ", record->wps_type ) );
|
||||
RTW_API_INFO( ( "%s\t\t ", ( record->security == RTW_SECURITY_OPEN ) ? "Open" :
|
||||
( record->security == RTW_SECURITY_WEP_PSK ) ? "WEP" :
|
||||
( record->security == RTW_SECURITY_WPA_TKIP_PSK ) ? "WPA TKIP" :
|
||||
( record->security == RTW_SECURITY_WPA_AES_PSK ) ? "WPA AES" :
|
||||
( record->security == RTW_SECURITY_WPA2_AES_PSK ) ? "WPA2 AES" :
|
||||
( record->security == RTW_SECURITY_WPA2_TKIP_PSK ) ? "WPA2 TKIP" :
|
||||
( record->security == RTW_SECURITY_WPA2_MIXED_PSK ) ? "WPA2 Mixed" :
|
||||
"Unknown" ) );
|
||||
|
||||
RTW_API_INFO( ( " %s ", record->SSID.val ) );
|
||||
RTW_API_INFO( ( "\r\n" ) );
|
||||
}
|
||||
|
||||
static rtw_result_t app_scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
|
||||
{
|
||||
static int ApNum = 0;
|
||||
|
||||
if (malloced_scan_result->scan_complete != RTW_TRUE) {
|
||||
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
|
||||
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
|
||||
|
||||
RTW_API_INFO( ( "%d\t ", ++ApNum ) );
|
||||
|
||||
print_scan_result(record);
|
||||
} else{
|
||||
ApNum = 0;
|
||||
}
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
|
||||
void fATW0(void *arg){
|
||||
if(!arg){
|
||||
printf("[ATW0]Usage: ATW0=SSID\n\r");
|
||||
return;
|
||||
}
|
||||
printf("[ATW0]: _AT_WLAN_SET_SSID_ [%s]\n\r", (char*)arg);
|
||||
strcpy((char *)wifi.ssid.val, (char*)arg);
|
||||
wifi.ssid.len = strlen((char*)arg);
|
||||
}
|
||||
|
||||
void fATW1(void *arg){
|
||||
printf("[ATW1]: _AT_WLAN_SET_PASSPHRASE_ [%s]\n\r", (char*)arg);
|
||||
strcpy((char *)password, (char*)arg);
|
||||
wifi.password = password;
|
||||
wifi.password_len = strlen((char*)arg);
|
||||
|
||||
/*
|
||||
* note:rtw_wx_set_passphrase will clear psecuritypriv->wpa_passphrase when len=64
|
||||
* so psk_derive will return because passphrase[0] == 0, then psk_passphrase
|
||||
* will not be set. Here set psk_passphrase64 to make restore_wifi_info_to_flash working
|
||||
*
|
||||
*/
|
||||
extern unsigned char psk_passphrase64[64 + 1];
|
||||
if (wifi.password_len == 64)
|
||||
strcpy(psk_passphrase64, wifi.password);
|
||||
}
|
||||
|
||||
void fATW2(void *arg){
|
||||
printf("[ATW2]: _AT_WLAN_SET_KEY_ID_ [%s]\n\r", (char*)arg);
|
||||
if((strlen((const char *)arg) != 1 ) || (*(char*)arg <'0' ||*(char*)arg >'3')) {
|
||||
printf("\n\rWrong WEP key id. Must be one of 0,1,2, or 3.");
|
||||
return;
|
||||
}
|
||||
wifi.key_id = atoi((const char *)(arg));
|
||||
}
|
||||
|
||||
void fATW3(void *arg){
|
||||
if(!arg){
|
||||
printf("[ATW3]Usage: ATW3=SSID\n\r");
|
||||
return;
|
||||
}
|
||||
|
||||
ap.ssid.len = strlen((char*)arg);
|
||||
|
||||
if(ap.ssid.len > 32){
|
||||
printf("[ATW3]Error: SSID length can't exceed 32\n\r");
|
||||
return;
|
||||
}
|
||||
strcpy((char *)ap.ssid.val, (char*)arg);
|
||||
|
||||
printf("[ATW3]: _AT_WLAN_AP_SET_SSID_ [%s]\n\r", ap.ssid.val);
|
||||
}
|
||||
|
||||
void fATW4(void *arg){
|
||||
strcpy((char *)password, (char*)arg);
|
||||
ap.password = password;
|
||||
ap.password_len = strlen((char*)arg);
|
||||
printf("[ATW4]: _AT_WLAN_AP_SET_SEC_KEY_ [%s]\n\r", ap.password);
|
||||
}
|
||||
|
||||
void fATW5(void *arg){
|
||||
ap.channel = (unsigned char) atoi((const char *)arg);
|
||||
printf("[ATW5]: _AT_WLAN_AP_SET_CHANNEL_ [channel %d]\n\r", ap.channel);
|
||||
}
|
||||
|
||||
void fATW6(void *arg){
|
||||
u32 mac[ETH_ALEN];
|
||||
u32 i;
|
||||
if(!arg){
|
||||
printf("[ATW6]Usage: ATW6=BSSID\n\r");
|
||||
return;
|
||||
}
|
||||
printf("[ATW6]: _AT_WLAN_SET_BSSID_ [%s]\n\r", (char*)arg);
|
||||
sscanf(arg, MAC_FMT, mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5);
|
||||
for(i = 0; i < ETH_ALEN; i ++)
|
||||
wifi.bssid.octet[i] = (u8)mac[i] & 0xFF;
|
||||
}
|
||||
|
||||
void fATWA(void *arg){
|
||||
#if CONFIG_LWIP_LAYER
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
struct netif * pnetif = &xnetif[0];
|
||||
#endif
|
||||
int timeout = 20;
|
||||
printf("[ATWA]: _AT_WLAN_AP_ACTIVATE_\n\r");
|
||||
if(ap.ssid.val[0] == 0){
|
||||
printf("[ATWA]Error: SSID can't be empty\n\r");
|
||||
return;
|
||||
}
|
||||
if(ap.password == NULL){
|
||||
ap.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
else{
|
||||
ap.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
|
||||
#if CONFIG_WEBSERVER
|
||||
//store into flash
|
||||
memset(wifi_setting.ssid, 0, sizeof(wifi_setting.ssid));;
|
||||
memcpy(wifi_setting.ssid, ap.ssid.val, strlen((char*)ap.ssid.val));
|
||||
wifi_setting.ssid[ap.ssid.len] = '\0';
|
||||
wifi_setting.security_type = ap.security_type;
|
||||
if(ap.security_type !=0)
|
||||
wifi_setting.security_type = 1;
|
||||
else
|
||||
wifi_setting.security_type = 0;
|
||||
if (ap.password)
|
||||
memcpy(wifi_setting.password, ap.password, strlen((char*)ap.password));
|
||||
else
|
||||
memset(wifi_setting.password, 0, sizeof(wifi_setting.password));;
|
||||
wifi_setting.channel = ap.channel;
|
||||
#if CONFIG_READ_FLASH
|
||||
StoreApInfo();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_LWIP_LAYER
|
||||
dhcps_deinit();
|
||||
IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
netif_set_addr(pnetif, &ipaddr, &netmask,&gw);
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
pnetif->flags |= NETIF_FLAG_IPSWITCH;
|
||||
#endif
|
||||
#endif
|
||||
wifi_off();
|
||||
vTaskDelay(20);
|
||||
if (wifi_on(RTW_MODE_AP) < 0){
|
||||
printf("\n\rERROR: Wifi on failed!");
|
||||
return;
|
||||
}
|
||||
printf("\n\rStarting AP ...");
|
||||
|
||||
#ifdef CONFIG_WPS_AP
|
||||
wpas_wps_dev_config(pnetif->hwaddr, 1);
|
||||
#endif
|
||||
if(wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) {
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
char essid[33];
|
||||
|
||||
if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) > 0) {
|
||||
if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) {
|
||||
printf("\n\r%s started\n", ap.ssid.val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(timeout == 0) {
|
||||
printf("\n\rERROR: Start AP timeout!");
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(1 * configTICK_RATE_HZ);
|
||||
timeout --;
|
||||
}
|
||||
#if CONFIG_LWIP_LAYER
|
||||
//LwIP_UseStaticIP(pnetif);
|
||||
dhcps_init(pnetif);
|
||||
#endif
|
||||
|
||||
init_wifi_struct( );
|
||||
}
|
||||
void fATWC(void *arg){
|
||||
int mode, ret;
|
||||
unsigned long tick1 = xTaskGetTickCount();
|
||||
unsigned long tick2, tick3;
|
||||
char empty_bssid[6] = {0}, assoc_by_bssid = 0;
|
||||
|
||||
printf("[ATWC]: _AT_WLAN_JOIN_NET_\n\r");
|
||||
if(memcmp (wifi.bssid.octet, empty_bssid, 6))
|
||||
assoc_by_bssid = 1;
|
||||
else if(wifi.ssid.val[0] == 0){
|
||||
printf("[ATWC]Error: SSID can't be empty\n\r");
|
||||
goto EXIT;
|
||||
}
|
||||
if(wifi.password != NULL){
|
||||
if((wifi.key_id >= 0)&&(wifi.key_id <= 3)) {
|
||||
wifi.security_type = RTW_SECURITY_WEP_PSK;
|
||||
}
|
||||
else{
|
||||
wifi.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
}
|
||||
else{
|
||||
wifi.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
//Check if in AP mode
|
||||
wext_get_mode(WLAN0_NAME, &mode);
|
||||
if(mode == IW_MODE_MASTER) {
|
||||
#if CONFIG_LWIP_LAYER
|
||||
dhcps_deinit();
|
||||
#endif
|
||||
wifi_off();
|
||||
vTaskDelay(20);
|
||||
if (wifi_on(RTW_MODE_STA) < 0){
|
||||
printf("\n\rERROR: Wifi on failed!");
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
if(assoc_by_bssid){
|
||||
printf("\n\rJoining BSS by BSSID "MAC_FMT" ...\n\r", MAC_ARG(wifi.bssid.octet));
|
||||
ret = wifi_connect_bssid(wifi.bssid.octet, (char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password,
|
||||
ETH_ALEN, wifi.ssid.len, wifi.password_len, wifi.key_id, NULL);
|
||||
} else {
|
||||
printf("\n\rJoining BSS by SSID %s...\n\r", (char*)wifi.ssid.val);
|
||||
ret = wifi_connect((char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password, wifi.ssid.len,
|
||||
wifi.password_len, wifi.key_id, NULL);
|
||||
}
|
||||
|
||||
if(ret!= RTW_SUCCESS){
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
goto EXIT;
|
||||
}
|
||||
tick2 = xTaskGetTickCount();
|
||||
printf("\r\nConnected after %dms.\n", (tick2-tick1));
|
||||
#if CONFIG_LWIP_LAYER
|
||||
/* Start DHCPClient */
|
||||
LwIP_DHCP(0, DHCP_START);
|
||||
tick3 = xTaskGetTickCount();
|
||||
printf("\r\n\nGot IP after %dms.\n", (tick3-tick1));
|
||||
#endif
|
||||
printf("\n\r");
|
||||
EXIT:
|
||||
init_wifi_struct( );
|
||||
}
|
||||
|
||||
void fATWD(void *arg){
|
||||
int timeout = 20;
|
||||
char essid[33];
|
||||
printf("[ATWD]: _AT_WLAN_DISC_NET_\n\r");
|
||||
printf("\n\rDeassociating AP ...");
|
||||
|
||||
if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
|
||||
printf("\n\rWIFI disconnected");
|
||||
return;
|
||||
}
|
||||
|
||||
if(wifi_disconnect() < 0) {
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
|
||||
printf("\n\rWIFI disconnected");
|
||||
break;
|
||||
}
|
||||
|
||||
if(timeout == 0) {
|
||||
printf("\n\rERROR: Deassoc timeout!");
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(1 * configTICK_RATE_HZ);
|
||||
timeout --;
|
||||
}
|
||||
printf("\n\r");
|
||||
init_wifi_struct( );
|
||||
}
|
||||
|
||||
void fATWS(void *arg){
|
||||
char buf[32] = {0};
|
||||
u8 *channel_list = NULL;
|
||||
u8 *pscan_config = NULL;
|
||||
int num_channel = 0;
|
||||
int i, argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWS]: _AT_WLAN_SCAN_\n\r");
|
||||
if(arg){
|
||||
strcpy(buf, arg);
|
||||
argc = parse_param(buf, argv);
|
||||
if(argc < 2)
|
||||
goto exit;
|
||||
num_channel = atoi(argv[1]);
|
||||
channel_list = (u8*)malloc(num_channel);
|
||||
if(!channel_list){
|
||||
printf("[ATWS]ERROR: Can't malloc memory for channel list\n\r");
|
||||
goto exit;
|
||||
}
|
||||
pscan_config = (u8*)malloc(num_channel);
|
||||
if(!pscan_config){
|
||||
printf("[ATWS]ERROR: Can't malloc memory for pscan_config\n\r");
|
||||
goto exit;
|
||||
}
|
||||
//parse command channel list
|
||||
for(i = 2; i <= argc -1 ; i++){
|
||||
*(channel_list + i - 2) = (u8)atoi(argv[i]);
|
||||
*(pscan_config + i - 2) = PSCAN_ENABLE;
|
||||
}
|
||||
|
||||
if(wifi_set_pscan_chan(channel_list, pscan_config, num_channel) < 0){
|
||||
printf("[ATWS]ERROR: wifi set partial scan channel fail\n\r");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if(wifi_scan_networks(app_scan_result_handler, NULL ) != RTW_SUCCESS){
|
||||
printf("[ATWS]ERROR: wifi scan failed\n\r");
|
||||
goto exit;
|
||||
}
|
||||
exit:
|
||||
if(arg && channel_list)
|
||||
free(channel_list);
|
||||
}
|
||||
|
||||
#if SCAN_WITH_SSID
|
||||
void fATWs(void *arg){
|
||||
char buf[32] = {0};
|
||||
u8 *channel_list = NULL;
|
||||
int scan_buf_len = 500;
|
||||
int num_channel = 0;
|
||||
int i, argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWs]: _AT_WLAN_SCAN_WITH_SSID_ [%s]\n\r", (char*)wifi.ssid.val);
|
||||
if(arg){
|
||||
strcpy(buf, arg);
|
||||
argc = parse_param(buf, argv);
|
||||
if(argc == 2){
|
||||
scan_buf_len = atoi(argv[1]);
|
||||
}else if(argc > 2){
|
||||
num_channel = atoi(argv[1]);
|
||||
channel_list = (u8*)malloc(num_channel);
|
||||
if(!channel_list){
|
||||
printf("[ATWS]ERROR: Can't malloc memory for channel list\n\r");
|
||||
goto exit;
|
||||
}
|
||||
//parse command channel list
|
||||
for(i = 2; i <= argc -1 ; i++){
|
||||
*(channel_list + i - 2) = (u8)atoi(argv[i]);
|
||||
}
|
||||
|
||||
if(wifi_set_pscan_chan(channel_list, num_channel) < 0){
|
||||
printf("[ATWS]ERROR: wifi set partial scan channel fail\n\r");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
printf("[ATWs]For Scan all channel Usage: ATWs=BUFFER_LENGTH\n\r");
|
||||
printf("[ATWs]For Scan partial channel Usage: ATWs=num_channels[channel_num1, ...]\n\r");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(wifi_scan_networks_with_ssid(NULL, &scan_buf_len, wifi.ssid.val, wifi.ssid.len) != RTW_SUCCESS){
|
||||
printf("[ATWS]ERROR: wifi scan failed\n\r");
|
||||
}
|
||||
exit:
|
||||
if(arg && channel_list)
|
||||
free(channel_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATWR(void *arg){
|
||||
int rssi = 0;
|
||||
printf("[ATWR]: _AT_WLAN_GET_RSSI_\n\r");
|
||||
wifi_get_rssi(&rssi);
|
||||
printf("\n\rwifi_get_rssi: rssi = %d", rssi);
|
||||
printf("\n\r");
|
||||
}
|
||||
|
||||
void fATWP(void *arg){
|
||||
unsigned int parm = atoi((const char *)(arg));
|
||||
printf("[ATWP]: _AT_WLAN_POWER_[%s]\n\r", parm?"ON":"OFF");
|
||||
if(parm == 1){
|
||||
if(wifi_on(RTW_MODE_STA)<0){
|
||||
printf("\n\rERROR: Wifi on failed!\n");
|
||||
}
|
||||
}
|
||||
else if(parm == 0)
|
||||
{
|
||||
#if CONFIG_WEBSERVER
|
||||
stop_web_server();
|
||||
#endif
|
||||
wifi_off();
|
||||
}
|
||||
else
|
||||
printf("[ATWP]Usage: ATWP=0/1\n\r");
|
||||
}
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
void fATWB(void *arg)
|
||||
{
|
||||
int timeout = 20;//, mode;
|
||||
#if CONFIG_LWIP_LAYER
|
||||
struct netif * pnetiff = (struct netif *)&xnetif[1];
|
||||
#endif
|
||||
printf("[ATWB](_AT_WLAN_AP_STA_ACTIVATE_)\n\r");
|
||||
if(ap.ssid.val[0] == 0){
|
||||
printf("[ATWB]Error: SSID can't be empty\n\r");
|
||||
return;
|
||||
}
|
||||
if(ap.channel > 14){
|
||||
printf("[ATWB]Error:bad channel! channel is from 1 to 14\n\r");
|
||||
return;
|
||||
}
|
||||
if(ap.password == NULL){
|
||||
ap.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
else{
|
||||
ap.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
|
||||
#if CONFIG_LWIP_LAYER
|
||||
dhcps_deinit();
|
||||
#endif
|
||||
|
||||
wifi_off();
|
||||
vTaskDelay(20);
|
||||
if (wifi_on(RTW_MODE_STA_AP) < 0){
|
||||
printf("\n\rERROR: Wifi on failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\n\rStarting AP ...");
|
||||
if(wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) {
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
return;
|
||||
}
|
||||
while(1) {
|
||||
char essid[33];
|
||||
|
||||
if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) {
|
||||
if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) {
|
||||
printf("\n\r%s started\n", ap.ssid.val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(timeout == 0) {
|
||||
printf("\n\rERROR: Start AP timeout!");
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(1 * configTICK_RATE_HZ);
|
||||
timeout --;
|
||||
}
|
||||
#if CONFIG_LWIP_LAYER
|
||||
LwIP_UseStaticIP(&xnetif[1]);
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
pnetiff->flags |= NETIF_FLAG_IPSWITCH;
|
||||
#endif
|
||||
dhcps_init(pnetiff);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATWI(void *arg){
|
||||
int count, argc = 0;
|
||||
char buf[32] = {0};
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWI]: _AT_WLAN_PING_TEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWI]Usage: ATWI=xxxx.xxxx.xxxx.xxxx[y/loop]\n\r");
|
||||
return;
|
||||
}
|
||||
strcpy(buf, arg);
|
||||
argv[0] = "ping";
|
||||
argc = parse_param(buf, argv);
|
||||
printf("[ATWI]Target address: %s\n\r", argv[1]);
|
||||
if(argc == 2){
|
||||
printf("[ATWI]Repeat Count: 5\n\r");
|
||||
do_ping_call(argv[1], 0, 5); //Not loop, count=5
|
||||
}else{
|
||||
if(strcmp(argv[2], "loop") == 0){
|
||||
printf("[ATWI]Repeat Count: %s\n\r", "loop");
|
||||
do_ping_call(argv[1], 1, 0); //loop, no count
|
||||
}
|
||||
else{
|
||||
count = atoi(argv[2]);
|
||||
printf("[ATWI]Repeat Count: %d\n\r", count);
|
||||
do_ping_call(argv[1], 0, count); //Not loop, with count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_BSD_TCP
|
||||
void fATWT(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWT]: _AT_WLAN_TCP_TEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWT]Usage: ATWT=[-c/c,xxxx.xxxx.xxxx.xxxx,buf_len,count] or ATWT=[-s/s] or ATWT=[stop]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "tcp";
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_tcp(argc, argv);
|
||||
}
|
||||
else
|
||||
printf("[ATWT]Usage: ATWT=[-c/c,xxxx.xxxx.xxxx.xxxx,buf_len,count] or ATWT=[-s/s] or ATWT=[stop]\n\r");
|
||||
}
|
||||
|
||||
void fATWU(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWU]: _AT_WLAN_UDP_TEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWU]Usage: ATWU=[-c/c,xxxx.xxxx.xxxx.xxxx,buf_len,count] or ATWU=[-s/s] or ATWU=[stop]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "ucp";
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_udp(argc, argv);
|
||||
}
|
||||
else
|
||||
printf("[ATWU]Usage: ATWU=[-c/c,xxxx.xxxx.xxxx.xxxx,buf_len,count] or ATWU=[-s/s] or ATWU=[stop]\n\r");
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATWM(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
argv[0] = "wifi_promisc";
|
||||
printf("[ATWM]: _AT_WLAN_PROMISC_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWM]Usage: ATWM=DURATION_SECONDS[with_len]");
|
||||
return;
|
||||
}
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_promisc(argc, argv);
|
||||
}
|
||||
}
|
||||
|
||||
void fATWL(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWL]: _AT_WLAN_SSL_CLIENT_\n\r");
|
||||
argv[0] = "ssl_client";
|
||||
if(!arg){
|
||||
printf("ATWL=SSL_SERVER_HOST[SRP_USER_NAME,SRP_PASSWORD]\n\r");
|
||||
return;
|
||||
}
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_ssl_client(argc, argv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if CONFIG_WEBSERVER
|
||||
void fATWE(void *arg){
|
||||
printf("[ATWE]: _AT_WLAN_START_WEB_SERVER_\n\r");
|
||||
start_web_server();
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATWQ(void *arg){
|
||||
int argc=0;
|
||||
char *argv[2] = {0};
|
||||
printf("[ATWQ]: _AT_WLAN_SIMPLE_CONFIG_\n\r");
|
||||
argv[argc++] = "wifi_simple_config";
|
||||
if(arg){
|
||||
argv[argc++] = arg;
|
||||
}
|
||||
cmd_simple_config(argc, argv);
|
||||
}
|
||||
#if CONFIG_ENABLE_WPS
|
||||
void fATWW(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWW]: _AT_WLAN_WPS_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWW]Usage: ATWW=pbc/pin\n\r");
|
||||
return;
|
||||
}
|
||||
argv[argc++] = "wifi_wps";
|
||||
argv[argc++] = arg;
|
||||
cmd_wps(argc, argv);
|
||||
}
|
||||
#endif
|
||||
void fATWw(void *arg){
|
||||
#ifdef CONFIG_WPS_AP
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWw]: _AT_WLAN_AP_WPS_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWw]Usage: ATWw=pbc/pin\n\r");
|
||||
return;
|
||||
}
|
||||
argv[argc++] = "wifi_ap_wps";
|
||||
argv[argc++] = arg;
|
||||
cmd_ap_wps(argc, argv);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CONFIG_ENABLE_P2P
|
||||
void fATWG(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWa]: _AT_WLAN_P2P_START_\n\r");
|
||||
argv[argc++] = "p2p_start";
|
||||
cmd_wifi_p2p_start(argc, argv);
|
||||
}
|
||||
void fATWH(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWb]: _AT_WLAN_P2P_STOP_\n\r");
|
||||
argv[argc++] = "p2p_stop";
|
||||
cmd_wifi_p2p_stop(argc, argv);
|
||||
}
|
||||
void fATWJ(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWc]: _AT_WLAN_P2P_CONNECT_\n\r");
|
||||
argv[0] = "p2p_connect";
|
||||
if(!arg){
|
||||
printf("ATWc=[DEST_MAC,pbc/pin]\n\r");
|
||||
return;
|
||||
}
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_p2p_connect(argc, argv);
|
||||
}
|
||||
}
|
||||
void fATWK(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWd]: _AT_WLAN_P2P_DISCONNECT_\n\r");
|
||||
argv[argc++] = "p2p_disconnect";
|
||||
cmd_p2p_disconnect(argc, argv);
|
||||
}
|
||||
void fATWN(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWe]: _AT_WLAN_P2P_INFO_\n\r");
|
||||
argv[argc++] = "p2p_info";
|
||||
cmd_p2p_info(argc, argv);
|
||||
}
|
||||
void fATWF(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWf]: _AT_WLAN_P2P_FIND_\n\r");
|
||||
argv[argc++] = "p2p_find";
|
||||
cmd_p2p_find(argc, argv);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_OTA_UPDATE
|
||||
void fATWO(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWO]: _AT_WLAN_OTA_UPDATE_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWO]Usage: ATWO=IP[PORT] or ATWO= REPOSITORY[FILE_PATH]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "update";
|
||||
if((argc = parse_param(arg, argv)) != 3){
|
||||
printf("[ATWO]Usage: ATWO=IP[PORT] or ATWO= REPOSITORY[FILE_PATH]\n\r");
|
||||
return;
|
||||
}
|
||||
cmd_update(argc, argv);
|
||||
}
|
||||
#endif
|
||||
void fATWx(void *arg){
|
||||
int i = 0;
|
||||
#if CONFIG_LWIP_LAYER
|
||||
u8 *mac = LwIP_GetMAC(&xnetif[0]);
|
||||
u8 *ip = LwIP_GetIP(&xnetif[0]);
|
||||
u8 *gw = LwIP_GetGW(&xnetif[0]);
|
||||
#endif
|
||||
u8 *ifname[2] = {WLAN0_NAME,WLAN1_NAME};
|
||||
rtw_wifi_setting_t setting;
|
||||
printf("[ATW?]: _AT_WLAN_INFO_\n\r");
|
||||
|
||||
for(i=0;i<NET_IF_NUM;i++){
|
||||
if(rltk_wlan_running(i)){
|
||||
#if CONFIG_LWIP_LAYER
|
||||
mac = LwIP_GetMAC(&xnetif[i]);
|
||||
ip = LwIP_GetIP(&xnetif[i]);
|
||||
gw = LwIP_GetGW(&xnetif[i]);
|
||||
#endif
|
||||
printf("\n\r\nWIFI %s Status: Running", ifname[i]);
|
||||
printf("\n\r==============================");
|
||||
|
||||
rltk_wlan_statistic(i);
|
||||
|
||||
wifi_get_setting((const char*)ifname[i],&setting);
|
||||
wifi_show_setting((const char*)ifname[i],&setting);
|
||||
#if CONFIG_LWIP_LAYER
|
||||
printf("\n\rInterface (%s)", ifname[i]);
|
||||
printf("\n\r==============================");
|
||||
printf("\n\r\tMAC => %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]) ;
|
||||
printf("\n\r\tIP => %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
printf("\n\r\tGW => %d.%d.%d.%d\n\r", gw[0], gw[1], gw[2], gw[3]);
|
||||
#endif
|
||||
if(setting.mode == RTW_MODE_AP || i == 1)
|
||||
{
|
||||
int client_number;
|
||||
struct {
|
||||
int count;
|
||||
rtw_mac_t mac_list[3];
|
||||
} client_info;
|
||||
|
||||
client_info.count = 3;
|
||||
wifi_get_associated_client_list(&client_info, sizeof(client_info));
|
||||
|
||||
printf("\n\rAssociated Client List:");
|
||||
printf("\n\r==============================");
|
||||
|
||||
if(client_info.count == 0)
|
||||
printf("\n\rClient Num: 0\n\r", client_info.count);
|
||||
else
|
||||
{
|
||||
printf("\n\rClient Num: %d", client_info.count);
|
||||
for( client_number=0; client_number < client_info.count; client_number++ )
|
||||
{
|
||||
printf("\n\rClient %d:", client_number + 1);
|
||||
printf("\n\r\tMAC => "MAC_FMT"",
|
||||
MAC_ARG(client_info.mac_list[client_number].octet));
|
||||
}
|
||||
printf("\n\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(configUSE_TRACE_FACILITY) && (configUSE_TRACE_FACILITY == 1) && (configUSE_STATS_FORMATTING_FUNCTIONS == 1)
|
||||
{
|
||||
signed char pcWriteBuffer[1024];
|
||||
vTaskList((char*)pcWriteBuffer);
|
||||
printf("\n\rTask List: \n\r%s", pcWriteBuffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void fATWZ(void *arg){
|
||||
char buf[32] = {0};
|
||||
char *copy = buf;
|
||||
int i = 0;
|
||||
int len = 0;
|
||||
printf("[ATWZ]: _AT_WLAN_IWPRIV_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWZ]Usage: ATWZ=COMMAND[PARAMETERS]\n\r");
|
||||
return;
|
||||
}
|
||||
strcpy(copy, arg);
|
||||
len = strlen(copy);
|
||||
do{
|
||||
if((*(copy+i)=='['))
|
||||
*(copy+i)=' ';
|
||||
if((*(copy+i)==']')||(*(copy+i)=='\0')){
|
||||
*(copy+i)='\0';
|
||||
break;
|
||||
}
|
||||
}while((i++) < len);
|
||||
wext_private_command(WLAN0_NAME, copy, 1);
|
||||
}
|
||||
|
||||
void print_wlan_help(void *arg){
|
||||
printf("\n\rWLAN AT COMMAND SET:");
|
||||
printf("\n\r==============================");
|
||||
printf("\n\r1. Wlan Scan for Network Access Point");
|
||||
printf("\n\r # ATWS");
|
||||
printf("\n\r2. Connect to an AES AP");
|
||||
printf("\n\r # ATW0=SSID");
|
||||
printf("\n\r # ATW1=PASSPHRASE");
|
||||
printf("\n\r # ATWC");
|
||||
printf("\n\r3. Create an AES AP");
|
||||
printf("\n\r # ATW3=SSID");
|
||||
printf("\n\r # ATW4=PASSPHRASE");
|
||||
printf("\n\r # ATW5=CHANNEL");
|
||||
printf("\n\r # ATWA");
|
||||
printf("\n\r4. Ping");
|
||||
printf("\n\r # ATWI=xxx.xxx.xxx.xxx");
|
||||
}
|
||||
|
||||
log_item_t at_wifi_items[ ] = {
|
||||
{"ATW0", fATW0,},
|
||||
{"ATW1", fATW1,},
|
||||
{"ATW2", fATW2,},
|
||||
{"ATW3", fATW3,},
|
||||
{"ATW4", fATW4,},
|
||||
{"ATW5", fATW5,},
|
||||
{"ATW6", fATW6,},
|
||||
{"ATWA", fATWA,},
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
{"ATWB", fATWB,},
|
||||
#endif
|
||||
{"ATWC", fATWC,},
|
||||
{"ATWD", fATWD,},
|
||||
{"ATWP", fATWP,},
|
||||
{"ATWR", fATWR,},
|
||||
{"ATWS", fATWS,},
|
||||
#if SCAN_WITH_SSID
|
||||
{"ATWs", fATWs,},
|
||||
#endif
|
||||
{"ATWM", fATWM,},
|
||||
{"ATWZ", fATWZ,},
|
||||
#if CONFIG_OTA_UPDATE
|
||||
{"ATWO", fATWO,},
|
||||
#endif
|
||||
#if CONFIG_WEBSERVER
|
||||
{"ATWE", fATWE,},
|
||||
#endif
|
||||
#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
|
||||
{"ATWQ", fATWQ,},
|
||||
#endif
|
||||
#ifdef CONFIG_WPS
|
||||
#if CONFIG_ENABLE_WPS
|
||||
{"ATWW", fATWW,},
|
||||
#endif
|
||||
{"ATWw", fATWw,}, //wps registrar for softap
|
||||
#if CONFIG_ENABLE_P2P
|
||||
{"ATWG", fATWG,}, //p2p start
|
||||
{"ATWH", fATWH,}, //p2p stop
|
||||
{"ATWJ", fATWJ,}, //p2p connect
|
||||
{"ATWK", fATWK,}, //p2p disconnect
|
||||
{"ATWN", fATWN,}, //p2p info
|
||||
{"ATWF", fATWF,}, //p2p find
|
||||
#endif
|
||||
#endif
|
||||
#if CONFIG_SSL_CLIENT
|
||||
{"ATWL", fATWL,},
|
||||
#endif
|
||||
#if CONFIG_LWIP_LAYER
|
||||
{"ATWI", fATWI,},
|
||||
#if CONFIG_BSD_TCP
|
||||
{"ATWT", fATWT,},
|
||||
{"ATWU", fATWU,},
|
||||
#endif
|
||||
#endif
|
||||
{"ATW?", fATWx,},
|
||||
{"ATW+ABC", fATWx,}
|
||||
};
|
||||
|
||||
void at_wifi_init(void)
|
||||
{
|
||||
init_wifi_struct();
|
||||
log_service_add_table(at_wifi_items, sizeof(at_wifi_items)/sizeof(at_wifi_items[0]));
|
||||
}
|
||||
|
||||
log_module_init(at_wifi_init);
|
||||
|
||||
#endif // end of #if CONFIG_WLAN
|
||||
#endif //end of #if SUPPORT_LOG_SERVICE
|
||||
67
component/common/api/at_cmd/atcmd_wifi.h
Normal file
67
component/common/api/at_cmd/atcmd_wifi.h
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#ifndef __ATCMD_WIFI_H__
|
||||
#define __ATCMD_WIFI_H__
|
||||
#include "main.h"
|
||||
#ifndef WLAN0_NAME
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#endif
|
||||
#ifndef WLAN1_NAME
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#endif
|
||||
/* Give default value if not defined */
|
||||
#ifndef NET_IF_NUM
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
#define NET_IF_NUM 2
|
||||
#else
|
||||
#define NET_IF_NUM 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef IP_ADDR0
|
||||
#define IP_ADDR0 192
|
||||
#define IP_ADDR1 168
|
||||
#define IP_ADDR2 1
|
||||
#define IP_ADDR3 80
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef NETMASK_ADDR0
|
||||
#define NETMASK_ADDR0 255
|
||||
#define NETMASK_ADDR1 255
|
||||
#define NETMASK_ADDR2 255
|
||||
#define NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef GW_ADDR0
|
||||
#define GW_ADDR0 192
|
||||
#define GW_ADDR1 168
|
||||
#define GW_ADDR2 1
|
||||
#define GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef AP_IP_ADDR0
|
||||
#define AP_IP_ADDR0 192
|
||||
#define AP_IP_ADDR1 168
|
||||
#define AP_IP_ADDR2 43
|
||||
#define AP_IP_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef AP_NETMASK_ADDR0
|
||||
#define AP_NETMASK_ADDR0 255
|
||||
#define AP_NETMASK_ADDR1 255
|
||||
#define AP_NETMASK_ADDR2 255
|
||||
#define AP_NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef AP_GW_ADDR0
|
||||
#define AP_GW_ADDR0 192
|
||||
#define AP_GW_ADDR1 168
|
||||
#define AP_GW_ADDR2 43
|
||||
#define AP_GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
323
component/common/api/at_cmd/log_service.c
Normal file
323
component/common/api/at_cmd/log_service.c
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "FreeRTOS.h"
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
#include "log_service.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "main.h"
|
||||
#include "wifi_util.h"
|
||||
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
//======================================================
|
||||
struct list_head log_hash[ATC_INDEX_NUM];
|
||||
|
||||
extern void at_wifi_init(void);
|
||||
extern void at_fs_init(void);
|
||||
extern void at_sys_init(void);
|
||||
//extern void at_app_init(void);
|
||||
char log_buf[LOG_SERVICE_BUFLEN];
|
||||
#if CONFIG_LOG_HISTORY
|
||||
char log_history[LOG_HISTORY_LEN][LOG_SERVICE_BUFLEN];
|
||||
static unsigned int log_history_count = 0;
|
||||
#endif
|
||||
xSemaphoreHandle log_rx_interrupt_sema = NULL;
|
||||
extern xSemaphoreHandle uart_rx_interrupt_sema;
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
#pragma section=".data.log_init"
|
||||
|
||||
unsigned int __log_init_begin__;
|
||||
unsigned int __log_init_end__;
|
||||
#elif defined ( __CC_ARM )
|
||||
//#pragma section=".data.log_init"
|
||||
log_init_t* __log_init_begin__;
|
||||
log_init_t* __log_init_end__;
|
||||
log_init_t log_init_table[] = {
|
||||
at_wifi_init,
|
||||
at_fs_init,
|
||||
at_sys_init
|
||||
// at_app_init
|
||||
};
|
||||
#else
|
||||
#error "not implement, add to linker script"
|
||||
extern unsigned int __log_init_begin__;
|
||||
extern unsigned int __log_init_end__;
|
||||
#endif
|
||||
|
||||
//======================================================
|
||||
int hash_index(char *str)
|
||||
{
|
||||
unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
|
||||
unsigned int hash = 0;
|
||||
|
||||
while (*str)
|
||||
{
|
||||
hash = hash * seed + (*str++);
|
||||
}
|
||||
|
||||
return (hash & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
void log_add_new_command(log_item_t *new)
|
||||
{
|
||||
int index = hash_index(new->log_cmd)%ATC_INDEX_NUM;
|
||||
|
||||
list_add(&new->node, &log_hash[index]);
|
||||
}
|
||||
void start_log_service(void);
|
||||
void log_service_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
log_init_t *log_init_table;
|
||||
__log_init_begin__ = (unsigned int)__section_begin(".data.log_init");
|
||||
__log_init_end__ = (unsigned int)__section_end(".data.log_init");
|
||||
log_init_table = (log_init_t *)__log_init_begin__;
|
||||
#elif defined(__CC_ARM)
|
||||
__log_init_begin__ = log_init_table;
|
||||
__log_init_end__ = log_init_table + sizeof(log_init_table);
|
||||
#else
|
||||
#error "not implement"
|
||||
#endif
|
||||
|
||||
|
||||
for(i=0;i<ATC_INDEX_NUM;i++)
|
||||
INIT_LIST_HEAD(&log_hash[i]);
|
||||
|
||||
for(i=0;i<(__log_init_end__-__log_init_begin__)/sizeof(log_init_t); i++)
|
||||
log_init_table[i]();
|
||||
|
||||
/* Initial uart rx swmaphore*/
|
||||
vSemaphoreCreateBinary(log_rx_interrupt_sema);
|
||||
xSemaphoreTake(log_rx_interrupt_sema, 1/portTICK_RATE_MS);
|
||||
start_log_service();
|
||||
}
|
||||
|
||||
//sizeof(log_items)/sizeof(log_items[0])
|
||||
void log_service_add_table(log_item_t *tbl, int len)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<len;i++)
|
||||
log_add_new_command(&tbl[i]);
|
||||
}
|
||||
|
||||
void* log_action(char *cmd)
|
||||
{
|
||||
int search_cnt=0;
|
||||
int index = hash_index(cmd)%ATC_INDEX_NUM;
|
||||
struct list_head *head = &log_hash[index];
|
||||
struct list_head *iterator;
|
||||
log_item_t *item;
|
||||
void *act = NULL;
|
||||
|
||||
list_for_each(iterator, head) {
|
||||
item = list_entry(iterator, log_item_t, node);
|
||||
search_cnt++;
|
||||
if( strcmp(item->log_cmd, cmd) == 0){
|
||||
//printf("%s match %s, search cnt %d\n\r", cmd, item->log_cmd, search_cnt);
|
||||
act = (void*)item->at_act;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return act;
|
||||
}
|
||||
|
||||
void* log_handler(char *cmd)
|
||||
{
|
||||
log_act_t action=NULL;
|
||||
char buf[100] = {0};
|
||||
char *copy=buf;
|
||||
char *token = NULL;
|
||||
char *param = NULL;
|
||||
char tok[5] = {0};//'\0'
|
||||
#if CONFIG_LOG_HISTORY
|
||||
strcpy(log_history[((log_history_count++)%LOG_HISTORY_LEN)], log_buf);
|
||||
#endif
|
||||
strcpy(copy, cmd);
|
||||
//token = _strsep(©, "=");
|
||||
token = strtok(copy, "=");
|
||||
if(token && (strlen(token) <= 4))
|
||||
strcpy(tok, token);
|
||||
else{
|
||||
//printf("\n\rAT Cmd format error!\n");
|
||||
return NULL;
|
||||
};
|
||||
//printf(" Command %s \n\r ", tok);
|
||||
param = strtok(NULL, NULL);
|
||||
//printf(" Param %s \n\r", param);
|
||||
action = (log_act_t)log_action(tok);
|
||||
|
||||
if(action){
|
||||
action(param);
|
||||
}
|
||||
return (void*)action;
|
||||
|
||||
}
|
||||
|
||||
int parse_param(char *buf, char **argv)
|
||||
{
|
||||
int argc = 1;
|
||||
while((argc < MAX_ARGC) && (*buf != '\0')) {
|
||||
while((*buf == '[')||(*buf == ' '))
|
||||
buf ++;
|
||||
if((*buf == ']')||(*buf == '\0'))
|
||||
break;
|
||||
argv[argc] = buf;
|
||||
argc ++;
|
||||
buf ++;
|
||||
|
||||
while((*buf != ',')&&(*buf != '[')&&(*buf != ']')&&(*buf != '\0'))
|
||||
buf ++;
|
||||
|
||||
while((*buf == ',')||(*buf == '[')||(*buf == ']')) {
|
||||
*buf = '\0';
|
||||
buf ++;
|
||||
}
|
||||
}
|
||||
return argc;
|
||||
}
|
||||
|
||||
void at_set_debug_level(unsigned char newDbgLevel)
|
||||
{
|
||||
gDbgLevel = newDbgLevel;
|
||||
}
|
||||
|
||||
void at_set_debug_mask(unsigned int newDbgFlag)
|
||||
{
|
||||
gDbgFlag = newDbgFlag;
|
||||
}
|
||||
|
||||
#if SUPPORT_INTERACTIVE_MODE
|
||||
extern char uart_buf[64];
|
||||
void legency_interactive_handler(unsigned char argc, unsigned char **argv)
|
||||
{
|
||||
#if 0 //defined(CONFIG_PLATFORM_8195A)
|
||||
if(argc<1)
|
||||
{
|
||||
DiagPrintf("Wrong argument number!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DiagPrintf("Wlan Normal Mode\n");
|
||||
|
||||
WlanNormal( argc, argv);
|
||||
#else
|
||||
strncpy(uart_buf, log_buf, 63);//uart_buf[64]
|
||||
xSemaphoreGive(uart_rx_interrupt_sema);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_WLAN
|
||||
#ifndef WLAN0_NAME
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#endif
|
||||
#ifndef WLAN1_NAME
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#endif
|
||||
int mp_commnad_handler(char *cmd)
|
||||
{
|
||||
char buf[64] = {0};
|
||||
char *token = NULL;
|
||||
|
||||
strcpy(buf, cmd);
|
||||
token = strtok(buf, " ");
|
||||
if(token && (strcmp(buf, "iwpriv") == 0)){
|
||||
token = strtok(NULL, "");
|
||||
wext_private_command(WLAN0_NAME, token, 1);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
void print_help_msg(void){
|
||||
#if CONFIG_WLAN
|
||||
extern void print_wlan_help(void);
|
||||
print_wlan_help();
|
||||
#endif
|
||||
//add other help message print here
|
||||
}
|
||||
|
||||
int print_help_handler(char *cmd){
|
||||
if(strcmp(cmd, "help") == 0){
|
||||
print_help_msg();
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void log_service(void *param)
|
||||
{
|
||||
printf("\n\rStart LOG SERVICE MODE\n\r");
|
||||
printf("\n\r# ");
|
||||
while(1){
|
||||
while(xSemaphoreTake(log_rx_interrupt_sema, portMAX_DELAY) != pdTRUE);
|
||||
if(log_handler((char *)log_buf) == NULL){
|
||||
#if CONFIG_WLAN
|
||||
if(mp_commnad_handler((char *)log_buf) < 0)
|
||||
#endif
|
||||
{
|
||||
#if SUPPORT_INTERACTIVE_MODE
|
||||
print_help_handler((char *)log_buf);
|
||||
legency_interactive_handler(NULL, NULL);
|
||||
continue;
|
||||
#else
|
||||
if(print_help_handler((char *)log_buf) < 0){
|
||||
printf("\n\runknown command '%s'", log_buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
log_buf[0] = '\0';
|
||||
printf("\n\r[MEM] After do cmd, available heap %d\n\r", xPortGetFreeHeapSize());
|
||||
printf("\r\n\n# ");
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
release_wakelock(WAKELOCK_LOGUART);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#define STACKSIZE 1280
|
||||
void start_log_service(void)
|
||||
{
|
||||
if(xTaskCreate(log_service, (char const*)"log_service", STACKSIZE, NULL, tskIDLE_PRIORITY + 5, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate failed", __FUNCTION__);
|
||||
}
|
||||
void fAT_exit(void *arg){
|
||||
printf("\n\rLeave LOG SERVICE");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
#if CONFIG_LOG_HISTORY
|
||||
void fAT_log(void *arg){
|
||||
int i = 0;
|
||||
printf("[AT]log history:\n\n\r");
|
||||
if(log_history_count > LOG_HISTORY_LEN){
|
||||
for(i=0; i<4; i++)
|
||||
printf(" %s\n\r", log_history[((log_history_count+i)%LOG_HISTORY_LEN)]);
|
||||
}
|
||||
else{
|
||||
for(i=0; i<(log_history_count-1); i++)
|
||||
printf(" %s\n\r", log_history[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
log_item_t at_log_items[ ] = {
|
||||
{"AT--", fAT_exit,},
|
||||
#if CONFIG_LOG_HISTORY
|
||||
{"AT??", fAT_log,},
|
||||
#endif
|
||||
{"ATxx", fAT_exit,}
|
||||
};
|
||||
void at_log_init(void)
|
||||
{
|
||||
log_service_add_table(at_log_items, sizeof(at_log_items)/sizeof(at_log_items[0]));
|
||||
}
|
||||
log_module_init(at_log_init);
|
||||
#endif
|
||||
95
component/common/api/at_cmd/log_service.h
Normal file
95
component/common/api/at_cmd/log_service.h
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#ifndef LOG_SERVICE_H
|
||||
#define LOG_SERVICE_H
|
||||
|
||||
#include "dlist.h"
|
||||
/*
|
||||
* Include user defined options first. Anything not defined in these files
|
||||
* will be set to standard values. Override anything you dont like!
|
||||
*/
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#include "platform_opts.h"
|
||||
#endif
|
||||
|
||||
#ifdef __ICCARM__
|
||||
#define STRINGIFY(s) #s
|
||||
#define SECTION(_name) _Pragma( STRINGIFY(location=##_name##))
|
||||
#define log_module_init(fn) \
|
||||
SECTION(".data.log_init") __root static void* log_##fn = (void*)fn
|
||||
#elif defined(__CC_ARM)
|
||||
#define log_module_init(fn) \
|
||||
static void* log_##fn __attribute__((section(".data.log_init"))) = (void*)fn;
|
||||
#define DiagPrintf printf
|
||||
#else
|
||||
#error "not implement"
|
||||
#endif
|
||||
|
||||
#define ATC_INDEX_NUM 32
|
||||
|
||||
#ifndef SUPPORT_LOG_SERVICE
|
||||
#define SUPPORT_LOG_SERVICE 1
|
||||
#endif
|
||||
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
|
||||
//LOG_SERVICE_BUFLEN: default, only 63 bytes could be used for keeping input
|
||||
// cmd, the last byte is for string end ('\0').
|
||||
#ifndef LOG_SERVICE_BUFLEN
|
||||
#define LOG_SERVICE_BUFLEN 64
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_HISTORY
|
||||
#define CONFIG_LOG_HISTORY 0
|
||||
#if CONFIG_LOG_HISTORY
|
||||
#define LOG_HISTORY_LEN 5
|
||||
#endif
|
||||
#endif //#ifndef CONFIG_LOG_HISTORY
|
||||
|
||||
#ifndef MAX_ARGC
|
||||
#define MAX_ARGC 6
|
||||
#endif
|
||||
|
||||
#define AT_BIT(n) (1<<n)
|
||||
#define AT_FLAG_DUMP AT_BIT(0)
|
||||
#define AT_FLAG_EDIT AT_BIT(1)
|
||||
#define AT_FLAG_ADC AT_BIT(2)
|
||||
#define AT_FLAG_GPIO AT_BIT(3)
|
||||
#define AT_FLAG_OTA AT_BIT(4)
|
||||
#define AT_FLAG_NFC AT_BIT(5)
|
||||
#define AT_FLAG_OS AT_BIT(6)
|
||||
|
||||
enum{
|
||||
AT_DBG_OFF = 0,
|
||||
AT_DBG_ALWAYS,
|
||||
AT_DBG_ERROR,
|
||||
AT_DBG_WARNING,
|
||||
AT_DBG_INFO
|
||||
};
|
||||
|
||||
static unsigned char gDbgLevel = AT_DBG_ERROR;
|
||||
static unsigned int gDbgFlag = 0xFFFFFFFF;
|
||||
|
||||
#define AT_PRINTK(fmt, args...) printf(fmt"\r\n",## args)
|
||||
#define AT_DBG_MSG(flag, level, fmt, args...) \
|
||||
do{ \
|
||||
if(((flag) & gDbgFlag) && (level <= gDbgLevel)){ \
|
||||
AT_PRINTK(fmt,## args); \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#ifndef SUPPORT_INTERACTIVE_MODE
|
||||
#define SUPPORT_INTERACTIVE_MODE 0
|
||||
#endif //#ifndef SUPPORT_INTERACTIVE_MODE
|
||||
#endif
|
||||
|
||||
typedef void (*log_init_t)(void);
|
||||
typedef void (*log_act_t)(void*);
|
||||
typedef struct _at_command_item_{
|
||||
char *log_cmd;
|
||||
log_act_t at_act;
|
||||
struct list_head node;
|
||||
}log_item_t;
|
||||
|
||||
void log_service_add_table(log_item_t *tbl, int len);
|
||||
int parse_param(char *buf, char **argv);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue