Comments (9)
I used the generator to create the functions and modified them later (enc,dec,calcSize). I encode the MessageType into a byte array and decode it by casting 3 Bytes to an UA_Int32 so I can use it in switch/case structures directly. Do you know any simpler solution? I am not really satisfied with that solution...
from open62541.
@FlorianPalm ok, just wanted to know if these functions will be generated once more. From your answer I learn that this is not the case, so I can modify directly in the code, right?
from open62541.
yes
from open62541.
ok, then we only need to decide if we want to do the encoding/decoding of the messageType in the encoders/decoders. You'll find a messy solution in commit 8da17e3. Personally I'd propose to have the messageType as a part of the struct, so it should decode it itself, eg. by calling TL_getPackageType, shouldn't it?
from open62541.
I do not like the function TL_getPacketType, it is too long and does too many comparisions. If the header structure holds the MessageType in an UA_Int32 instead of Byte[3] and we define an enum with the corresponding values it would just be a casting/shifting operation.
enum packetType
{
UA_MESSAGETYPE_HEL = 0x48454C, // H E L
UA_MESSAGETYPE_ACK = 0x41434B, // A C k
UA_MESSAGETYPE_ERR = 0x455151, // E R R
UA_MESSAGETYPE_OPN = 0x4F504E, // O P N
UA_MESSAGETYPE_MSG = 0x4D5347, // M S G
UA_MESSAGETYPE_CLO = 0x434C4F // C L O
};
the decoding function would look like that
UA_Int32 UA_OPCUATcpMessageHeader_decode(char const * src, UA_Int32* pos, UA_OPCUATcpMessageHeader* dst) {
UA_Int32 retval = UA_SUCCESS;
UA_Byte tmpBuf[3];
tmpBuf[3] = 0;
retval |= UA_Byte_decode(src,pos,&(tmpBuf[0]));
retval |= UA_Byte_decode(src,pos,&(tmpBuf[1]));
retval |= UA_Byte_decode(src,pos,&(tmpBuf[2]));
dst->messageType = (UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]);
retval |= UA_Byte_decode(src,pos,&(dst->isFinal));
retval |= UA_UInt32_decode(src,pos,&(dst->messageSize));
return retval;
}
So the structure can still hold the MessageType as UA_Int32
from open62541.
Perfect! To encourage reuse I'd like to propose introducing a new type UA_MessageType - storage type UA_Int32, size 4; encoding/decoding UA_Byte[3], size 3.
FlorianPalm [email protected] schrieb:
I do not like the function TL_getPacketType, it is too long and does
too many comparisions. If the header structure holds the MessageType in
an UA_Int32 instead of Byte[3] and we define an enum with the
corresponding values it would just be a casting/shifting operation.enum packetType { UA_MESSAGETYPE_HEL = 0x48454C, // H E L UA_MESSAGETYPE_ACK = 0x41434B, // A C k UA_MESSAGETYPE_ERR = 0x455151, // E R R UA_MESSAGETYPE_OPN = 0x4F504E, // O P N UA_MESSAGETYPE_MSG = 0x4D5347, // M S G UA_MESSAGETYPE_CLO = 0x434C4F // C L O };the decoding function would look like that
UA_Int32 UA_OPCUATcpMessageHeader_decode(char const * src, UA_Int32* pos, UA_OPCUATcpMessageHeader* dst) { UA_Int32 retval = UA_SUCCESS; UA_Byte tmpBuf[3]; tmpBuf[3] = 0; retval |= UA_Byte_decode(src,pos,&(tmpBuf[0])); retval |= UA_Byte_decode(src,pos,&(tmpBuf[1])); retval |= UA_Byte_decode(src,pos,&(tmpBuf[2])); dst->messageType = (UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]); retval |= UA_Byte_decode(src,pos,&(dst->isFinal)); retval |= UA_UInt32_decode(src,pos,&(dst->messageSize)); return retval; }So the structure can still hold the MessageType as UA_Int32
Reply to this email directly or view it on GitHub:
#28 (comment)
Prof. L. Urbas; TU Dresden; +49-177-4665201
from open62541.
good evening, i was following the discussion and had an idea
please look into the commit 1b36c82
i have implemented a very messy "plugin" system for the code generator, maybe you can just create a custom type for the functions above and use the generator on custom .xml files ;)
from open62541.
@Stasik0 : please reopen new issue for plugin system, @FlorianPalm solved this issue
from open62541.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from open62541.
Related Issues (20)
- Completed "nodeset-exporter" for export nodeset to xml. HOT 2
- PubSub subscriber address space target variable values not updated
- Server custom datatype variable nodes not decodable by Softing OPC UA client
- New logging API hard to use. HOT 3
- "BadDataEncodingInvalid" when trying to view historical event using UA_Client_HistoryRead_events with ABB server HOT 1
- Sporadic connection failures without TCP reuseaddr option HOT 4
- Custom DataTypes don't show members in client
- Condition Time set to 0 generating an Alarm from a timed callback
- Server crash when browsing ServerDiagnostics object HOT 3
- Version 1.4 not buildable with debian buster HOT 4
- Cannot set Application Server Uri to use self-signed Certificate HOT 1
- Debian package libopen62541-tools has been removed HOT 1
- Error comunicación OPC UA Cliente S7 TiaPortal V16 HOT 1
- Version 1.4 not linkable with debian linux HOT 2
- Error building nodesetloader in Open62541 library version 1.4.0. HOT 6
- CMake Macros are no longer installed since #6369 HOT 4
- Custom DataType array items changing to ExtensionObject HOT 2
- 'client_encryption.c' returns a 'BadCertificateRevocationUnknown' error
- Guidance for unit testing without UA_ENABLE_ALLOW_REUSEADDR HOT 1
- Help with session disconnect sending and receiving requests from client HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open62541.