mirror of
https://github.com/emqx/neuron.git
synced 2026-10-26 03:40:01 +08:00
Merge pull request #1780 from hxy7yx/main-1
adapter: removing unused code and enhancing test coverage
This commit is contained in:
@@ -139,7 +139,7 @@ jobs:
|
||||
if [ "${{ matrix.plugin }}" = "mqtt" ]; then
|
||||
sudo apt-get install -y mosquitto
|
||||
fi
|
||||
pip install -U pytest requests prometheus-client gmqtt pynng
|
||||
pip install -U pytest requests prometheus-client gmqtt pynng sniffio
|
||||
|
||||
- name: compile
|
||||
run: |
|
||||
|
||||
@@ -264,16 +264,6 @@ neu_adapter_t *neu_adapter_create(neu_adapter_info_t *info, bool load)
|
||||
}
|
||||
}
|
||||
|
||||
bool neu_adapter_reset(neu_adapter_t *adapter, neu_adapter_info_t *info)
|
||||
{
|
||||
if (adapter->state == NEU_NODE_RUNNING_STATE_RUNNING) {
|
||||
return false;
|
||||
}
|
||||
adapter->module = info->module;
|
||||
adapter->handle = info->handle;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t neu_adapter_trans_data_port(neu_adapter_t *adapter)
|
||||
{
|
||||
return adapter->trans_data_port;
|
||||
@@ -1284,13 +1274,6 @@ void neu_adapter_destroy(neu_adapter_t *adapter)
|
||||
free(adapter);
|
||||
}
|
||||
|
||||
void neu_adapter_handle_close(neu_adapter_t *adapter)
|
||||
{
|
||||
dlclose(adapter->handle);
|
||||
adapter->handle = NULL;
|
||||
adapter->module = NULL;
|
||||
}
|
||||
|
||||
int neu_adapter_uninit(neu_adapter_t *adapter)
|
||||
{
|
||||
if (adapter->module->type == NEU_NA_TYPE_DRIVER) {
|
||||
@@ -1424,16 +1407,6 @@ neu_node_state_t neu_adapter_get_state(neu_adapter_t *adapter)
|
||||
return state;
|
||||
}
|
||||
|
||||
int neu_adapter_validate_tag(neu_adapter_t *adapter, neu_datatag_t *tag)
|
||||
{
|
||||
const neu_plugin_intf_funs_t *intf_funs = adapter->module->intf_funs;
|
||||
neu_err_code_e error = NEU_ERR_SUCCESS;
|
||||
|
||||
error = intf_funs->driver.validate_tag(adapter->plugin, tag);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
neu_event_timer_t *neu_adapter_add_timer(neu_adapter_t * adapter,
|
||||
neu_event_timer_param_t param)
|
||||
{
|
||||
|
||||
@@ -70,7 +70,6 @@ void neu_adapter_set_error(int error);
|
||||
uint16_t neu_adapter_trans_data_port(neu_adapter_t *adapter);
|
||||
|
||||
neu_adapter_t *neu_adapter_create(neu_adapter_info_t *info, bool load);
|
||||
bool neu_adapter_reset(neu_adapter_t *adapter, neu_adapter_info_t *info);
|
||||
void neu_adapter_init(neu_adapter_t *adapter, neu_node_running_state_e state);
|
||||
|
||||
int neu_adapter_rename(neu_adapter_t *adapter, const char *new_name);
|
||||
@@ -84,7 +83,6 @@ neu_tag_cache_type_e neu_adapter_get_tag_cache_type(neu_adapter_t *adapter);
|
||||
|
||||
int neu_adapter_uninit(neu_adapter_t *adapter);
|
||||
void neu_adapter_destroy(neu_adapter_t *adapter);
|
||||
void neu_adapter_handle_close(neu_adapter_t *adapter);
|
||||
|
||||
neu_event_timer_t *neu_adapter_add_timer(neu_adapter_t * adapter,
|
||||
neu_event_timer_param_t param);
|
||||
@@ -94,8 +92,6 @@ int neu_adapter_set_setting(neu_adapter_t *adapter, const char *config);
|
||||
int neu_adapter_get_setting(neu_adapter_t *adapter, char **config);
|
||||
neu_node_state_t neu_adapter_get_state(neu_adapter_t *adapter);
|
||||
|
||||
int neu_adapter_validate_tag(neu_adapter_t *adapter, neu_datatag_t *tag);
|
||||
|
||||
int neu_adapter_register_group_metric(neu_adapter_t *adapter,
|
||||
const char *group_name, const char *name,
|
||||
const char *help, neu_metric_type_e type,
|
||||
|
||||
@@ -418,163 +418,6 @@ int neu_driver_cache_meta_get_changed(neu_driver_cache_t *cache,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int neu_driver_cache_get(neu_driver_cache_t *cache, const char *group,
|
||||
const char *tag, neu_driver_cache_value_t *value)
|
||||
{
|
||||
struct elem *elem = NULL;
|
||||
int ret = -1;
|
||||
tkey_t key = to_key(group, tag);
|
||||
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
HASH_FIND(hh, cache->table, &key, sizeof(tkey_t), elem);
|
||||
|
||||
if (elem != NULL) {
|
||||
value->timestamp = elem->timestamp;
|
||||
value->value.type = elem->value.type;
|
||||
value->value.precision = elem->value.precision;
|
||||
|
||||
switch (elem->value.type) {
|
||||
case NEU_TYPE_INT8:
|
||||
case NEU_TYPE_UINT8:
|
||||
case NEU_TYPE_BIT:
|
||||
value->value.value.u8 = elem->value.value.u8;
|
||||
break;
|
||||
case NEU_TYPE_INT16:
|
||||
case NEU_TYPE_UINT16:
|
||||
case NEU_TYPE_WORD:
|
||||
value->value.value.u16 = elem->value.value.u16;
|
||||
break;
|
||||
case NEU_TYPE_INT32:
|
||||
case NEU_TYPE_UINT32:
|
||||
case NEU_TYPE_DWORD:
|
||||
case NEU_TYPE_FLOAT:
|
||||
case NEU_TYPE_ERROR:
|
||||
value->value.value.u32 = elem->value.value.u32;
|
||||
break;
|
||||
case NEU_TYPE_INT64:
|
||||
case NEU_TYPE_UINT64:
|
||||
case NEU_TYPE_DOUBLE:
|
||||
case NEU_TYPE_LWORD:
|
||||
value->value.value.u64 = elem->value.value.u64;
|
||||
break;
|
||||
case NEU_TYPE_BOOL:
|
||||
value->value.value.boolean = elem->value.value.boolean;
|
||||
break;
|
||||
case NEU_TYPE_STRING:
|
||||
memcpy(value->value.value.str, elem->value.value.str,
|
||||
sizeof(elem->value.value.str));
|
||||
break;
|
||||
case NEU_TYPE_BYTES:
|
||||
value->value.value.bytes.length = elem->value.value.bytes.length;
|
||||
memcpy(value->value.value.bytes.bytes,
|
||||
elem->value.value.bytes.bytes,
|
||||
elem->value.value.bytes.length);
|
||||
break;
|
||||
case NEU_TYPE_PTR:
|
||||
value->value.value.ptr.length = elem->value.value.ptr.length;
|
||||
value->value.value.ptr.type = elem->value.value.ptr.type;
|
||||
value->value.value.ptr.ptr =
|
||||
calloc(1, elem->value.value.ptr.length);
|
||||
memcpy(value->value.value.ptr.ptr, elem->value.value.ptr.ptr,
|
||||
elem->value.value.ptr.length);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NEU_TAG_META_SIZE; i++) {
|
||||
if (strlen(elem->metas[i].name) > 0) {
|
||||
memcpy(&value->metas[i], &elem->metas[i],
|
||||
sizeof(neu_tag_meta_t));
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int neu_driver_cache_get_changed(neu_driver_cache_t *cache, const char *group,
|
||||
const char * tag,
|
||||
neu_driver_cache_value_t *value)
|
||||
{
|
||||
struct elem *elem = NULL;
|
||||
int ret = -1;
|
||||
tkey_t key = to_key(group, tag);
|
||||
|
||||
pthread_mutex_lock(&cache->mtx);
|
||||
HASH_FIND(hh, cache->table, &key, sizeof(tkey_t), elem);
|
||||
|
||||
if (elem != NULL && elem->changed) {
|
||||
value->timestamp = elem->timestamp;
|
||||
value->value.type = elem->value.type;
|
||||
value->value.precision = elem->value.precision;
|
||||
|
||||
switch (elem->value.type) {
|
||||
case NEU_TYPE_INT8:
|
||||
case NEU_TYPE_UINT8:
|
||||
case NEU_TYPE_BIT:
|
||||
value->value.value.u8 = elem->value.value.u8;
|
||||
break;
|
||||
case NEU_TYPE_INT16:
|
||||
case NEU_TYPE_UINT16:
|
||||
case NEU_TYPE_WORD:
|
||||
value->value.value.u16 = elem->value.value.u16;
|
||||
break;
|
||||
case NEU_TYPE_INT32:
|
||||
case NEU_TYPE_UINT32:
|
||||
case NEU_TYPE_FLOAT:
|
||||
case NEU_TYPE_ERROR:
|
||||
case NEU_TYPE_DWORD:
|
||||
value->value.value.u32 = elem->value.value.u32;
|
||||
break;
|
||||
case NEU_TYPE_INT64:
|
||||
case NEU_TYPE_UINT64:
|
||||
case NEU_TYPE_DOUBLE:
|
||||
case NEU_TYPE_LWORD:
|
||||
value->value.value.u64 = elem->value.value.u64;
|
||||
break;
|
||||
case NEU_TYPE_BOOL:
|
||||
value->value.value.boolean = elem->value.value.boolean;
|
||||
break;
|
||||
case NEU_TYPE_STRING:
|
||||
memcpy(value->value.value.str, elem->value.value.str,
|
||||
sizeof(elem->value.value.str));
|
||||
break;
|
||||
case NEU_TYPE_BYTES:
|
||||
value->value.value.bytes.length = elem->value.value.bytes.length;
|
||||
memcpy(value->value.value.bytes.bytes,
|
||||
elem->value.value.bytes.bytes,
|
||||
elem->value.value.bytes.length);
|
||||
break;
|
||||
case NEU_TYPE_PTR:
|
||||
value->value.value.ptr.length = elem->value.value.ptr.length;
|
||||
value->value.value.ptr.type = elem->value.value.ptr.type;
|
||||
value->value.value.ptr.ptr =
|
||||
calloc(1, elem->value.value.ptr.length);
|
||||
memcpy(value->value.value.ptr.ptr, elem->value.value.ptr.ptr,
|
||||
elem->value.value.ptr.length);
|
||||
}
|
||||
|
||||
for (int i = 0; i < NEU_TAG_META_SIZE; i++) {
|
||||
if (strlen(elem->metas[i].name) > 0) {
|
||||
memcpy(&value->metas[i], &elem->metas[i],
|
||||
sizeof(neu_tag_meta_t));
|
||||
}
|
||||
}
|
||||
|
||||
if (elem->value.type != NEU_TYPE_ERROR) {
|
||||
elem->changed = false;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&cache->mtx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void neu_driver_cache_del(neu_driver_cache_t *cache, const char *group,
|
||||
const char *tag)
|
||||
{
|
||||
|
||||
@@ -50,11 +50,6 @@ typedef struct {
|
||||
neu_tag_meta_t metas[NEU_TAG_META_SIZE];
|
||||
} neu_driver_cache_value_t;
|
||||
|
||||
int neu_driver_cache_get(neu_driver_cache_t *cache, const char *group,
|
||||
const char *tag, neu_driver_cache_value_t *value);
|
||||
int neu_driver_cache_get_changed(neu_driver_cache_t *cache, const char *group,
|
||||
const char * tag,
|
||||
neu_driver_cache_value_t *value);
|
||||
int neu_driver_cache_meta_get(neu_driver_cache_t *cache, const char *group,
|
||||
const char *tag, neu_driver_cache_value_t *value,
|
||||
neu_tag_meta_t *metas, int n_meta);
|
||||
|
||||
@@ -306,18 +306,6 @@ void neu_adapter_driver_destroy(neu_adapter_driver_t *driver)
|
||||
neu_driver_cache_destroy(driver->cache);
|
||||
}
|
||||
|
||||
int neu_adapter_driver_start(neu_adapter_driver_t *driver)
|
||||
{
|
||||
(void) driver;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_adapter_driver_stop(neu_adapter_driver_t *driver)
|
||||
{
|
||||
(void) driver;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_adapter_driver_init(neu_adapter_driver_t *driver)
|
||||
{
|
||||
(void) driver;
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
neu_adapter_driver_t *neu_adapter_driver_create();
|
||||
|
||||
void neu_adapter_driver_destroy(neu_adapter_driver_t *driver);
|
||||
int neu_adapter_driver_start(neu_adapter_driver_t *driver);
|
||||
int neu_adapter_driver_stop(neu_adapter_driver_t *driver);
|
||||
int neu_adapter_driver_init(neu_adapter_driver_t *driver);
|
||||
int neu_adapter_driver_uninit(neu_adapter_driver_t *driver);
|
||||
|
||||
|
||||
@@ -40,21 +40,21 @@ def simulator_setup_teardown(param):
|
||||
|
||||
|
||||
hold_bit = [{"name": "hold_bit", "address": "1!400001.15",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_READ, "type": config.NEU_TYPE_BIT}]
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_READ_SUBSCRIBE, "type": config.NEU_TYPE_BIT}]
|
||||
hold_int16 = [{"name": "hold_int16", "address": "1!400001",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_INT16}]
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE, "type": config.NEU_TYPE_INT16}]
|
||||
hold_uint16 = [{"name": "hold_uint16", "address": "1!400002",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_UINT16}]
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE, "type": config.NEU_TYPE_UINT16}]
|
||||
hold_int32 = [{"name": "hold_int32", "address": "1!400003",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_INT32}]
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE, "type": config.NEU_TYPE_INT32}]
|
||||
hold_uint32 = [{"name": "hold_uint32", "address": "1!400015",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_UINT32}]
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE, "type": config.NEU_TYPE_UINT32}]
|
||||
hold_float = [{"name": "hold_float", "address": "1!400017",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_FLOAT}]
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE, "type": config.NEU_TYPE_FLOAT}]
|
||||
hold_string = [{"name": "hold_string", "address": "1!400020.10",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_STRING}]
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE, "type": config.NEU_TYPE_STRING}]
|
||||
hold_bytes = [{"name": "hold_bytes", "address": "1!400040.10",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_BYTES}]
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE, "type": config.NEU_TYPE_BYTES}]
|
||||
|
||||
coil_bit_1 = [{"name": "coil_bit_1", "address": "1!000001",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_BIT}]
|
||||
|
||||
@@ -21,6 +21,8 @@ NEU_TAG_ATTRIBUTE_SUBSCRIBE = 4
|
||||
NEU_TAG_ATTRIBUTE_STATIC = 8
|
||||
NEU_TAG_ATTRIBUTE_RW = NEU_TAG_ATTRIBUTE_READ | NEU_TAG_ATTRIBUTE_WRITE
|
||||
NEU_TAG_ATTRIBUTE_RW_STATIC = NEU_TAG_ATTRIBUTE_RW | NEU_TAG_ATTRIBUTE_STATIC
|
||||
NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE = NEU_TAG_ATTRIBUTE_RW | NEU_TAG_ATTRIBUTE_SUBSCRIBE
|
||||
NEU_TAG_ATTRIBUTE_READ_SUBSCRIBE = NEU_TAG_ATTRIBUTE_READ | NEU_TAG_ATTRIBUTE_SUBSCRIBE
|
||||
|
||||
NEU_TYPE_INT8 = 1
|
||||
NEU_TYPE_UINT8 = 2
|
||||
|
||||
Reference in New Issue
Block a user