-
Notifications
You must be signed in to change notification settings - Fork 0
/
GridMonk_PROC_SCADA_FEP.cs
128 lines (104 loc) · 5.03 KB
/
GridMonk_PROC_SCADA_FEP.cs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Grid-MonK is an open source softwaer application intended to annalize power grids, esepcially microgrids
* The basic variant works by invoking the OpenDSS open-source application, with input files prepared by Grid_MonK
* and export output files read by OpenDSS and used for further calulations and for interracting with a grid specialist.
* Grid-Monk can be used and modified by anybody, the only condition is to keep these comments unchanged in the upper
* part of the used or modified application
* There is no guarrantee given for any functionality or for any
* influence on the computer(s) running this applications or on other applications which run on the computer(s)
* Initiator of the Grid-Monk application: Mihai Sanduleac, University Politehnica of Bucharest, Romania
* This module develops a standard SCADA interface with external acquisition modules which communicate through MQTT and a GridMonK standardized JSON messaging
* Contributors: Mihai Sanduleac
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
using Newtonsoft;
using Newtonsoft.Json;
using System.IO;
using System.Diagnostics;
namespace GridMonC
{
public partial class GridMonk : Form
{
//Client mosqsub/17072-RPI-TEST0 received PUBLISH (d0, q0, r0, m0, '/SCADA', ... (xx bytes))
// {"NodeName":"N21","U_node":"231.7","I_cons":"0.0","P_cons":"0.0","Q_cons":"-10.3"}
public class SCADA_FEP_Data
{
[DefaultValue("Node_NULL")]
[JsonProperty("NodeName", DefaultValueHandling = DefaultValueHandling.Populate)]
public String NodeName { get; set; }
[DefaultValue("0.0")]
[JsonProperty("U_node", DefaultValueHandling = DefaultValueHandling.Populate)]
public String U_node { get; set; }
[DefaultValue("0.0")]
[JsonProperty("I_cons", DefaultValueHandling = DefaultValueHandling.Populate)]
public String I_cons { get; set; }
[DefaultValue("0.0")]
[JsonProperty("P_cons", DefaultValueHandling = DefaultValueHandling.Populate)]
public String P_cons { get; set; }
[DefaultValue("0.0")]
[JsonProperty("Q_cons", DefaultValueHandling = DefaultValueHandling.Populate)]
public String Q_cons { get; set; }
}
public class SMX_FEP_Data
{
[DefaultValue("00000")]
[JsonProperty("MeterName", DefaultValueHandling = DefaultValueHandling.Populate)]
public String MeterName { get; set; }
[DefaultValue("0.0")]
[JsonProperty("U_node", DefaultValueHandling = DefaultValueHandling.Populate)]
public String U_node { get; set; }
[DefaultValue("0.0")]
[JsonProperty("I_cons", DefaultValueHandling = DefaultValueHandling.Populate)]
public String I_cons { get; set; }
[DefaultValue("0.0")]
[JsonProperty("P_cons", DefaultValueHandling = DefaultValueHandling.Populate)]
public String P_cons { get; set; }
[DefaultValue("0.0")]
[JsonProperty("Q_cons", DefaultValueHandling = DefaultValueHandling.Populate)]
public String Q_cons { get; set; }
}
void MQTT_Received_Data_SCADA_FEP(MqttMsgPublishEventArgs e)
{
string NodeName, MeterName, U_node, I_cons, P_cons, Q_cons;
Debug.WriteLine("Received = " + Encoding.UTF8.GetString(e.Message) + " on topic " + e.Topic);
message_received = Encoding.UTF8.GetString(e.Message);
// verify the received topic and process the information
if(e.Topic == "/SCADA")
{
var serializer = new JsonSerializer();
SCADA_FEP_Data res = serializer.Deserialize<SCADA_FEP_Data>(new JsonTextReader(new StringReader(Encoding.UTF8.GetString(e.Message))));
NodeName = res.NodeName;
U_node = res.U_node; I_cons = res.I_cons; P_cons = res.P_cons; Q_cons = res.Q_cons;
}
if (e.Topic == "/SMX")
{
var serializer = new JsonSerializer();
SMX_FEP_Data res = serializer.Deserialize<SMX_FEP_Data>(new JsonTextReader(new StringReader(Encoding.UTF8.GetString(e.Message))));
MeterName = res.MeterName;
U_node = res.U_node; I_cons = res.I_cons; P_cons = res.P_cons; Q_cons = res.Q_cons;
}
}
private void PROC_ini_SCADA_FEP()
{
// read SCADA_FEP config file "PROC_SCADA_FEP_config_file.txt"
//
}
private void timer3_PROC_SCADA_FEP(object sender, EventArgs e)
{
// Main loop of SCADA_FEP
// Publish new commands in MQTT/JSON format
// Make load-flow with new data
}
}
}