统一os_log

This commit is contained in:
zogodo
2020-02-17 21:10:13 +08:00
parent 1a7d4d5a47
commit 051a9504ee
12 changed files with 67 additions and 79 deletions

View File

@@ -94,10 +94,10 @@ static int HttpGetIndexPage(httpd_request_t *req)
OSStatus err = kNoErr;
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(index_html), HTTP_CONTENT_HTML_ZIP);
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http wifisetting headers."));
require_noerr_action(err, exit, http_log("ERROR: Unable to send http wifisetting headers."));
err = httpd_send_body(req->sock, index_html, sizeof(index_html));
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http wifisetting body."));
require_noerr_action(err, exit, http_log("ERROR: Unable to send http wifisetting body."));
exit:
return err;
@@ -284,13 +284,13 @@ static int HttpAddTask(httpd_request_t *req)
pTimedTask task = (pTimedTask)malloc(sizeof(struct TimedTask));
int re = sscanf(buf, "%ld %d %d", &task->prs_time, &task->socket_idx, &task->on);
app_httpd_log("AddTask buf[%s] re[%d] (%ld %d %d)",
http_log("AddTask buf[%s] re[%d] (%ld %d %d)",
buf, re, task->prs_time, task->socket_idx, task->on);
if (task->prs_time < 1577428136 || task->prs_time > 9577428136
|| task->socket_idx < 0 || task->socket_idx > 5
|| (task->on != 0 && task->on != 1))
{
app_httpd_log("AddTask Error!");
http_log("AddTask Error!");
re = 0;
}
@@ -305,7 +305,7 @@ static int HttpDelTask(httpd_request_t *req)
{
//TODO 从url获取时间
char* time_str = strstr(req->filename, "?time=");
app_httpd_log("HttpDelTask url[%s] time_str[%s][%s]", req->filename, time_str, time_str + 6);
http_log("HttpDelTask url[%s] time_str[%s][%s]", req->filename, time_str, time_str + 6);
int time1;
sscanf(time_str + 6, "%d", &time1);
@@ -335,7 +335,7 @@ static int OtaStart(httpd_request_t *req)
err = httpd_get_data(req, buf, 64);
require_noerr(err, exit);
app_httpd_log("OtaStart ota_url[%s]", buf);
http_log("OtaStart ota_url[%s]", buf);
UserOtaStart(buf, NULL);
send_http("OK", 2, exit, &err);
@@ -363,26 +363,26 @@ static void AppHttpRegisterHandlers()
int rc;
rc = httpd_register_wsgi_handlers(g_app_handlers, g_app_handlers_no);
if (rc) {
app_httpd_log("failed to register test web handler");
http_log("failed to register test web handler");
}
}
static int _AppHttpdStart()
{
OSStatus err = kNoErr;
app_httpd_log("initializing web-services");
http_log("initializing web-services");
/*Initialize HTTPD*/
if(is_http_init == false) {
err = httpd_init();
require_noerr_action(err, exit, app_httpd_log("failed to initialize httpd"));
require_noerr_action(err, exit, http_log("failed to initialize httpd"));
is_http_init = true;
}
/*Start http thread*/
err = httpd_start();
if(err != kNoErr) {
app_httpd_log("failed to start httpd thread");
http_log("failed to start httpd thread");
httpd_shutdown();
}
exit:
@@ -410,9 +410,9 @@ int AppHttpdStop()
OSStatus err = kNoErr;
/* HTTPD and services */
app_httpd_log("stopping down httpd");
http_log("stopping down httpd");
err = httpd_stop();
require_noerr_action(err, exit, app_httpd_log("failed to halt httpd"));
require_noerr_action(err, exit, http_log("failed to halt httpd"));
exit:
return err;

View File

@@ -34,15 +34,13 @@
#define HTTP_CONTENT_HTML_ZIP "text/html\r\nContent-Encoding: gzip"
#define app_httpd_log(M, ...) do { custom_log("apphttpd", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define HTTPD_HDR_DEFORT (HTTPD_HDR_ADD_SERVER|HTTPD_HDR_ADD_CONN_CLOSE|HTTPD_HDR_ADD_PRAGMA_NO_CACHE)
#define send_http(DATA, LEN, LABEL, P_ERR) \
*(P_ERR) = httpd_send_all_header(req, HTTP_RES_200, LEN , HTTP_CONTENT_HTML_STR); \
require_noerr_action(*(P_ERR), LABEL, app_httpd_log("ERROR: Unable to send http DATA headers.")); \
require_noerr_action(*(P_ERR), LABEL, http_log("ERROR: Unable to send http DATA headers.")); \
*(P_ERR) = httpd_send_body(req->sock, (const unsigned char*)DATA, LEN); \
require_noerr_action(*(P_ERR), LABEL, app_httpd_log("ERROR: Unable to send http DATA body.")); \
require_noerr_action(*(P_ERR), LABEL, http_log("ERROR: Unable to send http DATA body.")); \
#define TC1_STATUS_JSON \
"{\

View File

@@ -8,8 +8,6 @@
#include "http_server/app_httpd.h"
#include "timed_task/timed_task.h"
#define os_log(format, ...) do { custom_log("TC1", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
char rtc_init = 0; //sntp校时成功标志位
uint32_t total_time = 0;
char str_mac[16] = { 0 };
@@ -48,7 +46,7 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
int application_start(void)
{
int i;
os_log("start version[%s]", VERSION);
tc1_log("start version[%s]", VERSION);
//char main_num=0;
OSStatus err = kNoErr;
@@ -65,13 +63,13 @@ int application_start(void)
mico_wlan_get_mac_address(mac);
sprintf(str_mac, "%02X%02X%02X%02X%02X%02X",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
os_log("str_mac[%s]", str_mac);
tc1_log("str_mac[%s]", str_mac);
bool open_ap = false;
MicoGpioInitialize((mico_gpio_t)Button, INPUT_PULL_UP);
if (!MicoGpioInputGet(Button))
{ //开机时按钮状态
os_log("press ap_init");
tc1_log("press ap_init");
ApInit(false);
open_ap = true;
}
@@ -86,7 +84,7 @@ int application_start(void)
if (user_config->version != USER_CONFIG_VERSION)
{
os_log("WARNGIN: user params restored!");
tc1_log("WARNGIN: user params restored!");
err = mico_system_context_restore(sys_config);
require_noerr(err, exit);
}
@@ -96,13 +94,13 @@ int application_start(void)
sprintf(sys_config->micoSystemConfig.name, ZTC1_NAME, str_mac+8);
}
os_log("user:%s",user_config->user);
os_log("device name:%s",sys_config->micoSystemConfig.name);
os_log("mqtt_ip:%s",user_config->mqtt_ip);
os_log("mqtt_port:%d",user_config->mqtt_port);
os_log("mqtt_user:%s",user_config->mqtt_user);
os_log("mqtt_password:%s",user_config->mqtt_password);
os_log("version:%d",user_config->version);
tc1_log("user:%s",user_config->user);
tc1_log("device name:%s",sys_config->micoSystemConfig.name);
tc1_log("mqtt_ip:%s",user_config->mqtt_ip);
tc1_log("mqtt_port:%d",user_config->mqtt_port);
tc1_log("mqtt_user:%s",user_config->mqtt_user);
tc1_log("mqtt_password:%s",user_config->mqtt_password);
tc1_log("version:%d",user_config->version);
WifiInit();
if (!open_ap)
@@ -143,20 +141,20 @@ int application_start(void)
time_t now = time(NULL);
if (task_top && now >= task_top->prs_time)
{
os_log("process task time[%ld] socket_idx[%d] on[%d]",
tc1_log("process task time[%ld] socket_idx[%d] on[%d]",
task_top->prs_time, task_top->socket_idx, task_top->on);
UserRelaySet(task_top->socket_idx, task_top->on);
DelFirstTask();
}
else
{
//os_log("timed task count[%u]", task_count);
//tc1_log("timed task count[%u]", task_count);
}
mico_thread_msleep(1000);
}
exit:
os_log("application_start ERROR!");
tc1_log("application_start ERROR!");
if (power_buf) free(power_buf);
return 0;
}

View File

@@ -4,6 +4,15 @@
#include "mico.h"
#include "micokit_ext.h"
#define app_log(M, ...) do { custom_log("APP", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define key_log(M, ...) do { custom_log("KEY", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define ota_log(M, ...) do { custom_log("OTA", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define rtc_log(M, ...) do { custom_log("RTC", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define tc1_log(M, ...) do { custom_log("TC1", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define http_log(M, ...) do { custom_log("HTTP", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define mqtt_log(M, ...) do { custom_log("MQTT", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define wifi_log(M, ...) do { custom_log("WIFI", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define VERSION "v1.0.15"
#define TYPE 1

View File

@@ -20,9 +20,6 @@
*/
#include "http_server/web_log.h"
#define app_log(M, ...) do { custom_log("APP", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#define mqtt_log(M, ...) do { custom_log("MQTT", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#include "main.h"
#include "mico.h"
#include "MQTTClient.h"

View File

@@ -29,19 +29,13 @@
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
#include "mico.h"
#include "main.h"
#include "HTTPUtils.h"
#include "SocketUtils.h"
#include "ota_server.h"
#include "url.h"
#include "http_server/web_log.h"
#if OTA_DEBUG
#define ota_server_log(M, ...) do { custom_log("OTA", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
#else
#define ota_server_log(M, ...)
#endif
static ota_server_context_t *ota_server_context = NULL;
static HTTPHeader_t *httpHeader = NULL;
@@ -176,7 +170,7 @@ static int OtaServerSendHeader(void)
ret = OtaServerSend((char *) header, strlen(header));
// ota_server_log("send: %d\r\n%s", strlen(header), header);
// ota_log("send: %d\r\n%s", strlen(header), header);
if (header != NULL) free(header);
return ret;
}
@@ -219,7 +213,7 @@ static int OtaServerConnectServer(struct in_addr in_addr)
return -1;
}
ota_server_log("ota server connected!");
ota_log("ota server connected!");
return 0;
}
@@ -253,7 +247,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
pptr=hostent_content->h_addr_list;
in_addr.s_addr = *(uint32_t *)(*pptr);
strcpy(ota_server_context->download_url.ip, inet_ntoa(in_addr));
ota_server_log("OTA server address: %s, host ip: %s", ota_server_context->download_url.host, ota_server_context->download_url.ip);
ota_log("OTA server address: %s, host ip: %s", ota_server_context->download_url.host, ota_server_context->download_url.ip);
offset = 0;
MicoFlashErase(MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length);
@@ -309,7 +303,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
case kNoSpaceErr:
case kConnectionErr:
default:
ota_server_log("ERROR: HTTP Header parse error: %d", err);
ota_log("ERROR: HTTP Header parse error: %d", err);
break;
}
}
@@ -330,7 +324,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
mico_ota_switch_to_new_fw(ota_server_context->download_state.download_len, crc16);
mico_system_power_perform(mico_system_context_get(), eState_Software_Reset);
}else{
ota_server_log("OTA md5 check err, Calculation:%s, Get:%s", md5_value_string, ota_server_context->ota_check.md5);
ota_log("OTA md5 check err, Calculation:%s, Get:%s", md5_value_string, ota_server_context->ota_check.md5);
OtaServerProgressSet(OTA_FAIL);
}
goto DELETE;
@@ -354,7 +348,7 @@ DELETE:
ota_server_context = NULL;
}
ota_server_log("ota server thread will delete");
ota_log("ota server thread will delete");
mico_rtos_delete_thread(NULL);
}

View File

@@ -1,5 +1,4 @@
#include "http_server/web_log.h"
#define os_log(format, ...) do { custom_log("OTA", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
#include "mico.h"
#include "ota_server/ota_server.h"
@@ -15,17 +14,17 @@ static void OtaServerStatusHandler(OTA_STATE_E state, float progress)
{
case OTA_LOADING:
ota_progress = progress;
os_log("ota server is loading, progress %.2f%%", progress);
ota_log("ota server is loading, progress %.2f%%", progress);
if (((int) progress)%10 == 1)
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":%d}", str_mac,((int) progress));
break;
case OTA_SUCCE:
ota_progress = 100;
os_log("ota server daemons success");
ota_log("ota server daemons success");
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":100}", str_mac);
break;
case OTA_FAIL:
os_log("ota server daemons failed");
ota_log("ota server daemons failed");
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":-1}", str_mac);
break;
default:
@@ -36,7 +35,7 @@ static void OtaServerStatusHandler(OTA_STATE_E state, float progress)
void UserOtaStart(char *url, char *md5)
{
ota_progress = 0;
os_log("ready to ota:%s",url);
ota_log("ready to ota:%s",url);
OtaServerStart(url, md5, OtaServerStatusHandler);
}

View File

@@ -1,6 +1,4 @@
#include "http_server/web_log.h"
#define os_log(format, ...) do { custom_log("RTC", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
#include "main.h"
#include "user_gpio.h"
#include "sntp.h"
@@ -37,7 +35,7 @@ OSStatus UserSntpGetTime()
hostent_content = gethostbyname(ntp_hosts[i]);
if (hostent_content == NULL)
{
os_log("gethostbyname(%s)", ntp_hosts[i]);
rtc_log("gethostbyname(%s)", ntp_hosts[i]);
continue;
}
pptr = hostent_content->h_addr_list;
@@ -52,7 +50,7 @@ OSStatus UserSntpGetTime()
if (err != kNoErr)
{
os_log("sntp_get_time4 err[%d]", err);
rtc_log("sntp_get_time4 err[%d]", err);
return err;
}
@@ -72,7 +70,7 @@ OSStatus UserRtcInit(void)
0x1000, 0);
require_noerr_string(err, exit, "ERROR: Unable to start the rtc thread.");
if (kNoErr != err) os_log("ERROR1, app thread exit err: %d kNoErr[%d]", err, kNoErr);
if (kNoErr != err) rtc_log("ERROR1, app thread exit err: %d kNoErr[%d]", err, kNoErr);
exit:
return err;
@@ -94,7 +92,7 @@ void RtcThread(mico_thread_arg_t arg)
err = UserSntpGetTime();
if (err == kNoErr)
{
os_log("sntp success!");
rtc_log("sntp success!");
rtc_init = 1;
break;
}
@@ -143,7 +141,7 @@ void RtcThread(mico_thread_arg_t arg)
}
// exit:
os_log("EXIT: rtc exit with err = %d.", err);
rtc_log("EXIT: rtc exit with err = %d.", err);
mico_rtos_delete_thread(NULL);
}

View File

@@ -1,5 +1,4 @@
#include "http_server/web_log.h"
#define os_log(format, ...) do { custom_log("KEY", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
#include "main.h"
#include "user_gpio.h"
@@ -104,14 +103,14 @@ void UserRelaySetAll(char y)
static void KeyLongPress(void)
{
// os_log("KeyLongPress");
// key_log("KeyLongPress");
// UserLedSet(1);
// UserMqttSend("mqtt test");
}
static void KeyLong10sPress(void)
{
os_log("WARNGIN: user params restored!");
key_log("WARNGIN: user params restored!");
appRestoreDefault_callback(user_config, sizeof(user_config_t));
sys_config->micoSystemConfig.ssid[0] = 0;
mico_system_context_update(mico_system_context_get());
@@ -152,7 +151,7 @@ static void KeyTimeoutHandler(void* arg)
key_time++;
if (key_time <= BUTTON_LONG_PRESS_TIME)
{
os_log("button long pressed:%d",key_time);
key_log("button long pressed:%d",key_time);
if (key_time == 30)
{
@@ -179,7 +178,7 @@ static void KeyTimeoutHandler(void* arg)
if (key_time < BUTTON_LONG_PRESS_TIME)
{ //100ms*10=1s 大于1s为长按
key_time = 0;
os_log("button short pressed:%d",key_time);
key_log("button short pressed:%d",key_time);
KeyShortPress();
}
else if (key_time > 100)

View File

@@ -1,5 +1,4 @@
#include "http_server/web_log.h"
#define os_log(format, ...) do { custom_log("OTA", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
#include "TimeUtils.h"
#include "mico.h"
@@ -70,7 +69,7 @@ static void PowerIrqHandler(void* arg)
void PowerInit(void)
{
os_log("user_power_init");
ota_log("user_power_init");
MicoGpioInitialize(POWER, INPUT_PULL_UP);
MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, PowerIrqHandler, NULL);
}

View File

@@ -5,8 +5,6 @@
#include "user_gpio.h"
#include "http_server/web_log.h"
#define os_log(format, ...) do { custom_log("WIFI", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
char wifi_status = WIFI_STATE_NOCONNECT;
mico_timer_t wifi_led_timer;
@@ -19,7 +17,7 @@ static void WifiGetIpCallback(IPStatusTypedef *pnet, void * arg)
strcpy(ip_status.gateway, pnet->gate);
strcpy(ip_status.mask, pnet->mask);
os_log("got IP:%s", pnet->ip);
wifi_log("got IP:%s", pnet->ip);
wifi_status = WIFI_STATE_CONNECTED;
//UserFunctionCmdReceived(1,"{\"cmd\":\"device report\"}");
}
@@ -36,7 +34,7 @@ static void WifiStatusCallback(WiFiEvent status, void* arg)
OSStatus status = micoWlanSuspendSoftAP(); //关闭AP
if (status != kNoErr)
{
os_log("close ap error[%d]", status);
wifi_log("close ap error[%d]", status);
}
ip_status.mode = 1;
@@ -68,7 +66,7 @@ char* wifi_ret = NULL;
void WifiScanCallback(ScanResult_adv* scan_ret, void* arg)
{
int count = (int)scan_ret->ApNum;
os_log("wifi_scan_callback ApNum[%d] ApList[0](%s)", count, scan_ret->ApList[0].ssid);
wifi_log("wifi_scan_callback ApNum[%d] ApList[0](%s)", count, scan_ret->ApList[0].ssid);
int i = 0;
wifi_ret = malloc(sizeof(char)*count * (32 + 2) + 50);
@@ -80,7 +78,7 @@ void WifiScanCallback(ScanResult_adv* scan_ret, void* arg)
{
ApInfo* ap = (ApInfo*)&scan_ret->ApList[i];
uint8_t* mac = (uint8_t*)ap->bssid;
os_log("wifi_scan_callback ssid[%16s] bssid[%02X-%02X-%02X-%02X-%02X-%02X] security[%d]",
wifi_log("wifi_scan_callback ssid[%16s] bssid[%02X-%02X-%02X-%02X-%02X-%02X] security[%d]",
ap->ssid, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ap->security);
char* ssid = scan_ret->ApList[i].ssid;
//排除隐藏的wifi和SSID带'或"的我wifi
@@ -110,7 +108,7 @@ static void WifiLedTimerCallback(void* arg)
switch (wifi_status)
{
case WIFI_STATE_FAIL:
os_log("wifi connect fail");
wifi_log("wifi connect fail");
UserLedSet(0);
mico_rtos_stop_timer(&wifi_led_timer);
break;
@@ -134,7 +132,7 @@ static void WifiLedTimerCallback(void* arg)
void WifiConnect(char* wifi_ssid, char* wifi_key)
{
os_log("WifiConnect wifi_ssid[%s] wifi_key[%s]", wifi_ssid, wifi_key);
wifi_log("WifiConnect wifi_ssid[%s] wifi_key[%s]", wifi_ssid, wifi_key);
//wifi配置初始化
network_InitTypeDef_st wNetConfig;
@@ -174,7 +172,7 @@ void ApConfig(char* name, char* key)
{
strncpy(user_config->ap_name, name, 32);
strncpy(user_config->ap_key, key, 32);
os_log("ApConfig ap_name[%s] ap_key[%s]", user_config->ap_name, user_config->ap_key);
wifi_log("ApConfig ap_name[%s] ap_key[%s]", user_config->ap_name, user_config->ap_key);
micoWlanSuspendStation();
ApInit(false);
mico_system_context_update(sys_config);
@@ -186,7 +184,7 @@ void ApInit(bool use_defaul)
{
sprintf(user_config->ap_name, ZZ_AP_NAME, str_mac + 6);
sprintf(user_config->ap_key, "%s", ZZ_AP_KEY);
os_log("ApInit ap_name[%s] ap_ke[%s]", user_config->ap_name, user_config->ap_key);
wifi_log("ApInit ap_name[%s] ap_ke[%s]", user_config->ap_name, user_config->ap_key);
}
network_InitTypeDef_st wNetConfig;
@@ -201,6 +199,6 @@ void ApInit(bool use_defaul)
strcpy((char *)wNetConfig.dnsServer_ip_addr, ZZ_AP_DNS_SERVER);
micoWlanStart(&wNetConfig);
os_log("ApInit ssid[%s] key[%s]", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
wifi_log("ApInit ssid[%s] key[%s]", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
}