mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-06 18:32:49 +08:00
调试
This commit is contained in:
@@ -6,27 +6,24 @@
|
||||
#include "mqtt_server/user_mqtt_client.h"
|
||||
#include "user_power.h"
|
||||
|
||||
uint32_t p_count = user_config->p_count_1_day_ago;
|
||||
PowerRecord power_record = { 1,{ 0 } };
|
||||
char power_record_str[1101] = { 0 };
|
||||
uint32_t p_count = 0;
|
||||
PowerRecord power_record = {1, {0}};
|
||||
char power_record_str[1101] = {0};
|
||||
float real_time_power = 0;
|
||||
|
||||
void SetPowerRecord(PowerRecord* pr, uint32_t pw)
|
||||
{
|
||||
pr->powers[(++pr->idx)% PW_NUM] = pw;
|
||||
void SetPowerRecord(PowerRecord *pr, uint32_t pw) {
|
||||
pr->powers[(++pr->idx) % PW_NUM] = pw;
|
||||
}
|
||||
|
||||
char* GetPowerRecord(int idx)
|
||||
{
|
||||
char *GetPowerRecord(int idx) {
|
||||
if (idx > power_record.idx) return "";
|
||||
idx = idx <= power_record.idx - PW_NUM ? 0 : idx;
|
||||
|
||||
int i = idx > 0 ? idx : (power_record.idx - PW_NUM + 1);
|
||||
i = i < 0 ? 0 : i;
|
||||
char* tmp = power_record_str;
|
||||
for (; i <= power_record.idx; i++)
|
||||
{
|
||||
sprintf(tmp, "%lu,", power_record.powers[i%PW_NUM]);
|
||||
char *tmp = power_record_str;
|
||||
for (; i <= power_record.idx; i++) {
|
||||
sprintf(tmp, "%lu,", power_record.powers[i % PW_NUM]);
|
||||
tmp += strlen(tmp);
|
||||
}
|
||||
*(--tmp) = 0;
|
||||
@@ -38,9 +35,11 @@ float n_1s = 0; //在当前这一秒功率中断次数
|
||||
uint64_t past_ns = 0; //系统运行的纳秒数
|
||||
uint64_t irq_old = 0; //上次中断的时间(纳秒)
|
||||
|
||||
static void PowerIrqHandler(void* arg)
|
||||
{
|
||||
static void PowerIrqHandler(void *arg) {
|
||||
//警告! 不能在此函数里调用任何有关moloc()的操作
|
||||
if (p_count == 0) {
|
||||
p_count = user_config->p_count_1_day_ago;
|
||||
}
|
||||
|
||||
p_count++;
|
||||
|
||||
@@ -48,30 +47,27 @@ static void PowerIrqHandler(void* arg)
|
||||
past_ns = mico_nanosecond_clock_value(); //系统运行纳秒数
|
||||
uint64_t spend_ns = past_ns - irq_old;
|
||||
|
||||
if (irq_old % NS + spend_ns <= NS)
|
||||
{
|
||||
if (irq_old % NS + spend_ns <= NS) {
|
||||
n_1s += 1;
|
||||
irq_old = past_ns;
|
||||
return;
|
||||
}
|
||||
|
||||
int n = (spend_ns - past_ns % NS) / NS;
|
||||
n_1s += (float)(NS - irq_old % NS) / spend_ns;
|
||||
n_1s += (float) (NS - irq_old % NS) / spend_ns;
|
||||
real_time_power = 17.1 * n_1s;
|
||||
SetPowerRecord(&power_record, (int)real_time_power);
|
||||
SetPowerRecord(&power_record, (int) real_time_power);
|
||||
|
||||
int i = 0;
|
||||
for (; i < n; i++)
|
||||
{
|
||||
for (; i < n; i++) {
|
||||
real_time_power = 17.1 * NS / spend_ns;
|
||||
SetPowerRecord(&power_record, (int)real_time_power);
|
||||
SetPowerRecord(&power_record, (int) real_time_power);
|
||||
}
|
||||
irq_old = past_ns;
|
||||
n_1s = (float)(past_ns % NS) / spend_ns;
|
||||
n_1s = (float) (past_ns % NS) / spend_ns;
|
||||
}
|
||||
|
||||
void PowerInit(void)
|
||||
{
|
||||
void PowerInit(void) {
|
||||
power_log("PowerInit");
|
||||
MicoGpioInitialize(POWER, INPUT_PULL_UP);
|
||||
MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, PowerIrqHandler, NULL);
|
||||
|
||||
Reference in New Issue
Block a user