mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 13:38:14 +08:00
LOG 通
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
#include "user_power.h"
|
#include "user_power.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "web_data.c"
|
#include "web_data.c"
|
||||||
|
#include "http_server/web_log.h"
|
||||||
|
|
||||||
static bool is_http_init;
|
static bool is_http_init;
|
||||||
static bool is_handlers_registered;
|
static bool is_handlers_registered;
|
||||||
@@ -185,13 +186,24 @@ exit:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int HttpGetLog(httpd_request_t *req)
|
||||||
|
{
|
||||||
|
OSStatus err = kNoErr;
|
||||||
|
char* logs = GetLogRecord(0);
|
||||||
|
send_http(logs, strlen(logs), exit, &err);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
struct httpd_wsgi_call g_app_handlers[] = {
|
struct httpd_wsgi_call g_app_handlers[] = {
|
||||||
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
|
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
|
||||||
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
|
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
|
||||||
{"/status", HTTPD_HDR_DEFORT, 0, HttpGetTc1Status, NULL, NULL, NULL},
|
{"/status", HTTPD_HDR_DEFORT, 0, HttpGetTc1Status, NULL, NULL, NULL},
|
||||||
{"/power", HTTPD_HDR_DEFORT, 0, NULL, HttpGetPowerInfo, NULL, NULL},
|
{"/power", HTTPD_HDR_DEFORT, 0, NULL, HttpGetPowerInfo, NULL, NULL},
|
||||||
{"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL},
|
{"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL},
|
||||||
{"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL},
|
{"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL },
|
||||||
|
{"/log", HTTPD_HDR_DEFORT, 0, HttpGetLog, NULL, NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int g_app_handlers_no = sizeof(g_app_handlers)/sizeof(struct httpd_wsgi_call);
|
static int g_app_handlers_no = sizeof(g_app_handlers)/sizeof(struct httpd_wsgi_call);
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
#include"web_log.h"
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include"http_server/web_log.h"
|
||||||
|
|
||||||
LogRecord log_record = { 1,{ 0 } };
|
LogRecord log_record = { 1,{ 0 } };
|
||||||
char log_record_str[LOG_NUM*LOG_LEN] = { 0 };
|
char log_record_str[LOG_NUM*LOG_LEN] = { 0 };
|
||||||
|
char* LOG_TMP;
|
||||||
|
|
||||||
void SetLogRecord(LogRecord* lr, char* log)
|
void SetLogRecord(LogRecord* lr, char* log)
|
||||||
{
|
{
|
||||||
@@ -9,12 +14,12 @@ void SetLogRecord(LogRecord* lr, char* log)
|
|||||||
{
|
{
|
||||||
log[LOG_LEN-1] = 0;
|
log[LOG_LEN-1] = 0;
|
||||||
}
|
}
|
||||||
char** log = &lr->logs[(++lr->idx)% LOG_NUM];
|
char** p_log = &lr->logs[(++lr->idx)% LOG_NUM];
|
||||||
if (*log)
|
if (*p_log)
|
||||||
{
|
{
|
||||||
free(*log);
|
free(*p_log);
|
||||||
}
|
}
|
||||||
*log = lr;
|
*p_log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* GetLogRecord(int idx)
|
char* GetLogRecord(int idx)
|
||||||
@@ -26,6 +31,7 @@ char* GetLogRecord(int idx)
|
|||||||
char* tmp = log_record_str;
|
char* tmp = log_record_str;
|
||||||
for (; i <= log_record.idx; i++)
|
for (; i <= log_record.idx; i++)
|
||||||
{
|
{
|
||||||
|
if (!log_record.logs[i%LOG_NUM]) continue;
|
||||||
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
|
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
|
||||||
tmp += strlen(tmp);
|
tmp += strlen(tmp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,16 @@ typedef struct
|
|||||||
char* logs[LOG_NUM];
|
char* logs[LOG_NUM];
|
||||||
} LogRecord;
|
} LogRecord;
|
||||||
|
|
||||||
|
extern LogRecord log_record;
|
||||||
|
extern char* LOG_TMP;
|
||||||
|
|
||||||
void SetLogRecord(LogRecord* lr, char* log);
|
void SetLogRecord(LogRecord* lr, char* log);
|
||||||
char* GetLogRecord(int idx);
|
char* GetLogRecord(int idx);
|
||||||
|
|
||||||
|
|
||||||
#define os_log(format, ...) \
|
#define os_log(format, ...) \
|
||||||
char* log = (char*)malloc(sizeof(char)*LOG_LEN); \
|
LOG_TMP = (char*)malloc(sizeof(char)*LOG_LEN); \
|
||||||
snprintf(log, LOG_LEN, format, ##__VA_ARGS__); \
|
snprintf(LOG_TMP, LOG_LEN, format, ##__VA_ARGS__); \
|
||||||
SetLogRecord(log_record, log); \
|
SetLogRecord(&log_record, LOG_TMP); \
|
||||||
custom_log("WIFI", format, ##__VA_ARGS__) \
|
custom_log("WIFI", format, ##__VA_ARGS__) \
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
#include "time_server/user_sntp.h"
|
#include "time_server/user_sntp.h"
|
||||||
#include "mqtt_server/user_function.h"
|
#include "mqtt_server/user_function.h"
|
||||||
#include "web_log.h"
|
#include "http_server/web_log.h"
|
||||||
|
|
||||||
char wifi_status = WIFI_STATE_NOCONNECT;
|
char wifi_status = WIFI_STATE_NOCONNECT;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user