Model of the DataType:
Code: Select all
Types
|- DataTypes
| |- BaseDataType
| | |- Structure
| | | |- CustomDataType
| | | | |- CustomArray [ArrayOfFloat]
Code: Select all
Types
|- EventTypes
| |- BaseEventType
| | |- CustomEventType
| | | |- CustomData (TypeDefinition=CustomDataType, ValueRank=Array, ArrayDimensions=0)
| | | | |- CustomArray
Code: Select all
OpcUa_StatusCode UaProvider_CustomProvider_Events_Set_CustomEventType_CustomData(
UaServer_Event *a_pEvent,
OpcUa_Int32 a_iNoOfValues,
CustomProvider_CustomDataType *a_pValues)
{
OpcUa_Variant *pValue = OpcUa_Null;
OpcUa_Int32 i = 0;
OpcUa_InitializeStatus(OpcUa_Module_Server, "UaProvider_CustomProvider_Events_SetCustomEventTypeCustomData"); // remark: this name doesn't exactly match the function-name as it lacks some underscores
OpcUa_ReturnErrorIfArgumentNull(a_pEvent);
OpcUa_ReturnErrorIfArgumentNull(a_pValues);
pValue = (OpcUa_Variant*)UaBase_Vector_Get(&a_pEvent->EventFields, CustomEventTypeField_CustomData);
OpcUa_ReturnErrorIfNull(pValue, OpcUa_BadNoData);
OpcUa_Variant_Clear(pValue);
if (pValue->Value.Array.Length <= a_iNoOfValues)
{
pValue->Value.Array.Value.ExtensionObjectArray = OpcUa_Null;
}
else
{
pValue->Value.Array.Value.ExtensionObjectArray = (OpcUa_ExtensionObject*)OpcUa_Alloc(a_iNoOfValues * sizeof(OpcUa_ExtensionObject));
OpcUa_ReturnErrorIfAllocFailed(pValue->Value.Array.Value.ExtensionObjectArray);
for (i = 0; i < a_iNoOfValues; i++)
{
OpcUa_ExtensionObject_Initialize(&pValue->Value.Array.Value.ExtensionObjectArray[i]);
}
for (i = 0; i < a_iNoOfValues; i++)
{
pValue->Value.Array.Value.ExtensionObjectArray[i].Encoding = OpcUa_ExtensionObjectEncoding_EncodeableObject;
pValue->Value.Array.Value.ExtensionObjectArray[i].Body.EncodeableObject.Type = &CustomProvider_CustomDataType_EncodeableType;
uStatus = CustomProvider_CustomDataType_Copy(&a_pValues[i], (CustomProvider_CustsomDataType**) &pValue->Value.Array.Value.ExtensionObjectArray[i].Body.EncodeableObject.Object);
OpcUa_GotoErrorIfBad(uStatus);
}
}
pValue->Datatype = OpcUaType_ExtensionObject;
pValue->ArrayType = OpcUa_VariantArrayType_Array;
pValue->Value.Array.Length = a_iNoOfValues;
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_Variant_Clear(pValue);
OpcUa_FinishErrorHandling;
}
Code: Select all
CustomProvider_CustomDataType* pData;
pData = (CustomProvider_CustomDataType*)OpcUa_Alloc(sizeof(CustomProvider_CustomDataType) * NoOfData);
OpcUa_GotoErrorIfAllocFailed(pMTData);
for(i=0; i <NoOfData; ++i)
{
CustomProvider_CustomDataType_Initialize(&pData[i]);
... Set CustomDataType fields
}
... Create Event and set Event Fields ...
UaProvider_CustomProvider_Events_Set_CustomEventType_CustomData(pEvent,NoOfData,pData);
uStatus = UaServer_Events_FireEvent(pEvent);
OpcUa_GotoErrorIfBad(uStatus);
On to the second issue; After removing the comparison-code I end up with the following code.
Code: Select all
OpcUa_StatusCode UaProvider_CustomProvider_Events_Set_CustomEventType_CustomData(
UaServer_Event *a_pEvent,
OpcUa_Int32 a_iNoOfValues,
CustomProvider_CustomDataType *a_pValues)
{
OpcUa_Variant *pValue = OpcUa_Null;
OpcUa_Int32 i = 0;
OpcUa_InitializeStatus(OpcUa_Module_Server, "UaProvider_CustomProvider_Events_SetCustomEventTypeCustomData"); // remark: this name doesn't exactly match the function-name as it lacks some underscores
OpcUa_ReturnErrorIfArgumentNull(a_pEvent);
OpcUa_ReturnErrorIfArgumentNull(a_pValues);
pValue = (OpcUa_Variant*)UaBase_Vector_Get(&a_pEvent->EventFields, CustomEventTypeField_CustomData);
OpcUa_ReturnErrorIfNull(pValue, OpcUa_BadNoData);
OpcUa_Variant_Clear(pValue);
pValue->Value.Array.Value.ExtensionObjectArray = (OpcUa_ExtensionObject*)OpcUa_Alloc(a_iNoOfValues * sizeof(OpcUa_ExtensionObject));
OpcUa_ReturnErrorIfAllocFailed(pValue->Value.Array.Value.ExtensionObjectArray);
for (i = 0; i < a_iNoOfValues; i++)
{
OpcUa_ExtensionObject_Initialize(&pValue->Value.Array.Value.ExtensionObjectArray[i]);
}
for (i = 0; i < a_iNoOfValues; i++)
{
pValue->Value.Array.Value.ExtensionObjectArray[i].Encoding = OpcUa_ExtensionObjectEncoding_EncodeableObject;
pValue->Value.Array.Value.ExtensionObjectArray[i].Body.EncodeableObject.Type = &CustomProvider_CustomDataType_EncodeableType;
uStatus = CustomProvider_CustomDataType_Copy(&a_pValues[i], (CustomProvider_CustsomDataType**) &pValue->Value.Array.Value.ExtensionObjectArray[i].Body.EncodeableObject.Object);
OpcUa_GotoErrorIfBad(uStatus);
}
pValue->Datatype = OpcUaType_ExtensionObject;
pValue->ArrayType = OpcUa_VariantArrayType_Array;
pValue->Value.Array.Length = a_iNoOfValues;
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_Variant_Clear(pValue);
OpcUa_FinishErrorHandling;
}
UaExpert EventView Details:
Code: Select all
-----------------------------------------------
| Name | Value |
-----------------------------------------------
| ns:Customdata | Array of ExtensionObjects |
| [0] | CustomDataType |
| CustomArray | ... Null or data present |
| [1] | CustomDataType |
| CustomArray | ... Null or data present |
-----------------------------------------------
UaExpert EventView Details:
Code: Select all
-----------------------------------------------
| Name | Value |
-----------------------------------------------
| ns:Customdata | Array of ExtensionObjects |
| [0] | ExtensionObject |
| [1] | ExtensionObject |
-----------------------------------------------
I've also tried the following code, but the issue remains:
Code: Select all
OpcUa_StatusCode UaProvider_CustomProvider_Events_Set_CustomEventType_CustomData(
UaServer_Event *a_pEvent,
OpcUa_Int32 a_iNoOfValues,
CustomProvider_CustomDataType *a_pValues)
{
CustomProvider_CustomDataType* pCustomDataValue;
OpcUa_Variant *pValue = OpcUa_Null;
OpcUa_Int32 i = 0;
OpcUa_InitializeStatus(OpcUa_Module_Server, "UaProvider_CustomProvider_Events_SetCustomEventTypeCustomData"); // remark: this name doesn't exactly match the function-name as it lacks some underscores
OpcUa_ReturnErrorIfArgumentNull(a_pEvent);
OpcUa_ReturnErrorIfArgumentNull(a_pValues);
pValue = (OpcUa_Variant*)UaBase_Vector_Get(&a_pEvent->EventFields, CustomEventTypeField_CustomData);
OpcUa_ReturnErrorIfNull(pValue, OpcUa_BadNoData);
OpcUa_Variant_Clear(pValue);
pValue->Value.Array.Value.ExtensionObjectArray = (OpcUa_ExtensionObject*)OpcUa_Alloc(a_iNoOfValues * sizeof(OpcUa_ExtensionObject));
OpcUa_ReturnErrorIfAllocFailed(pValue->Value.Array.Value.ExtensionObjectArray);
OpcUa_MemSet(pValue->Value.Array.Value.ExtensionObjectArray, 0, a_iNoOfValues * sizeof (OpcUa_ExtensionObject));
for (i = 0; i < a_iNoOfValues; i++)
{
uStatus = OpcUa_EncodeableObject_CreateExtension(&CustomProvider_CustomDataType_EncodeableType, &pValue->Value.Array.Value.ExtensionObjectArray[i], (OpcUa_Void**)&pCustomDataValue);
OpcUa_GotoErrorIfBad(uStatus);
}
pValue->Datatype = OpcUaType_ExtensionObject;
pValue->ArrayType = OpcUa_VariantArrayType_Array;
pValue->Value.Array.Length = a_iNoOfValues;
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_Variant_Clear(pValue);
OpcUa_FinishErrorHandling;
}