-
Notifications
You must be signed in to change notification settings - Fork 7
Add read and write for UA_String type; run tests against opc server #7
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
base: master
Are you sure you want to change the base?
Changes from all commits
86981b8
3034a00
8777408
1641170
256730e
d929534
f4cf490
88a9dc7
9fbc0e2
023a13c
2272d5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ jobs: | |
| matrix: | ||
| os: | ||
| - ubuntu-22.04 # jammy | ||
| - windows-2022 | ||
| ruby: | ||
| - '3.1' | ||
| - '3.0' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,4 @@ mkmf.log | |
| /.ruby-version | ||
| /opcua_client-*.gem | ||
| /tmp | ||
| /tools/server/server | ||
| /tools/server/opcua-server | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -411,17 +411,20 @@ static VALUE rb_readUaValues(VALUE self, VALUE v_nsIndex, VALUE v_aryNames) { | |||||||||||||
| UA_UInt16 val = *(UA_UInt16*)readValues[i].data; | ||||||||||||||
| rubyVal = INT2FIX(val); | ||||||||||||||
| } else if (UA_Variant_hasScalarType(&readValues[i], &UA_TYPES[UA_TYPES_INT32])) { | ||||||||||||||
| UA_Int32 val = *(UA_Int32*)readValues[i].data; | ||||||||||||||
| rubyVal = INT2FIX(val); | ||||||||||||||
| UA_Int32 val = *(UA_Int32*)readValues[i].data; | ||||||||||||||
| rubyVal = INT2FIX(val); | ||||||||||||||
| } else if (UA_Variant_hasScalarType(&readValues[i], &UA_TYPES[UA_TYPES_UINT32])) { | ||||||||||||||
| UA_UInt32 val = *(UA_UInt32*)readValues[i].data; | ||||||||||||||
| rubyVal = INT2FIX(val); | ||||||||||||||
| UA_UInt32 val = *(UA_UInt32*)readValues[i].data; | ||||||||||||||
| rubyVal = INT2FIX(val); | ||||||||||||||
| } else if (UA_Variant_hasScalarType(&readValues[i], &UA_TYPES[UA_TYPES_BOOLEAN])) { | ||||||||||||||
| UA_Boolean val = *(UA_Boolean*)readValues[i].data; | ||||||||||||||
| rubyVal = val ? Qtrue : Qfalse; | ||||||||||||||
| UA_Boolean val = *(UA_Boolean*)readValues[i].data; | ||||||||||||||
| rubyVal = val ? Qtrue : Qfalse; | ||||||||||||||
| } else if (UA_Variant_hasScalarType(&readValues[i], &UA_TYPES[UA_TYPES_FLOAT])) { | ||||||||||||||
| UA_Float val = *(UA_Float*)readValues[i].data; | ||||||||||||||
| rubyVal = DBL2NUM(val); | ||||||||||||||
| UA_Float val = *(UA_Float*)readValues[i].data; | ||||||||||||||
| rubyVal = DBL2NUM(val); | ||||||||||||||
| } else if (UA_Variant_hasScalarType(&readValues[i], &UA_TYPES[UA_TYPES_STRING])) { | ||||||||||||||
| UA_String val = *(UA_String*)readValues[i].data; | ||||||||||||||
| rubyVal = rb_utf8_str_new(val.data, val.length); | ||||||||||||||
| } else { | ||||||||||||||
| rubyVal = Qnil; // unsupported | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -525,6 +528,12 @@ static VALUE rb_writeUaValues(VALUE self, VALUE v_nsIndex, VALUE v_aryNames, VAL | |||||||||||||
| values[i].data = UA_malloc(sizeof(UA_Boolean)); | ||||||||||||||
| *(UA_Boolean*)values[i].data = newValue; | ||||||||||||||
| values[i].type = &UA_TYPES[UA_TYPES_BOOLEAN]; | ||||||||||||||
| } else if (uaType == UA_TYPES_STRING) { | ||||||||||||||
| Check_Type(v_newValue, T_STRING); | ||||||||||||||
| UA_String newValue = UA_STRING(StringValueCStr(v_newValue)); | ||||||||||||||
| values[i].data = UA_malloc(sizeof(UA_String)); | ||||||||||||||
| UA_String_copy(&newValue, (UA_String*)values[i].data); | ||||||||||||||
| values[i].type = &UA_TYPES[uaType]; | ||||||||||||||
| } else { | ||||||||||||||
| rb_raise(cError, "Unsupported type"); | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -608,6 +617,11 @@ static VALUE rb_writeUaValue(VALUE self, VALUE v_nsIndex, VALUE v_name, VALUE v_ | |||||||||||||
| value.data = UA_malloc(sizeof(UA_Boolean)); | ||||||||||||||
| *(UA_Boolean*)value.data = newValue; | ||||||||||||||
| value.type = &UA_TYPES[UA_TYPES_BOOLEAN]; | ||||||||||||||
| } else if (uaType == UA_TYPES_STRING) { | ||||||||||||||
| UA_String newValue = UA_STRING(StringValueCStr(v_newValue)); | ||||||||||||||
| value.data = UA_malloc(sizeof(UA_String)); | ||||||||||||||
| UA_String_copy(&newValue, (UA_String*)value.data); | ||||||||||||||
|
||||||||||||||
| UA_String_copy(&newValue, (UA_String*)value.data); | |
| UA_StatusCode copyStatus = UA_String_copy(&newValue, (UA_String*)value.data); | |
| if (copyStatus != UA_STATUSCODE_GOOD) { | |
| UA_free(value.data); | |
| rb_raise(cError, "UA_String_copy failed"); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| all: server | ||
|
|
||
| server: open62541.o | ||
| g++ -I../../ext/opcua_client server.cpp open62541.o -o server | ||
| g++ -I../../ext/opcua_client server.cpp open62541.o -o opcua-server | ||
|
|
||
| open62541.o: | ||
| gcc -std=c99 -c ../../ext/opcua_client/open62541.c | ||
|
|
||
| clean: | ||
| -rm *.o server | ||
| -rm *.o opcua-server |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,12 @@ static UA_NodeId addVariableUnder(UA_Server *server, UA_Int16 nsId, int type, co | |||||
| } else if (type == UA_TYPES_BOOLEAN) { | ||||||
| UA_Boolean initialValue = *(UA_Boolean*)defaultValue; | ||||||
| UA_Variant_setScalar(&attr.value, &initialValue, &UA_TYPES[type]); | ||||||
| } else if (type == UA_TYPES_FLOAT) { | ||||||
| UA_Float initialValue = *(UA_Float*)defaultValue; | ||||||
| UA_Variant_setScalar(&attr.value, &initialValue, &UA_TYPES[type]); | ||||||
| } else if (type == UA_TYPES_STRING) { | ||||||
| UA_String *initialValue = (UA_String*)defaultValue; | ||||||
| UA_Variant_setScalar(&attr.value, initialValue, &UA_TYPES[type]); | ||||||
| } else { | ||||||
| throw "type not supported"; | ||||||
| } | ||||||
|
|
@@ -52,7 +58,7 @@ static UA_NodeId addVariable(UA_Server *server, UA_Int16 nsId, int type, const c | |||||
| return addVariableUnder(server, nsId, type, desc, name, nodeIdString, qnString, parentNodeId, defaultValue); | ||||||
| } | ||||||
|
|
||||||
| static void addVariableV2(UA_Server *server, UA_Int16 nsId, int type, const char *variable, UA_Int32 defaultValue = 0) { | ||||||
| static void addVariableV2(UA_Server *server, UA_Int16 nsId, int type, const char *variable, void *defaultValue) { | ||||||
| char* varName = newString(); | ||||||
| sprintf(varName, "%s", variable); | ||||||
|
|
||||||
|
|
@@ -66,7 +72,23 @@ static void addVariableV2(UA_Server *server, UA_Int16 nsId, int type, const char | |||||
| char* nodeId = newString(); | ||||||
| sprintf(nodeId, "%s", varName); | ||||||
|
|
||||||
| UA_NodeId parentNode = addVariable(server, nsId, type, desc, displayName, nodeId, varName, &defaultValue); | ||||||
| UA_NodeId parentNode = addVariable(server, nsId, type, desc, displayName, nodeId, varName, defaultValue); | ||||||
| } | ||||||
|
|
||||||
| static void addVariableInt(UA_Server *server, UA_Int16 nsId, int type, const char *variable, UA_Int32 defaultValue) { | ||||||
| addVariableV2(server, nsId, type, variable, &defaultValue); | ||||||
| } | ||||||
|
|
||||||
| static void addVariableBool(UA_Server *server, UA_Int16 nsId, int type, const char *variable, UA_Boolean defaultValue) { | ||||||
| addVariableV2(server, nsId, type, variable, &defaultValue); | ||||||
| } | ||||||
|
|
||||||
| static void addVariableFloat(UA_Server *server, UA_Int16 nsId, int type, const char *variable, UA_Float defaultValue = 0) { | ||||||
|
||||||
| static void addVariableFloat(UA_Server *server, UA_Int16 nsId, int type, const char *variable, UA_Float defaultValue = 0) { | |
| static void addVariableFloat(UA_Server *server, UA_Int16 nsId, int type, const char *variable, UA_Float defaultValue = 0.0f) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak potential: if UA_String_copy fails, the allocated memory from UA_malloc will not be freed. Consider checking the return value of UA_String_copy and freeing the allocated memory on failure.