open62541 1.4.15
Open source implementation of OPC UA
Loading...
Searching...
No Matches
conversion.h
Go to the documentation of this file.
1/** This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 *
5 * Copyright 2020 (c) Matthias Konnerth
6 */
7
8#ifndef CONVERSION_H
9#define CONVERSION_H
10#include <open62541/types.h>
11
13
14#include <time.h>
15
16static inline UA_Boolean isNodeId(const char *s)
17{
18 if (!s)
19 {
20 return UA_FALSE;
21 }
22 if (!strncmp(s, "ns=", 3) || !strncmp(s, "i=", 2) || !strncmp(s, "s=", 2) ||
23 !strncmp(s, "g=", 2) || !strncmp(s, "b=", 2))
24 {
25 return UA_TRUE;
26 }
27 return UA_FALSE;
28}
29
30static inline UA_Boolean isValTrue(const char *s)
31{
32 if (!s)
33 {
34 return UA_FALSE;
35 }
36 if (strcmp(s, "true"))
37 {
38 return UA_FALSE;
39 }
40 return UA_TRUE;
41}
42
43static inline UA_NodeId extractNodeId(char *s)
44{
46 if(!s)
47 {
48 return id;
49 }
50 UA_String idString;
51 idString.length=strlen(s);
52 idString.data = (UA_Byte*)s;
53 UA_StatusCode result = UA_NodeId_parse(&id, idString);
54 if(result!=UA_STATUSCODE_GOOD)
55 {
56 return id;
57 }
58 return id;
59}
60
61static inline UA_DateTime UA_DateTime_fromString(const char *dateString)
62{
64 memset(&dt, 0, sizeof(UA_DateTimeStruct));
65 sscanf(dateString, "%hi-%hu-%huT%hu:%hu:%huZ",
66 &dt.year, &dt.month, &dt.day, &dt.hour, &dt.min, &dt.sec);
67 UA_DateTime dateTime = UA_DateTime_fromStruct(dt);
68 return dateTime;
69}
70
71#endif
#define UA_STATUSCODE_GOOD
The operation succeeded.
Definition statuscodes.h:8
Represents a Datetime as a structure.
Definition types.h:169
UA_UInt16 month
Definition types.h:177
UA_UInt16 min
Definition types.h:174
UA_Int16 year
Definition types.h:178
UA_UInt16 hour
Definition types.h:175
UA_UInt16 day
Definition types.h:176
UA_UInt16 sec
Definition types.h:173
UA_Byte * data
Definition types.h:121
size_t length
Definition types.h:120
_UA_BEGIN_DECLS typedef bool UA_Boolean
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition types.h:27
UA_EXPORT const UA_NodeId UA_NODEID_NULL
UA_DateTime UA_DateTime_fromStruct(UA_DateTimeStruct ts)
return id
Definition types.h:341
#define UA_FALSE
Definition types.h:29
#define UA_TRUE
Definition types.h:28
uint32_t UA_StatusCode
Definition types.h:82
uint8_t UA_Byte
Definition types.h:37