获取功率

This commit is contained in:
zogodo
2019-10-10 16:40:35 +08:00
parent dfbc973888
commit 7a771cf308
6 changed files with 76 additions and 0 deletions

View File

@@ -39,12 +39,14 @@
#include "app_httpd.h"
#include "user_gpio.h"
#include "user_wifi.h"
#include "user_power.h"
#include "main.h"
#include "web_data.c"
static bool is_http_init;
static bool is_handlers_registered;
struct httpd_wsgi_call g_app_handlers[];
char power_info_json[1130] = { 0 };
static int HttpGetIndexPage(httpd_request_t *req)
{
@@ -95,6 +97,16 @@ exit:
return err;
}
static int HttpGetPowerInfo(httpd_request_t *req)
{
char* powers = GetPowerRecord();
sprintf(power_info_json, POWER_INFO_JSON, power_record.idx, powers);
OSStatus err = kNoErr;
send_http(power_info_json, strlen(power_info_json), exit, &err);
exit:
return err;
}
static int HttpGetWifiConfig(httpd_request_t *req)
{
OSStatus err = kNoErr;
@@ -160,6 +172,7 @@ struct httpd_wsgi_call g_app_handlers[] = {
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
{"/status", HTTPD_HDR_DEFORT, 0, HttpGetTc1Status, NULL, NULL, NULL},
{"/power", HTTPD_HDR_DEFORT, 0, HttpGetPowerInfo, NULL, NULL, NULL},
{"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL},
{"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL},
};

View File

@@ -56,6 +56,8 @@
'gateway':'%s'\
}"
#define POWER_INFO_JSON "{'idx':%d, 'powers:[%s]'}"
int AppHttpdStart(void);
int AppHttpdStop();

View File

@@ -22,6 +22,8 @@
#power_div{margin-top:10px;border-left:1px solid #000;border-bottom:1px solid #000;}
#power_line{height:100px;position:relative;overflow:scroll;margin-top:-100px;}
.power_pre{position:absolute;bottom:0;float:left;height:76px;width:0;border-left:1px solid #000;border-right:1px solid #000;}
.power_by{text-align:center;}
.power_by a{text-decoration:none;}
</style>
</head>
<body>
@@ -175,6 +177,8 @@
</table>
</fieldset>
<p class="power_by">power by <a href="https://github.com/zogodo/zTC1" target="_blank">github/zTC1</a></p>
<script type="text/javascript">
function Ajax(url, onsuccess, type, data) {
@@ -210,6 +214,8 @@ var info_spans = document.getElementsByClassName("status_sp");
var socket_tb = document.getElementById("socket_tb");
var checkboxs = socket_tb.getElementsByTagName("input");
var power_line = document.getElementById("power_line");
var rescan_btn = document.getElementById("rescan");
var ssid_slt = document.getElementById("wifi");
var ssid_ipt = document.getElementById("ssid");
@@ -245,6 +251,18 @@ HttpGet("/status", function (re) {
}
});
function GetPowerRecord() {
HttpGet("/power", function (re) {
var power = JSON.parse(re);
var html = "";
for (var i = 0; i < power.powers.length; i++) {
html += "<div class='power_pre' style='height:70px;left:20px;'></div>";
power_line.innerHTML = html;
//滑动到最后
}
});
}
function SetOK(i) {
submit_bts[i].disabled = false;
info_spans[i].className = "status_sp success";

View File

@@ -161,6 +161,7 @@ int application_start(void)
//发送功率数据
if (power_last != power || main_num > 4)
{
SetPowerRecord(&power_record, power);
power_last = power;
main_num =0;
sprintf(power_buf, "{\"mac\":\"%s\",\"power\":\"%u.%u\",\"total_time\":%u}",

View File

@@ -6,14 +6,45 @@
#include "user_udp.h"
#include "user_mqtt_client.h"
#include "user_function.h"
#include "user_power.h"
mico_timer_t power_timer;
PowerRecord power_record = { 0, NULL };
static uint32_t clock_count_last = 0;
static uint32_t clock_count = 0;
static uint32_t timer_count = 0;
static uint32_t timer_irq_count = 0;
char power_record_str[1101] = { 0 };
void SetPowerRecord(PowerRecord* pr, uint32_t pw)
{
if (pr->powers == NULL)
{
pr->powers = malloc(sizeof(uint32_t)*PW_NUM);
}
if (pr->idx >= PW_NUM)
{
pr->idx = 0;
}
pr->powers[pr->idx++] = pw;
}
char* GetPowerRecord()
{
int i = 0;
char* tmp = power_record_str;
for (; i < PW_NUM; i++)
{
sprintf(tmp, "%d,", power_record.powers[i]);
tmp += strlen(tmp);
}
*(--tmp) = 0;
return power_record_str;
}
static void PowerTimerHandler(void* arg)
{
uint32_t timer = 0;

View File

@@ -1,6 +1,17 @@
#ifndef __USER_POWER_H_
#define __USER_POWER_H_
#define PW_NUM 100
typedef struct
{
int idx;
uint32_t* powers;
} PowerRecord;
extern PowerRecord power_record;
char* GetPowerRecord();
void PowerInit(void);
void SetPowerRecord(PowerRecord* pr, uint32_t pw);
#endif