-
Notifications
You must be signed in to change notification settings - Fork 0
/
getData.php
134 lines (125 loc) · 4.74 KB
/
getData.php
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
<?php
require('./socket.php');
require('./socketClient.php');
//$socket = new socketClient('10.13.100.68', 8001);
$socket = new socketClient('179.156.26.52', 8002);
//
//if (isset($_GET['sensor'])) {
// echo 'ok';
//// $packet = array('OP' => '1','sensor' => '1',);
//// echo $socket->send(json_encode($packet));
//}
//
////setando valor de tensão para a bomba
//if (isset($_GET['bomba'])) {
// if (isset($_GET['tensao'])) {
// $setPoint = $_GET['tensao'];
//
// //enviando o comando para o servidor
// $packet = array(
// 'OP' => '0',
// 'tensao' => '' . $setPoint . '',
// );
// $socket->send(json_encode($packet));
// echo json_encode(floatval($setPoint));
// }
//}
//
//if (isset($_GET['tanque'])) {
// if (isset($_GET['nivel'])) {
// $setPoint = $_GET['nivel'];
// $setTanque = $_GET['tanque'];
//
//// enviando o comando para o servidor
// $packet = array(
// 'OP' => '2',
// 'tanque' => '' . $setTanque . '',
// 'altura' => '' . $setPoint . '',
// );
// $response = $socket->send(json_encode($packet));
// $nivel = json_decode($response, true)['response'];
// echo json_encode(floatVal($nivel));
// }
//}
//
// --- Novo
// ---------------------------------------- LEITURA DOS DADOS
if (isset($_GET['leitura'])) {
$packet = array('comando' => 0,);
echo $socket->send(json_encode($packet));
}
// ---------------------------------------- COMANDO NA PLANTA
if (isset($_GET['controle'])) {
if (isset($_GET['malha'])) {
// if (isset($_GET['sinal'])) {
//Dados do sinal
$sinal_tipo = $_GET['sgntipo'];
$amp_max = (float) $_GET['ampmax'];
$amp_min = (float) $_GET['ampmin'];
$periodo_max = (float) $_GET['periodomax'];
$periodo_min = (float) $_GET['periodomin'];
$offset = (float) $_GET['offset'];
if ($_GET['malha'] === 'true') { //malha aberta
$packet = array(
'comando' => 1,
'malha_aberta' => true,
'com_sinal' => true,
'sinal' => array(
'tipo' => $sinal_tipo,
'amp_max' => $amp_max,
'amp_min' => $amp_min,
'periodo_max' => $periodo_max,
'periodo_min' => $periodo_min,
'offset' => $offset,
)
);
// echo json_encode($packet);
echo $socket->send(json_encode($packet));
} else { //malha fechada
//Dados do controle
$ctrl_tipo = $_GET['ctrltipo'];
$kp = (float) $_GET['kp'];
$ki = (float) $_GET['ki'];
$kd = (float) $_GET['kd'];
if ($_GET['controle'] === 'true') { //malha fechada COM sinal de controle
$packet = array(
'comando' => 1,
'malha_aberta' => false,
'com_sinal' => true,
'sinal' => array(
'tipo' => $sinal_tipo,
'amp_max' => $amp_max,
'amp_min' => $amp_min,
'periodo_max' => $periodo_max,
'periodo_min' => $periodo_min,
'offset' => $offset,
),
'controle' => array(
'tipo' => $ctrl_tipo,
'Kp' => $kp,
'Ki' => $ki,
'Kd' => $kd,
)
);
// echo json_encode($packet);
echo $socket->send(json_encode($packet));
} else { //malha fechada SEM sinal de controle
$packet = array(
'comando' => 1,
'malha_aberta' => false,
'com_sinal' => false,
'controle' => array(
'tipo' => $ctrl_tipo,
'Kp' => $kp,
'Ki' => $ki,
'Kd' => $kd,
)
);
// echo json_encode($packet);
echo $socket->send(json_encode($packet));
}
}
// }
}
}
// ---------------------------------------- ABORTAR PLANTA