Decode firmware update information
This commit is contained in:
parent
aa262879f0
commit
80452e10de
@ -1,12 +1,14 @@
|
|||||||
#include "sync_response.h"
|
#include "sync_response.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
const static char *TAG = "sync_response";
|
const static char *TAG = "sync_response";
|
||||||
|
|
||||||
sync_response *sync_response_parse(cJSON *res)
|
sync_response *sync_response_parse(cJSON *res)
|
||||||
{
|
{
|
||||||
|
// Parse relays information
|
||||||
cJSON *relays_json = cJSON_GetObjectItem(res, "relays");
|
cJSON *relays_json = cJSON_GetObjectItem(res, "relays");
|
||||||
if (relays_json == NULL)
|
if (relays_json == NULL)
|
||||||
{
|
{
|
||||||
@ -45,12 +47,26 @@ sync_response *sync_response_parse(cJSON *res)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse firmware update information
|
||||||
|
cJSON *update = cJSON_GetObjectItem(res, "available_update");
|
||||||
|
if (update != NULL)
|
||||||
|
{
|
||||||
|
char *val = cJSON_GetStringValue(update);
|
||||||
|
sync_res->available_update = val != NULL ? strdup(val) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return sync_res;
|
return sync_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sync_response_print(sync_response *res)
|
void sync_response_print(sync_response *res)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, " === sync response begin === ");
|
ESP_LOGI(TAG, " === sync response begin === ");
|
||||||
|
|
||||||
|
if (res->available_update != NULL)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "> AVAILABLE UPDATE! Version %s", res->available_update);
|
||||||
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "# of relays: %d", res->len);
|
ESP_LOGI(TAG, "# of relays: %d", res->len);
|
||||||
for (size_t i = 0; i < res->len; i++)
|
for (size_t i = 0; i < res->len; i++)
|
||||||
ESP_LOGI(TAG, "Relay[%d]=%s", i, res->relays[i] ? "ON" : "off");
|
ESP_LOGI(TAG, "Relay[%d]=%s", i, res->relays[i] ? "ON" : "off");
|
||||||
@ -59,8 +75,13 @@ void sync_response_print(sync_response *res)
|
|||||||
|
|
||||||
void sync_response_free(sync_response *res)
|
void sync_response_free(sync_response *res)
|
||||||
{
|
{
|
||||||
if (res != NULL)
|
if (res == NULL)
|
||||||
free(res);
|
return;
|
||||||
|
|
||||||
|
if (res->available_update != NULL)
|
||||||
|
free(res->available_update);
|
||||||
|
|
||||||
|
free(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sync_response_is_relay_on(sync_response *res, int relay_number)
|
bool sync_response_is_relay_on(sync_response *res, int relay_number)
|
||||||
|
@ -16,6 +16,7 @@ extern "C"
|
|||||||
typedef struct sync_response
|
typedef struct sync_response
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
char *available_update;
|
||||||
bool relays[];
|
bool relays[];
|
||||||
} sync_response;
|
} sync_response;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user