不能在功率中断里调用任何有关moloc()的操作?

This commit is contained in:
zogodo
2020-02-18 10:19:09 +08:00
parent 73a60d3e04
commit 8793d905f4
4 changed files with 10 additions and 15 deletions

View File

@@ -123,6 +123,8 @@ int application_start(void)
while (1)
{
UserMqttHassPower();
time_t now = time(NULL);
if (task_top && now >= task_top->prs_time)
{

View File

@@ -14,7 +14,7 @@
#define wifi_log(M, ...) do { custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__) } while(0)
#define power_log(M, ...) do { custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__) } while(0)
#define VERSION "v1.0.17"
#define VERSION "v1.0.18"
#define TYPE 1
#define TYPE_NAME "zTC1"

View File

@@ -499,20 +499,13 @@ void UserMqttHassAutoPower(void)
if (topic_buf) free(topic_buf);
}
char topic_buf[64] = { 0 };
char send_buf[32] = { 0 };
void UserMqttHassPower(void)
{
char *send_buf = NULL;
char *topic_buf = NULL;
send_buf = malloc(512); //
topic_buf = malloc(128); //
if (send_buf != NULL && topic_buf != NULL)
{
sprintf(topic_buf, "homeassistant/sensor/%s/power/state", str_mac);
sprintf(send_buf, "{\"power\":\"%.3f\"}", real_time_power);
UserMqttSendTopic(topic_buf, send_buf, 0);
}
if (send_buf) free(send_buf);
if (topic_buf) free(topic_buf);
sprintf(topic_buf, "homeassistant/sensor/%s/power/state", str_mac);
sprintf(send_buf, "{\"power\":\"%.3f\"}", real_time_power/10);
UserMqttSendTopic(topic_buf, send_buf, 0);
}
bool UserMqttIsConnect()

View File

@@ -40,6 +40,8 @@ uint64_t irq_old = 0; //上次中断的时间(纳秒)
static void PowerIrqHandler(void* arg)
{
//警告! 不能在此函数里调用任何有关moloc()的操作
p_count++;
//mico_time_get_time(&past_ns); //系统运行毫秒数
@@ -57,14 +59,12 @@ static void PowerIrqHandler(void* arg)
n_1s += (float)(NS - irq_old % NS) / spend_ns;
real_time_power = 17.1 * n_1s;
SetPowerRecord(&power_record, (int)real_time_power);
UserMqttHassPower();
int i = 0;
for (; i < n; i++)
{
real_time_power = 17.1 * NS / spend_ns;
SetPowerRecord(&power_record, (int)real_time_power);
UserMqttHassPower();
}
irq_old = past_ns;
n_1s = (float)(past_ns % NS) / spend_ns;