[r825]: / branches / FeatureBranches / refactorpayload / SparkplugB / Function Blocks / FB_Edge / FB_Edge / NCMD / onNCMDMessage / svnobj  Maximize  Restore  History

Download this file

67 lines (61 with data), 14.0 kB

 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(*
    NCMD messages are used by backend applications to write to EoN node outputs and send Node Control
    The following is a representation of a simple NCMD message on the topic:
        spBv1.0/Sparkplug
 B Devices/NCMD/Raspberry Pi
        
   The host 
EoN node ID
 of this EoN node is: Raspberry Pi
        
   This is an NCMD message to an EoN node
    This NCMD payload tells the EoN node to republish its NBIRTH and DBIRTH(s) messages. This can be requested if
    pTopic : POINTER TO WSTRING(GC_Sparkplug.supported_string_lengths); // resembles the topic under which the message is posted 
END_VAR
VAR_IN_OUT
	eError  : ERROR;
    newMetricValid       : BOOL;
    newString : WSTRING;
    newreal   : REAL;
    newdatatype          : MetricDataType;
    i                 : DINT;
	itfExistingMetric : IRemoteMetric;
//note: pMessage is already decoded
onNCMDMessage := FALSE;
// //get first metric
pMessage.GetFirstMetric( name => newName,
	                     datatype => newdatatype,
						 timestamp => newtimestamp,
						 valueString => newString,
						 valueLreal => newLreal,
						 valueReal => newreal,
						 valueVarInt => newVarInt,
						 MetricValid => newMetricValid,
						 HasNext => newHasNext);
                         
THIS^.GetMetricbyName( DeviceId:= "", 
                       MetricName:= newName, 
                       Metric=> itfExistingMetric, 
                       GetTimestamp=> ,
                       xError=> MetricNotExisting, 
                       eError=> );
                       
IF NOT newMetricValid THEN
	; // There are no metrics, so we needn't do anything
ELSIF MetricNotExisting THEN
    WriteDeviceLog( UDINT_TO_DWORD( CmpLog.LogClass.LOG_INFO ),
						'Someone sent an NCMD with metric %s not in our NBIRTH.  It was ignored',
						TO_STRING(newName) );
	ELSE
		//update one
        Update( Metric := itfExistingMetric,
                Name := newName,
                DataType := newdatatype,
                Status := MetricStatus.ONLINE_OK,
                Timestamp := newtimestamp,
                String_ := newString,
                LReal_ :=  newLreal,
                Real_ := newreal,
                VarInt :=  newVarInt );
                
	END_IF
END_WHILE
WriteDeviceLog( UDINT_TO_DWORD( CmpLog.LogClass.LOG_INFO ),
                'EoN NCMD Received Topic: %s',
                WSTRING_TO_STRING( pTopic^ ) );
onNCMDMessage := TRUE;