1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | {attribute 'hide'} METHOD onSubscribeMessage : BOOL VAR_INPUT pMessage : FB_PayloadSimpleDecoder; //should already be decoded VAR_OUTPUT xError : BOOL; eError : ERROR; VAR handledError : ERROR; //an error that will be given back by a function, but we can handle the error. If not, it will be in the VAR_OUTPUT.eError myGroupId : REFERENCE TO FB_GroupId; myEdge : REFERENCE TO FB_RemoteEdge; myDevice : REFERENCE TO FB_RemoteDevice; myTopic( pTopic := pTopic ); //parses the topic CASE myTopic.MessageType OF //SparkplugMessageTypes myGroupId REF= THIS^.allocGroupId( GroupId := myTopic.GroupId, myEdge REF= THIS^.allocEdgetoGroupId( EdgeId := myTopic.EdgeId, eError => eError ); IF eError = ERROR.NO_ERROR THEN pMessage := pMessage, xError => xError, myGroupId REF= THIS^.GetGroupID( GroupId := myTopic.GroupId, SparkplugMessageTypes.NDEATH: //Death certificate for MQTT EoN nodes. eError := ERROR.NotImplemented; myDevice REF= THIS^.GetDevice( GroupId := myTopic.GroupId, DeviceId := myTopic.DeviceId, ERROR.GroupIDNotFound: // ==> NEW GROUP! must rebirth the edge ERROR.NO_ERROR: // ==> UPDATE EXISTING DEVICE SparkplugMessageTypes.STATE: //Critical application state message ; //do nothing, ignore these ELSE ; //{info 'TODO: maybe some sort of error??'} END_CASE WriteDeviceLog( UDINT_TO_DWORD( CmpLog.LogClass.LOG_INFO ), 'PrimaryHost Received Topic: %s', WSTRING_TO_STRING( pTopic^ ) ); onSubscribeMessage := TRUE; |