first commit and add gitignore, README.md

This commit is contained in:
ChesterTseng 2016-06-04 19:09:35 +08:00
commit 760756ba2c
1861 changed files with 709236 additions and 0 deletions

View file

@ -0,0 +1,196 @@
#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/google_nest.h"
#include <cJSON.h>
#include <platform_opts.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");
}
#if CONFIG_GOOGLE_NEST
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);
#endif

View file

@ -0,0 +1,481 @@
#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"
#include "osdep_api.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[]);
#if SUPPORT_UART_YMODEM
extern int uart_ymodem(void);
#endif
#if (configGENERATE_RUN_TIME_STATS == 1)
static char cBuffer[512];
#endif
//-------- 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_UART_YMODEM
void fATSY(void *arg)
{
uart_ymodem();
}
#endif
#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;
analogin_deinit(&adc);
// 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());
#if (configGENERATE_RUN_TIME_STATS == 1)
get_wakelock_hold_stats((char *)cBuffer);
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "%s", cBuffer);
#endif
break;
#if (configGENERATE_RUN_TIME_STATS == 1)
case 'c': // clean wakelock info (for recalculate wakelock hold time)
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] clean wakelock stat");
clean_wakelock_stat();
break;
#endif
default:
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
break;
}
}
#endif
#if (configGENERATE_RUN_TIME_STATS == 1)
void fATSS(void *arg) // Show CPU stats
{
AT_PRINTK("[ATSS]: _AT_SYSTEM_CPU_STATS_");
vTaskGetRunTimeStats((char *)cBuffer);
AT_PRINTK("%s", cBuffer);
}
#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]);
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);
}
log_item_t at_sys_items[] = {
{"ATSD", fATSD,}, // Dump register
{"ATSE", fATSE,}, // Edit register
#if SUPPORT_UART_YMODEM
{"ATSY", fATSY,}, // uart ymodem upgrade
#endif
#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
#if (configGENERATE_RUN_TIME_STATS == 1)
{"ATSS", fATSS,}, // Show CPU stats
#endif
{"ATS@", fATSs,}, // Debug message setting
{"ATS!", fATSc,}, // Debug config setting
{"ATS#", fATSt,}, // test command
{"ATS?", fATSx,} // Help
};
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);

View file

@ -0,0 +1,5 @@
#ifndef __ATCMD_SYS_H__
#define __ATCMD_SYS_H__
#endif

File diff suppressed because it is too large Load diff

View 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

View file

@ -0,0 +1,339 @@
#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 CONFIG_INIC_EN
extern unsigned char inic_cmd_ioctl;
#endif
#if defined (__ICCARM__)
#pragma section=".data.log_init"
unsigned int __log_init_begin__;
unsigned int __log_init_end__;
#elif defined ( __CC_ARM ) || defined(__GNUC__)
//#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
#if defined(__GNUC__)
#define USE_STRSEP
#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) || defined(__GNUC__)
__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);
#if defined(USE_STRSEP)
token = _strsep(&copy, "=");
param = copy;
#else
token = strtok(copy, "=");
param = strtok(NULL, NULL);
#endif
if(token && (strlen(token) <= 4))
strcpy(tok, token);
else{
//printf("\n\rAT Cmd format error!\n");
return NULL;
};
//printf(" Command %s \n\r ", tok);
//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';
#if CONFIG_INIC_EN
inic_cmd_ioctl = 0;
#endif
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

View file

@ -0,0 +1,97 @@
#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"
#include "platform_stdlib.h"
#endif
#ifdef __ICCARM__
#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
#elif defined(__GNUC__)
#define log_module_init(fn) \
static void* log_##fn __attribute__((section(".data.log_init"))) = (void*)fn;
#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(...) do { printf(__VA_ARGS__); printf("\r\n"); } while(0)
#define AT_DBG_MSG(flag, level, ...) \
do{ \
if(((flag) & gDbgFlag) && (level <= gDbgLevel)){ \
AT_PRINTK(__VA_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