mirror of
https://github.com/emqx/neuron.git
synced 2026-10-23 18:37:45 +08:00
Fix opcua bool type parsing error
- And add other type support
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ opcua:
|
||||
default_key_file: ./opcua-default-key.der
|
||||
host: localhost
|
||||
port: 4840
|
||||
username: gaoc01
|
||||
username: user
|
||||
password: 123456
|
||||
cert_file: ""
|
||||
key_file: ""
|
||||
@@ -145,6 +145,20 @@ static int wrap_read_response_json_object(neu_fixed_array_t * array,
|
||||
json->tags[i - 1].value.val_double = value;
|
||||
break;
|
||||
}
|
||||
case NEU_DTYPE_BOOL: {
|
||||
bool value;
|
||||
neu_dvalue_get_bool(val, &value);
|
||||
json->tags[i - 1].t = NEU_JSON_BOOL;
|
||||
json->tags[i - 1].value.val_bool = value;
|
||||
break;
|
||||
}
|
||||
case NEU_DTYPE_BIT: {
|
||||
bool value;
|
||||
neu_dvalue_get_uint8(val, &value);
|
||||
json->tags[i - 1].t = NEU_JSON_BIT;
|
||||
json->tags[i - 1].value.val_bit = value;
|
||||
break;
|
||||
}
|
||||
case NEU_DTYPE_CSTR: {
|
||||
char *value;
|
||||
neu_dvalue_get_ref_cstr(val, &value);
|
||||
|
||||
@@ -125,8 +125,13 @@ static int read_response_array_generate(vector_t * datas,
|
||||
|
||||
int type = data->type;
|
||||
switch (type) {
|
||||
case NEU_DTYPE_BYTE: {
|
||||
val = neu_dvalue_new(NEU_DTYPE_BYTE);
|
||||
case NEU_DTYPE_INT8: {
|
||||
val = neu_dvalue_new(NEU_DTYPE_INT8);
|
||||
neu_dvalue_set_int8(val, data->value.value_int8);
|
||||
break;
|
||||
}
|
||||
case NEU_DTYPE_UINT8: {
|
||||
val = neu_dvalue_new(NEU_DTYPE_UINT8);
|
||||
neu_dvalue_set_uint8(val, data->value.value_uint8);
|
||||
break;
|
||||
}
|
||||
@@ -172,7 +177,7 @@ static int read_response_array_generate(vector_t * datas,
|
||||
}
|
||||
case NEU_DTYPE_DOUBLE: {
|
||||
val = neu_dvalue_new(NEU_DTYPE_DOUBLE);
|
||||
neu_dvalue_set_float(val, data->value.value_double);
|
||||
neu_dvalue_set_double(val, data->value.value_double);
|
||||
break;
|
||||
}
|
||||
case NEU_DTYPE_CSTR: {
|
||||
|
||||
@@ -215,7 +215,7 @@ static int client_set_read_value(opcua_data_t *data, UA_Variant *value)
|
||||
// byte(OPCUA) -> uint8(Neuron)
|
||||
if (UA_Variant_hasScalarType(value, &UA_TYPES[UA_TYPES_BYTE])) {
|
||||
data->value.value_uint8 = *(UA_Byte *) value->data;
|
||||
data->type = NEU_DTYPE_BYTE;
|
||||
data->type = NEU_DTYPE_UINT8;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -256,6 +256,18 @@ static int client_set_read_value(opcua_data_t *data, UA_Variant *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (UA_Variant_hasScalarType(value, &UA_TYPES[UA_TYPES_INT64])) {
|
||||
data->value.value_int64 = *(UA_Int64 *) value->data;
|
||||
data->type = NEU_DTYPE_INT64;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (UA_Variant_hasScalarType(value, &UA_TYPES[UA_TYPES_UINT64])) {
|
||||
data->value.value_uint64 = *(UA_UInt64 *) value->data;
|
||||
data->type = NEU_DTYPE_UINT64;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (UA_Variant_hasScalarType(value, &UA_TYPES[UA_TYPES_FLOAT])) {
|
||||
data->value.value_float = *(UA_Float *) value->data;
|
||||
data->type = NEU_DTYPE_FLOAT;
|
||||
|
||||
+20
-12
@@ -111,16 +111,21 @@ static void data_uint32_add(UA_Server *server, char *name, char *node_id,
|
||||
node_attributes_set(server, name, node_id, UA_TYPES_UINT32, &u32, readonly);
|
||||
}
|
||||
|
||||
// UA_DateTime
|
||||
// static void data_datetime_add(UA_Server *server, char *name, char *node_id,
|
||||
// uint32_t data, const int readonly)
|
||||
// {
|
||||
// UNUSED(server);
|
||||
// UNUSED(name);
|
||||
// UNUSED(node_id);
|
||||
// UNUSED(data);
|
||||
// UNUSED(readonly);
|
||||
// }
|
||||
// UA_Int64
|
||||
static void data_int64_add(UA_Server *server, char *name, char *node_id,
|
||||
int64_t data, const int readonly)
|
||||
{
|
||||
UA_Int64 i64 = data;
|
||||
node_attributes_set(server, name, node_id, UA_TYPES_INT64, &i64, readonly);
|
||||
}
|
||||
|
||||
// UA_UInt64
|
||||
static void data_uint64_add(UA_Server *server, char *name, char *node_id,
|
||||
uint64_t data, const int readonly)
|
||||
{
|
||||
UA_UInt64 u64 = data;
|
||||
node_attributes_set(server, name, node_id, UA_TYPES_UINT64, &u64, readonly);
|
||||
}
|
||||
|
||||
// UA_Float
|
||||
static void data_float_add(UA_Server *server, char *name, char *node_id,
|
||||
@@ -229,13 +234,16 @@ int main(int argc, char **argv)
|
||||
&config->securityPolicies[config->securityPoliciesSize - 1].policyUri,
|
||||
2, logins);
|
||||
|
||||
data_int8_add(server, "type_int8", "neu.type.int8", -10, 0);
|
||||
data_uint8_add(server, "type_uint8", "neu.type.uint8", 10, 0);
|
||||
data_int8_add(server, "type_int8", "neu.type_int8", -10, 0);
|
||||
data_uint8_add(server, "type_uint8", "neu.type_uint8", 10, 0);
|
||||
data_bool_add(server, "type_bool", "neu.type_bool", true, 0);
|
||||
data_int16_add(server, "type_int16", "neu.type_int16", -1001, 0);
|
||||
data_uint16_add(server, "type_uint16", "neu.type_uint16", 1001, 0);
|
||||
data_int32_add(server, "type_int32", "neu.type_int32", -100, 0);
|
||||
data_uint32_add(server, "type_uint32", "neu.type_uint32", 111111, 0);
|
||||
data_int64_add(server, "type_int64", "neu.type_int64", -10011111111111, 0);
|
||||
data_uint64_add(server, "type_uint64", "neu.type_uint64", 5678710019198784,
|
||||
0);
|
||||
data_float_add(server, "type_float", "neu.type_float", 38.9, 0);
|
||||
data_double_add(server, "type_double", "neu.type_double", 100038.9999, 0);
|
||||
data_string_add(server, "type_cstr", "nue.type_cstr", "hello world!", 0);
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"function": 13,
|
||||
"uuid": "554f5fd8-f437-11eb-975c-7704b9e17821",
|
||||
"node_id": 6,
|
||||
"group_config_name": "config_opcua_sample",
|
||||
"tags": [
|
||||
{
|
||||
"name": "type_int8",
|
||||
"address": "1!neu.type_int8",
|
||||
"attribute": 1,
|
||||
"type": 3
|
||||
},
|
||||
{
|
||||
"name": "type_uint8",
|
||||
"address": "1!neu.type_uint8",
|
||||
"attribute": 1,
|
||||
"type": 7
|
||||
},
|
||||
{
|
||||
"name": "type_bool",
|
||||
"address": "1!neu.type_bool",
|
||||
"attribute": 1,
|
||||
"type": 13
|
||||
},
|
||||
{
|
||||
"name": "type_int16",
|
||||
"address": "1!neu.type_int16",
|
||||
"attribute": 1,
|
||||
"type": 4
|
||||
},
|
||||
{
|
||||
"name": "type_uint16",
|
||||
"address": "1!neu.type_uint16",
|
||||
"attribute": 1,
|
||||
"type": 8
|
||||
},
|
||||
{
|
||||
"name": "type_int32",
|
||||
"address": "1!neu.type_int32",
|
||||
"attribute": 1,
|
||||
"type": 5
|
||||
},
|
||||
{
|
||||
"name": "type_uint32",
|
||||
"address": "1!neu.type_uint32",
|
||||
"attribute": 1,
|
||||
"type": 8
|
||||
},
|
||||
{
|
||||
"name": "type_datetime",
|
||||
"address": "1!neu.type_datetime",
|
||||
"attribute": 1,
|
||||
"type": 8
|
||||
},
|
||||
{
|
||||
"name": "type_int64",
|
||||
"address": "1!neu.type_int64",
|
||||
"attribute": 1,
|
||||
"type": 6
|
||||
},
|
||||
{
|
||||
"name": "type_uint64",
|
||||
"address": "1!neu.type_uint64",
|
||||
"attribute": 1,
|
||||
"type": 10
|
||||
},
|
||||
{
|
||||
"name": "type_float",
|
||||
"address": "1!neu.type_float",
|
||||
"attribute": 1,
|
||||
"type": 11
|
||||
},
|
||||
{
|
||||
"name": "type_double",
|
||||
"address": "1!neu.type_double",
|
||||
"attribute": 1,
|
||||
"type": 12
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user