123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #include <open62541/plugin/historydata/history_data_backend_memory.h>
- #include <open62541/plugin/historydata/history_data_gathering_default.h>
- #include <open62541/plugin/historydata/history_database_default.h>
- #include <open62541/plugin/historydatabase.h>
- #include <open62541/plugin/log_stdout.h>
- #include <open62541/server.h>
- #include <open62541/server_config_default.h>
- #include <signal.h>
- #include <stdlib.h>
- static volatile UA_Boolean running = true;
- static void stopHandler(int sign) {
- (void)sign;
- UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
- running = false;
- }
- int main(void) {
- signal(SIGINT, stopHandler);
- signal(SIGTERM, stopHandler);
- UA_Server *server = UA_Server_new();
- UA_ServerConfig *config = UA_Server_getConfig(server);
- UA_ServerConfig_setDefault(config);
-
- UA_HistoryDataGathering gathering = UA_HistoryDataGathering_Default(1);
-
- config->historyDatabase = UA_HistoryDatabase_default(gathering);
-
- UA_VariableAttributes attr = UA_VariableAttributes_default;
- UA_UInt32 myUint32 = 40;
- UA_Variant_setScalar(&attr.value, &myUint32, &UA_TYPES[UA_TYPES_UINT32]);
- attr.description = UA_LOCALIZEDTEXT("en-US","myUintValue");
- attr.displayName = UA_LOCALIZEDTEXT("en-US","myUintValue");
- attr.dataType = UA_TYPES[UA_TYPES_UINT32].typeId;
-
- attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
-
- attr.historizing = true;
-
- UA_NodeId uint32NodeId = UA_NODEID_STRING(1, "myUintValue");
- UA_QualifiedName uint32Name = UA_QUALIFIEDNAME(1, "myUintValue");
- UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
- UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
- UA_NodeId outNodeId;
- UA_NodeId_init(&outNodeId);
- UA_StatusCode retval = UA_Server_addVariableNode(server,
- uint32NodeId,
- parentNodeId,
- parentReferenceNodeId,
- uint32Name,
- UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
- attr,
- NULL,
- &outNodeId);
- UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
- "UA_Server_addVariableNode %s", UA_StatusCode_name(retval));
-
- UA_HistorizingNodeIdSettings setting;
-
- setting.historizingBackend = UA_HistoryDataBackend_Memory(3, 100);
-
- setting.maxHistoryDataResponseSize = 100;
-
-
-
- setting.historizingUpdateStrategy = UA_HISTORIZINGUPDATESTRATEGY_VALUESET;
-
- retval = gathering.registerNodeId(server, gathering.context, &outNodeId, setting);
- UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "registerNodeId %s", UA_StatusCode_name(retval));
-
- retval = UA_Server_run(server, &running);
- UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "UA_Server_run %s", UA_StatusCode_name(retval));
-
- UA_Server_delete(server);
- return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
- }
|