-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathplugin.cpp
303 lines (239 loc) · 7.37 KB
/
plugin.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#include <iec61850.h>
#include <plugin_api.h>
#include <stdio.h>
#include <string>
#include <logger.h>
#include <config_category.h>
#include <rapidjson/document.h>
#include <version.h>
#include <iec61850_model.h>
typedef void (*INGEST_CB)(void *, Reading);
using namespace std;
#define PLUGIN_NAME "iec61850"
/**
* Default configuration
*/
static const char *default_config = QUOTE ({
"plugin" : {
"description" : "iec61850 south plugin",
"type" : "string",
"default" : PLUGIN_NAME,
"readonly" : "true"
},
"asset" : {
"description" : "Asset name",
"type" : "string",
"default" : "iec61850",
"displayName" : "Asset Name",
"order" : "1",
"mandatory" : "true"
},
"ip" : {
"description" : "IP of the Server",
"type" : "string",
"default" : "127.0.0.1",
"displayName" : "61850 Server IP",
"order" : "2"
},
"port" : {
"description" : "Port number of the 61850 server",
"type" : "integer",
"default" : "102",
"displayName" : "61850 Server port"
},
"IED Model" : {
"description" : "Name of the 61850 IED model",
"type" : "string", //IedModel
"default" : "simpleIO",
"displayName" : "61850 Server IedModel"
},
"Logical Device" : {
"description" : "Logical device of the 61850 server",
"type" : "string", //LogicalDevice
"default" : "GenericIO",
"displayName" : "61850 Server logical device"
},
"Logical Node" : {
"description" : "Logical node of the 61850 server",
"type" : "string", //LogicalNode
"default" : "GGIO1",
"displayName" : "61850 Server logical node"
},
"CDC" : {
"description" : "CDC name of the 61850 server",
"type" : "string", //CDC_SAV
"default" : "SPCSO1",
"displayName" : "61850 Server CDC_SAV"
},
"Data Attribute" : {
"description" : "Data attribute of the CDC",
"type" : "string", //dataAttribute
"default" : "stVal",
"displayName" : "61850 Server data attribute"
},
"Functional Constraint" : {
"description" : "Functional constraint of the 61850 server",
"type" : "string", //FC
"default" : "ST",
"displayName" : "61850 Server functional constraint"
}
});
/**
* The 61850 plugin interface
*/
extern "C" {
static PLUGIN_INFORMATION info = {
PLUGIN_NAME, // Name
VERSION, // Version
SP_ASYNC, // Flags
PLUGIN_TYPE_SOUTH, // Type
"1.0.0", // Interface version
default_config // Default configuration
};
/**
* Return the information about this plugin
*/
PLUGIN_INFORMATION *plugin_info() {
Logger::getLogger()->info("61850 Config is %s", info.config);
return &info;
}
PLUGIN_HANDLE plugin_init(ConfigCategory *config) {
IEC61850 *iec61850;
Logger::getLogger()->info("Initializing the plugin");
string ip = "127.0.0.1";
string model="testmodel";
string logicalNode;
string logicalDevice;
string cdc;
string attribute;
string fc;
uint16_t port = 8102;
if (config->itemExists("ip")){
ip = config->getValue("ip");
}
if (config->itemExists("port")){
port = static_cast<uint16_t>(stoi(config->getValue("port")));
char str[80];
sprintf(str, "%u", port);
}
if (config->itemExists("IED Model")) {
model = (config->getValue("IED Model"));
}
if (config->itemExists("Logical Device")) {
logicalDevice = config->getValue("Logical Device");
}
if (config->itemExists("Logical Node")) {
logicalNode = config->getValue("Logical Node");
}
if (config->itemExists("CDC")) {
cdc = config->getValue("CDC");
}
if (config->itemExists("Functional Constraint")) {
fc = config->getValue("Functional Constraint");
}
if (config->itemExists("Data Attribute")) {
attribute = config->getValue("Data Attribute");
}
iec61850 = new IEC61850(ip.c_str(), port, model, logicalNode, logicalDevice, cdc, attribute, fc);
if (config->itemExists("asset")) {
iec61850->setAssetName(config->getValue("asset"));
} else {
iec61850->setAssetName("iec61850");
}
return (PLUGIN_HANDLE) iec61850;
}
/**
* Start the Async handling for the plugin
*/
void plugin_start(PLUGIN_HANDLE *handle) {
if (!handle)
return;
Logger::getLogger()->info("Starting the plugin");
IEC61850 *iec61850 = (IEC61850 *) handle;
iec61850->start();
}
/**
* Register ingest callback
*/
void plugin_register_ingest(PLUGIN_HANDLE *handle, INGEST_CB cb, void *data) {
if (!handle)
throw new exception();
IEC61850 *iec61850 = (IEC61850 *) handle;
iec61850->registerIngest(data, cb);
}
/**
* Poll for a plugin reading
*/
Reading plugin_poll(PLUGIN_HANDLE *handle) {
throw runtime_error("IEC_104 is an async plugin, poll should not be called");
}
/**
* Reconfigure the plugin
*
*/
void plugin_reconfigure(PLUGIN_HANDLE *handle, string &newConfig) {
ConfigCategory config("new", newConfig);
auto *iec61850 = (IEC61850 *) *handle;
std::unique_lock<std::mutex> guard2(iec61850->loopLock);
iec61850->loopActivated = false;
iec61850->loopThread.join();
string ip;
string model;
string logicalNode;
string logicalDevice;
string cdc;
string attribute;
string fc;
uint16_t port;
iec61850->stop();
if (config.itemExists("ip")){
ip = config.getValue("ip");
iec61850->setIp(ip.c_str());
}
if (config.itemExists("port")){
port = static_cast<uint16_t>(stoi(config.getValue("port")));
char str[80];
sprintf(str, "%u", port);
iec61850->setPort(port);
}
if (config.itemExists("IED Model")) {
model = (config.getValue("IED Model"));
iec61850->setModel(model);
}
if (config.itemExists("Logical Device")) {
logicalDevice = config.getValue("Logical Device");
iec61850->setLogicalDevice(logicalDevice);
}
if (config.itemExists("Logical Node")) {
logicalNode = config.getValue("Logical Node");
iec61850->setLogicalNode(logicalNode);
}
if (config.itemExists("CDC")) {
cdc = config.getValue("CDC");
iec61850->setCdc(cdc);
}
if (config.itemExists("Data Attribute")) {
attribute = config.getValue("Data Attribute");
iec61850->setAttribute(attribute);
}
if (config.itemExists("Functional Constraint")) {
fc = config.getValue("Functional Constraint");
iec61850->setFc(fc);
}
if (config.itemExists("asset")) {
iec61850->setAssetName(config.getValue("asset"));
} else {
iec61850->setAssetName("iec61850");
}
iec61850->start();
guard2.unlock();
}
/**
* Shutdown the plugin
*/
void plugin_shutdown(PLUGIN_HANDLE *handle) {
auto *iec61850 = (IEC61850 *) handle;
iec61850->stop();
delete iec61850;
}
}