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

Download this file

95 lines (87 with data), 14.5 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//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 MetricNotExisting THEN
    xError := TRUE;
    eError := Error.OhMy_ThatShouldNotHaveHappened;
    WriteDeviceLog( UDINT_TO_DWORD( CmpLog.LogClass.LOG_INFO ),
                    TO_STRING( Error.OhMy_ThatShouldNotHaveHappened ) );    
ELSE
	// update one as it allready excists
    Update( Metric := itfExistingMetric,
            Name := newName,
            DataType := newdatatype,
            Status := MetricStatus.ONLINE_OK,
            Timestamp := newtimestamp,
            String_ := newString,
            LReal_ :=  newLreal,
            Real_ := newreal,
            VarInt :=  newVarInt );
END_IF3
WHILE newHasNext DO
	pMessage.GetNextMetric( 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 MetricNotExisting THEN
        xError := TRUE;
        eError := Error.OhMy_ThatShouldNotHaveHappened;
                        'PrimaryHost ProcessNDATA MetricNotExisting but haven$'t implemeneted NCMD/Rebirth: %s',
	At the moment, this only supports the one specific metric, Node Control/Rebirth
    Node Command (NCMD)
    
    commands to EoN nodes. Multiple metrics can be supplied in a single NCMD message.
        
   The 
Group ID
 of this device is: Sparkplug
 B Devices
    Consider the following Sparkplug
 B payload in the NCMD message shown above:
    {
        "timestamp": 1486144502122,
        "metrics": [{
                "name": "Node Control/Rebirth",
                "timestamp": 1486144502122,
                "dataType": "Boolean",
                "value": true
         }]
    }
    a backend application gets an out of order seq number or if a metric arrives in an NDATA or DDATA message that
    was not provided in the original NBIRTH or DBIRTH messages.
*)
{attribute 'hide'}
METHOD onNCMDMessage : BOOL
VAR_INPUT
    pMessage : FB_PayloadSimpleDecoder; //should already be decoded
VAR_OUTPUT
	xError  : BOOL;
VAR
    newName           : WSTRING(GC_Sparkplug.supported_string_lengths);
    newVarInt : DecodedVarInt;
    newLreal  : LREAL;
    newHasNext           : BOOL;
	newtimestamp         : T_DateTime;