mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
@@ -1,3 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <nng/nng.h>
|
||||
#include <nng/supplemental/http/http.h>
|
||||
|
||||
@@ -11,6 +13,20 @@
|
||||
#include "json/neu_json_error.h"
|
||||
#include "json/neu_json_fn.h"
|
||||
|
||||
static void ede_cmd_uninit(neu_req_add_gtag_t *cmd)
|
||||
{
|
||||
if (cmd == NULL || cmd->groups == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cmd->n_group; ++i) {
|
||||
neu_ede_tags_uninit(cmd->groups[i].tags, cmd->groups[i].n_tag);
|
||||
}
|
||||
free(cmd->groups);
|
||||
cmd->groups = NULL;
|
||||
cmd->n_group = 0;
|
||||
}
|
||||
|
||||
void handle_ede(nng_aio *aio)
|
||||
{
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
@@ -31,13 +47,16 @@ void handle_ede(nng_aio *aio)
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_CID, {
|
||||
neu_http_response(aio, NEU_ERR_INVALID_CID, result_error);
|
||||
});
|
||||
goto success;
|
||||
}
|
||||
|
||||
int ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
if (neu_plugin_op(plugin, header, &cmd) != 0) {
|
||||
ede_cmd_uninit(&cmd);
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
neu_http_response(aio, NEU_ERR_IS_BUSY, result_error);
|
||||
});
|
||||
}
|
||||
|
||||
success:;
|
||||
})
|
||||
}
|
||||
@@ -1148,6 +1148,7 @@ static int get_tags_resp(context_t *ctx, neu_resp_get_tag_t *tags)
|
||||
tags_res.tags[index].precision = tag->precision;
|
||||
tags_res.tags[index].decimal = tag->decimal;
|
||||
tags_res.tags[index].bias = tag->bias;
|
||||
tags_res.tags[index].unit = tag->unit;
|
||||
tags_res.tags[index].t = NEU_JSON_UNDEFINE;
|
||||
}
|
||||
|
||||
|
||||
@@ -332,6 +332,12 @@ int neu_ede_parse_file(const char *file_path, neu_ede_result_t *result)
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
if (!object_header_seen || result->count == 0) {
|
||||
neu_ede_result_uninit(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ target_include_directories(mqtt_schema_test PRIVATE
|
||||
target_link_libraries(mqtt_schema_test neuron-base gtest_main gtest)
|
||||
|
||||
file(COPY ${CMAKE_SOURCE_DIR}/tests/ut/EDE_test.csv DESTINATION ${UT_DIRECTORY}/config)
|
||||
file(COPY ${CMAKE_SOURCE_DIR}/tests/ut/wrong.ede DESTINATION ${UT_DIRECTORY}/config)
|
||||
add_executable(ede_test ede_test.cc ${CMAKE_SOURCE_DIR}/src/utils/ede.c)
|
||||
target_include_directories(ede_test PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
|
||||
@@ -15,6 +15,7 @@ zlog_category_t *neuron = NULL;
|
||||
|
||||
static constexpr size_t kExpectedEdeTagCount = 1499;
|
||||
#define EDE_TEST_FILE_PATH "./config/EDE_test.csv"
|
||||
#define WRONG_EDE_FILE_PATH "./config/wrong.ede"
|
||||
|
||||
static std::vector<std::string> split_semicolon(const std::string &line)
|
||||
{
|
||||
@@ -150,6 +151,22 @@ TEST(EdeTest, ParseEdeFileToAddressAndType)
|
||||
neu_ede_result_uninit(&result);
|
||||
}
|
||||
|
||||
TEST(EdeTest, RejectTruncatedEdeFile)
|
||||
{
|
||||
neu_ede_result_t result = { 0 };
|
||||
neu_datatag_t * tags = NULL;
|
||||
size_t count = 0;
|
||||
|
||||
EXPECT_NE(neu_ede_parse_file(WRONG_EDE_FILE_PATH, &result), 0);
|
||||
EXPECT_EQ(result.entries, nullptr);
|
||||
EXPECT_EQ(result.count, 0);
|
||||
|
||||
EXPECT_NE(neu_ede_parse_file_to_tags(WRONG_EDE_FILE_PATH, &tags, &count),
|
||||
0);
|
||||
EXPECT_EQ(tags, nullptr);
|
||||
EXPECT_EQ(count, 0);
|
||||
}
|
||||
|
||||
TEST(EdeTest, FormatAddress)
|
||||
{
|
||||
char address[128] = { 0 };
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#Engineering-Data-Exchange;;;;;;;;;;;;;;;;;;;
|
||||
#PROJECT_NAME;NeuronEX BACnet/IP EDE Simulator;;;;;;;;;;;;;;;;;;;
|
||||
#VERSION_OF_REFERENCEFILE;1.0;;;;;;;;;;;;;;;;;;;
|
||||
#TIMESTAMP_OF_LAST_CHANGE;25.09.2026;;;;;;;;;;;;;;;;;;;
|
||||
#AUTHOR_OF_LAST_
|
||||
Reference in New Issue
Block a user