Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ezpi 370 implement hub log #117

Merged
merged 6 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const char* ezlopi_msg_subclass_str = "msg_subclass";
const char* ezlopi_ui_broadcast_str = "ui_broadcast";
const char* ezlopi_result_str = "result";
const char* ezlopi_params_str = "params";
const char* ezlopi_severity_str = "severity";
const char* ezlopi_gateway_id_str = "gateway_id";
const char* ezlopi_scene_id_str = "scene_id";
const char* ezlopi_scene_name_str = "scene_name";
Expand All @@ -41,6 +42,7 @@ const char* ezlopi_fields_str = "fields";
const char* ezlopi_blockType_str = "blockType";
const char* ezlopi_when_str = "when";
const char* ezlopi_enabled_str = "enabled";
const char* ezlopi_enable_str = "enable";
const char* ezlopi_group_id_str = "group_id";
const char* ezlopi_parent_id_str = "parent_id";
const char* ezlopi_then_str = "then";
Expand Down
2 changes: 2 additions & 0 deletions ezlopi-cloud/ezlopi-cloud-constants/ezlopi_cloud_keywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern const char* ezlopi_msg_subclass_str;
extern const char* ezlopi_ui_broadcast_str;
extern const char* ezlopi_result_str;
extern const char* ezlopi_params_str;
extern const char* ezlopi_severity_str;
extern const char* ezlopi_gateway_id_str;
extern const char* ezlopi_scene_id_str;
extern const char* ezlopi_scene_name_str;
Expand All @@ -42,6 +43,7 @@ extern const char* ezlopi_fields_str;
extern const char* ezlopi_blockType_str;
extern const char* ezlopi_when_str;
extern const char* ezlopi_enabled_str;
extern const char* ezlopi_enable_str;
extern const char* ezlopi_group_id_str;
extern const char* ezlopi_parent_id_str;
extern const char* ezlopi_then_str;
Expand Down
8 changes: 8 additions & 0 deletions ezlopi-cloud/ezlopi-cloud-log/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
file(GLOB_RECURSE src_files "*.c*")
idf_component_register(SRCS "ezlopi_cloud_log.c" "${src_files}"
INCLUDE_DIRS "."
REQUIRES
cjext
ezlopi-core-log
ezlopi-core-sntp
ezlopi-cloud-constants)
89 changes: 89 additions & 0 deletions ezlopi-cloud/ezlopi-cloud-log/ezlopi_cloud_log.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

#include <stdbool.h>
#include <string.h>

#include "ezlopi_core_log.h"
#include "ezlopi_core_sntp.h"

#include "ezlopi_cloud_constants.h"

#include "ezlopi_cloud_log.h"



void ezlopi_hub_cloud_log_set(cJSON* cj_request, cJSON* cj_response)
{
cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (cj_params)
{
cJSON* cj_log_enable = cJSON_GetObjectItem(cj_params, ezlopi_enable_str);
cJSON* cj_log_severity = cJSON_GetObjectItem(cj_params, ezlopi_severity_str);
if (cj_log_enable && cj_log_severity)
{
bool severity_enable = cj_log_enable->type == cJSON_True ? true : false;
const char* log_severity_type = cj_log_severity->type == cJSON_String ? cj_log_severity->valuestring : NULL;
ezlopi_core_cloud_log_severity_process(severity_enable, log_severity_type);
}
}
}
}

void ezlopi_hub_serial_log_set(cJSON* cj_request, cJSON* cj_response)
{
cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (cj_params)
{
cJSON* cj_log_severity = cJSON_GetObjectItem(cj_params, ezlopi_severity_str);
if (cj_log_severity)
{
const char* log_severity_type = cj_log_severity->type == cJSON_String ? cj_log_severity->valuestring : NULL;
ezlopi_core_serial_log_severity_process(log_severity_type);
}
}
}
}

void ezlopi_hub_cloud_log_set_updater(cJSON* cj_request, cJSON* cj_response)
{
cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
uint64_t timestamp = EZPI_CORE_sntp_get_current_time_ms();
const char* messsage_str = "Log severity set";
size_t total_len = 15 + strlen(messsage_str) + 2;
char message[total_len];
memset(message, 0, total_len);
snprintf(message, total_len, "%lld: %s", timestamp, messsage_str);

cJSON_AddStringToObject(cj_result, ezlopi_message_str, message);

const char* severity_str = ezlopi_core_cloud_log_get_current_severity_enum_str();
cJSON_AddStringToObject(cj_result, ezlopi_severity_str, severity_str);
}
}

void ezlopi_hub_serial_log_set_updater(cJSON* cj_request, cJSON* cj_response)
{
cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
if (cj_result)
{
cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
if (cj_params)
{
cJSON* cj_log_severity = cJSON_GetObjectItem(cj_params, ezlopi_severity_str);
if (cj_log_severity)
{
cJSON_AddStringToObject(cj_result, ezlopi_name_str, "log.level");
const char* severity_str = ezlopi_core_serial_log_get_current_severity_enum_str();
cJSON_AddStringToObject(cj_result, ezlopi_value_str, severity_str);
}
}
}
}

16 changes: 16 additions & 0 deletions ezlopi-cloud/ezlopi-cloud-log/ezlopi_cloud_log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


#ifndef _EZLOPI_CLOUD_LOG_H_
#define _EZLOPI_CLOUD_LOG_H_

#include "cjext.h"


void ezlopi_hub_cloud_log_set(cJSON* cj_request, cJSON* cj_response);
void ezlopi_hub_cloud_log_set_updater(cJSON* cj_request, cJSON* cj_response);

void ezlopi_hub_serial_log_set(cJSON* cj_request, cJSON* cj_response);
void ezlopi_hub_serial_log_set_updater(cJSON* cj_request, cJSON* cj_response);

#endif // _EZLOPI_CLOUD_LOG_H_

1 change: 1 addition & 0 deletions ezlopi-core/ezlopi-core-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(EZLOPI_CLOUD_COMPONENTS
ezlopi-cloud-coordinates
ezlopi-cloud-registration
ezlopi-cloud-offline-login
ezlopi-cloud-log
)

set(EZLOPI_CORE_COMPONENTS
Expand Down
12 changes: 6 additions & 6 deletions ezlopi-core/ezlopi-core-api/ezlopi_core_api_macros.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// ("name", func, updater_func)

#if (defined(CONFIG_EZPI_WEBSOCKET_CLIENT) || defined(EZPI_LOCAL_WEBSOCKET_SERVER))


#if (defined(CONFIG_EZPI_WEBSOCKET_CLIENT) || defined(CONFIG_EZPI_LOCAL_WEBSOCKET_SERVER))
CLOUD_METHOD("hub.items.list", items_list_v3, NULL)
CLOUD_METHOD("hub.item.value.set", items_set_value_v3, NULL)

CLOUD_METHOD("hub.devices.list", devices_list_v3, NULL)
CLOUD_METHOD("hub.device.name.set", device_name_set, device_updated)

CLOUD_METHOD("hub.log.set", ezlopi_hub_cloud_log_set, ezlopi_hub_cloud_log_set_updater)
CLOUD_METHOD("hub.log.local.set", ezlopi_hub_serial_log_set, ezlopi_hub_serial_log_set_updater)

#ifdef CONFIG_EZPI_SERV_ENABLE_MODES
CLOUD_METHOD("hub.modes.get", ezlopi_cloud_modes_get, NULL)
CLOUD_METHOD("hub.modes.current.get", ezlopi_cloud_modes_current_get, NULL)
Expand Down Expand Up @@ -73,7 +73,7 @@ CLOUD_METHOD("hub.scenes.notification.add", scenes_notification_add, scene_chang
CLOUD_METHOD("hub.scenes.notification.remove", scenes_notification_remove, scene_changed)
CLOUD_METHOD("hub.scenes.status.get", scenes_status_get, NULL) // Incomplete
CLOUD_METHOD("hub.scenes.block.status.reset", scenes_block_status_reset, NULL)
#endif // CONFIG_EZPI_SERV_ENABLE_MESHBOTS
#endif // CONFIG_EZPI_SERV_MESHBOT_EN

CLOUD_METHOD("hub.room.list", room_list, NULL)
CLOUD_METHOD("hub.room.create", room_create, room_created)
Expand All @@ -94,7 +94,7 @@ CLOUD_METHOD("hub.scenes.scripts.run", scenes_scripts_run, NULL)
CLOUD_METHOD("hub.scenes.expressions.set", scenes_expressions_set, NULL)
CLOUD_METHOD("hub.scenes.expressions.list", scenes_expressions_list, NULL)
CLOUD_METHOD("hub.scenes.expressions.delete", scenes_expressions_delete, NULL)
#endif // CONFIG_EZPI_SERV_ENABLE_MESHBOTS
#endif // CONFIG_EZPI_SERV_MESHBOT_EN

CLOUD_METHOD("hub.nma.register.repeat", register_repeat, NULL)

Expand Down
1 change: 1 addition & 0 deletions ezlopi-core/ezlopi-core-api/ezlopi_core_api_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ezlopi_cloud_scenes_scripts.h"
#include "ezlopi_cloud_scenes_expressions.h"
#include "ezlopi_cloud_status.h"
#include "ezlopi_cloud_log.h"

#include "ezlopi_core_reset.h"
#include "ezlopi_util_trace.h"
Expand Down
6 changes: 3 additions & 3 deletions ezlopi-core/ezlopi-core-buffer/ezlopi_core_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ char *ezlopi_core_buffer_acquire(uint32_t *len, uint32_t wait_to_acquired_ms)
{
if (pdTRUE == xSemaphoreTake(__buffer_lock, wait_to_acquired_ms / portTICK_RATE_MS))
{
TRACE_I("acquired in: %d", xTaskGetTickCount() - start_time);
// TRACE_I("acquired in: %d", xTaskGetTickCount() - start_time);
ret = __buffer;
*len = __buffer_len;
__buffer_lock_state = EZ_BUFFER_STATE_BUSY;
}
else
{
TRACE_E("waited for: %d", xTaskGetTickCount() - start_time);
// TRACE_E("waited for: %d", xTaskGetTickCount() - start_time);
}
}

Expand All @@ -121,6 +121,6 @@ void ezlopi_core_buffer_release(void)
}
else
{
TRACE_E("buffer release failed!");
// TRACE_E("buffer release failed!");
}
}
1 change: 1 addition & 0 deletions ezlopi-core/ezlopi-core-ezlopi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(EZLOPI_CORE_COMPONENTS
ezlopi-core-modes
ezlopi-core-scenes
ezlopi-core-buffer
ezlopi-core-log
)

set(EZLOPI_CLOUD_COMPONENTS
Expand Down
4 changes: 4 additions & 0 deletions ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ezlopi_core_devices_list.h"
#include "ezlopi_core_scenes_scripts.h"
#include "ezlopi_core_scenes_expressions.h"
#include "ezlopi_core_log.h"

#ifdef CONFIG_EZPI_CORE_ETHERNET_EN
#include "ezlopi_core_ethernet.h"
Expand All @@ -31,6 +32,9 @@ void ezlopi_init(void)
{
// Init memories
ezlopi_nvs_init();

ezlopi_core_read_set_log_severities();

EZPI_HAL_uart_init();

#if defined(CONFIG_EZPI_WEBSOCKET_CLIENT) || defined(CONFIG_EZPI_LOCAL_WEBSOCKET_SERVER)
Expand Down
25 changes: 25 additions & 0 deletions ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_broadcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ int ezlopi_core_ezlopi_broadcast_add_to_queue(cJSON* cj_data)
return ret;
}

void ezlopi_core_broadcast_log_cjson(cJSON* cj_log_data)
{
int ret = 0;

if (cj_log_data)
{
uint32_t buffer_len = 0;
char* data_buffer = ezlopi_core_buffer_acquire(&buffer_len, 5000);

if (data_buffer && buffer_len)
{
memset(data_buffer, 0, buffer_len);

if (true == cJSON_PrintPreallocated(cj_log_data, data_buffer, buffer_len, false))
{
ret = __call_broadcast_methods(data_buffer);
}

ezlopi_core_buffer_release();
}
}

return ret;
}

int ezlopi_core_ezlopi_broadcast_cjson(cJSON* cj_data)
{
int ret = 0;
Expand Down
2 changes: 2 additions & 0 deletions ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi_broadcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ void ezlopi_core_ezlopi_broadcast_remove_method(f_broadcast_method_t broadcast_m
void ezlopi_core_ezlopi_broadcast_methods_set_queue(int (*func)(cJSON*));
l_broadcast_method_t* ezlopi_core_ezlopi_broadcast_method_add(f_broadcast_method_t broadcast_method, char* method_name, uint32_t retries);

void ezlopi_core_broadcast_log_cjson(cJSON* cj_log_data);

#endif // __EZLOPI_CORE_EZLOPI_BROADCAST_H__
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ extern "C"
\"id_room\": \"\",\
\"id_item\": 2,\
\"gpio_in\": 0,\
\"gpio_out\": 8,\
\"gpio_out\": 15,\
\"pullup_ip\": false,\
\"pullup_op\": false,\
\"is_ip\": false,\
Expand Down
12 changes: 12 additions & 0 deletions ezlopi-core/ezlopi-core-log/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
file(GLOB_RECURSE src_files "*.c*")
idf_component_register(SRCS "ezlopi_core_log.c" "${src_files}"
INCLUDE_DIRS "."
REQUIRES
ezlopi-core-sntp
ezlopi-core-ezlopi
ezlopi-core-ezlopi
ezlopi-cloud-constants
)



Loading