forked from mzillgith/libiec61850
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeagle_client.c
115 lines (77 loc) · 3.15 KB
/
beagle_client.c
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
/*
* beagle_client.c
*
* Switch LEDs on the BeagleBone
*/
#include "iec61850_client.h"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv) {
char* hostname;
int tcpPort = 102;
if (argc > 1)
hostname = argv[1];
else
hostname = "localhost";
if (argc > 2)
tcpPort = atoi(argv[2]);
IedClientError error;
IedConnection con = IedConnection_create();
IedConnection_connect(con, &error, hostname, tcpPort);
if (error == IED_ERROR_OK) {
/************************
* Direct control
***********************/
bool led4State = false;
ControlObjectClient controlLED1
= ControlObjectClient_create("beagleGenericIO/GGIO1.SPCSO1", con);
ControlObjectClient controlLED2
= ControlObjectClient_create("beagleGenericIO/GGIO1.SPCSO2", con);
ControlObjectClient controlLED3
= ControlObjectClient_create("beagleGenericIO/GGIO1.SPCSO3", con);
ControlObjectClient controlLED4
= ControlObjectClient_create("beagleGenericIO/GGIO1.DPCSO1", con);
MmsValue* ctlValOn = MmsValue_newBoolean(true);
MmsValue* ctlValOff = MmsValue_newBoolean(false);
if (!ControlObjectClient_operate(controlLED1, ctlValOff, 0)) goto control_error;
ControlObjectClient_select(controlLED2);
if (!ControlObjectClient_operate(controlLED2, ctlValOff, 0)) goto control_error;
if (!ControlObjectClient_operate(controlLED4, ctlValOff, 0)) goto control_error;
while (1) {
if (!ControlObjectClient_operate(controlLED3, ctlValOff, 0)) goto control_error;
if (!ControlObjectClient_operate(controlLED1, ctlValOn, 0)) goto control_error;
Thread_sleep(1000);
if (!ControlObjectClient_operate(controlLED1, ctlValOff, 0)) goto control_error;
ControlObjectClient_select(controlLED2);
if (!ControlObjectClient_operate(controlLED2, ctlValOn, 0)) goto control_error;
Thread_sleep(1000);
ControlObjectClient_select(controlLED2);
if (!ControlObjectClient_operate(controlLED2, ctlValOff, 0)) goto control_error;
if (!ControlObjectClient_operate(controlLED3, ctlValOn, 0)) goto control_error;
Thread_sleep(1000);
if (led4State == false) {
if (!ControlObjectClient_operate(controlLED4, ctlValOn, 0)) goto control_error;
led4State = true;
}
else {
if (!ControlObjectClient_operate(controlLED4, ctlValOff, 0)) goto control_error;
led4State = false;
}
}
goto exit_control_loop;
control_error:
printf("Error controlling device!\n");
exit_control_loop:
MmsValue_delete(ctlValOn);
MmsValue_delete(ctlValOff);
ControlObjectClient_destroy(controlLED1);
ControlObjectClient_destroy(controlLED2);
ControlObjectClient_destroy(controlLED3);
ControlObjectClient_destroy(controlLED4);
IedConnection_close(con);
}
else {
printf("Connection failed!\n");
}
IedConnection_destroy(con);
}