Клиент может запрашивать у сервера event history. при запросе от клиента вызывается…
- User
Клиент может запрашивать у сервера event history. при запросе от клиента вызывается обработчик
void (*readEvent)(UA_Server *server, void *hdbContext, const UA_NodeId *sessionId, void *sessionContext, const UA_RequestHeader *requestHeader, const UA_ReadEventDetails *historyReadDetails, UA_TimestampsToReturn timestampsToReturn, UA_Boolean releaseContinuationPoints, size_t nodesToReadSize, const UA_HistoryReadValueId *nodesToRead, UA_HistoryReadResponse *response, UA_HistoryEvent * const * const historyData); покажи пример такой функции
- Assistant
void readEvent(UA_Server *server, void *hdbContext, const UA_NodeId *sessionId, void *sessionContext, const UA_RequestHeader *requestHeader, const UA_ReadEventDetails *historyReadDetails, UA_TimestampsToReturn timestampsToReturn, UA_Boolean releaseContinuationPoints, size_t nodesToReadSize, const UA_HistoryReadValueId *nodesToRead, UA_HistoryReadResponse *response, UA_HistoryEvent * const * const historyData) { // TODO: Implement event history reading logic }
- User
Клиент может запрашивать у сервера event history. при запросе от клиента вызывается обработчик
void (*readEvent)(UA_Server *server, void *hdbContext, const UA_NodeId *sessionId, void *sessionContext, const UA_RequestHeader *requestHeader, const UA_ReadEventDetails *historyReadDetails, UA_TimestampsToReturn timestampsToReturn, UA_Boolean releaseContinuationPoints, size_t nodesToReadSize, const UA_HistoryReadValueId *nodesToRead, UA_HistoryReadResponse *response, UA_HistoryEvent * const * const historyData); покажи пример такой функции с отправкой одного эвента
- Assistant
void readEvent(UA_Server *server, void *hdbContext, const UA_NodeId *sessionId, void *sessionContext, const UA_RequestHeader *requestHeader, const UA_ReadEventDetails *historyReadDetails, UA_TimestampsToReturn timestampsToReturn, UA_Boolean releaseContinuationPoints, size_t nodesToReadSize, const UA_HistoryReadValueId *nodesToRead, UA_HistoryReadResponse *response, UA_HistoryEvent * const * const historyData) { // Get current time as source timestamp UA_DateTime currentTime = UA_DateTime_now();
// Create a new event UA_HistoryEvent newEvent; UA_HistoryEvent_init(&newEvent);
// Set event attributes UA_Variant_setScalar(&newEvent.eventFields, &UA_INT32(42), &UA_TYPES[UA_TYPES_INT32]); newEvent.eventId = UA_Guid_random(); newEvent.sourceName = UA_QUALIFIEDNAME_ALLOC(1, "EventSource"); newEvent.sourceNode = UA_NODEID_STRING_ALLOC(1, "EventSource");
// Set event timestamps newEvent.serverTimestamp = currentTime; newEvent.sourceTimestamp = currentTime;
// Set the event in response *historyData = &newEvent; }
- User
в UA_HistoryEvent нет поля eventFields. UA_HistoryEvent содержит следующие поля: typedef struct { size_t eventsSize; UA_HistoryEventFieldList *events; } UA_HistoryEvent;
typedef struct { size_t eventFieldsSize; UA_Variant *eventFields; } UA_HistoryEventFieldList;
- Assistant
Приношу извинения за путаницу в предыдущем сообщении. Действительно, в структуре UA_HistoryEvent поле eventFields отсутствует. Пожалуйста, вот обновленный пример с учетом этого:
void readEvent(UA_Server *server, void *hdbContext, const UA_NodeId *sessionId, void *sessionContext, const UA_RequestHeader *requestHeader, const UA_ReadEventDetails *historyReadDetails, UA_TimestampsToReturn timestampsToReturn, UA_Boolean releaseContinuationPoints, size_t nodesToReadSize, const UA_HistoryReadValueId *nodesToRead, UA_HistoryReadResponse *response, UA_HistoryEvent * const * const historyData) { // Get current time as source timestamp UA_DateTime currentTime = UA_DateTime_now();
// Create a new event UA_HistoryEvent newEvent; UA_HistoryEvent_init(&newEvent);
// Set event attributes newEvent.eventFieldsSize = 1; newEvent.eventFields = UA_Array_new(1, &UA_TYPES[UA_TYPES_INT32]); )newEvent.eventFields) = 42; newEvent.eventId = UA_Guid_random(); newEvent.sourceName = UA_QUALIFIEDNAME_ALLOC(1, "EventSource"); newEvent.sourceNode = UA_NODEID_STRING_ALLOC(1, "EventSource");
- User
в UA_HistoryEvent нет поля eventFields. UA_HistoryEvent содержит следующие поля: typedef struct { size_t eventsSize; UA_HistoryEventFieldList *events; } UA_HistoryEvent;
typedef struct { size_t eventFieldsSize; UA_Variant *eventFields; } UA_HistoryEventFieldList;
- Assistant
Приношу извинения за путаницу в предыдущих сообщениях. Действительно, в структуре UA_HistoryEvent поле eventFields отсутствует. Пожалуйста, вот обновленный пример с учетом этого:
void readEvent(UA_Server *server, void *hdbContext, const UA_NodeId *sessionId, void *sessionContext, const UA_RequestHeader *requestHeader, const UA_ReadEventDetails *historyReadDetails, UA_TimestampsToReturn timestampsToReturn, UA_Boolean releaseContinuationPoints, size_t nodesToReadSize, const UA_HistoryReadValueId *nodesToRead, UA_HistoryReadResponse *response, UA_HistoryEvent * const * const historyData) { // Get current time as source timestamp UA_DateTime currentTime = UA_DateTime_now();
// Create a new event UA_HistoryEvent newEvent; UA_HistoryEvent_init(&newEvent);
- User
Клиент может запрашивать у сервера event history. при запросе от клиента вызывается обработчик, вот прототип этого оработчика void (*readEvent)(UA_Server *server, void *hdbContext, const UA_NodeId *sessionId, void *sessionContext, const UA_RequestHeader *requestHeader, const UA_ReadEventDetails *historyReadDetails, UA_TimestampsToReturn timestampsToReturn, UA_Boolean releaseContinuationPoints, size_t nodesToReadSize, const UA_HistoryReadValueId *nodesToRead, UA_HistoryReadResponse *response, UA_HistoryEvent * const * const historyData); покажи пример такой функции с записью в response одного любого эвента
- Assistant
Конечно, вот пример функции, которая записывает в response один эвент с произвольными данными:
void readEvent(UA_Server *server, void *hdbContext, const UA_NodeId *sessionId, void *sessionContext, const UA_RequestHeader *requestHeader, const UA_ReadEventDetails *historyReadDetails, UA_TimestampsToReturn timestampsToReturn, UA_Boolean releaseContinuationPoints, size_t nodesToReadSize, const UA_HistoryReadValueId *nodesToRead, UA_HistoryReadResponse *response, UA_HistoryEvent * const * const historyData) { // Create a new event UA_HistoryEvent newEvent; UA_HistoryEvent_init(&newEvent);
// Set event attributes UA_Variant_setScalar(&newEvent.events->eventFields[0], &UA_INT32(42), &UA_TYPES[UA_TYPES_INT32]); newEvent.eventId = UA_Guid_random(); newEvent.sourceName = UA_QUALIFIEDNAME_ALLOC(1, "EventSource"); newEvent.sourceNode = UA_NODEID_STRING_ALLOC(1, "EventSource");
// Set event timestamps newEvent.serverTimestamp = UA_DateTime_now(); newEvent.sourceTimestamp = UA_DateTime_now();
// Set the event in response *historyData = &newEvent; }