-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
148 lines (131 loc) · 2.87 KB
/
app.js
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
// Import required modules
const express = require('express');
const bodyParser = require('body-parser');
var om2mrpm=0;
var cin='0';
var prev_cin='0';
var rpm = 80;
var kp = 5;
var ki = 0.001;
var kd = 0.25;
var count = 0;
var currrpm = 0;
var count1 = 0;
// Create an instance of express
const app = express();
// Set up middleware
app.use(bodyParser.json());
// Import routes
// Catch all other routes and return the index file
app.get('/', (req, res) => {
// console.log(__dirname);
// res.send("Hello World");
const path = require('path');
const full_path = path.join(__dirname, 'public/index.html');
res.sendFile(full_path);
}
);
app.get('/graph', (req, res) => {
const path = require('path');
const full_path = path.join(__dirname, 'public/graph.html');
res.sendFile(full_path);
}
);
app.post('/api/updateRPM', (req, res) => {
console.log(req.body);
rpm = parseFloat(req.body.rpm);
kp = parseFloat(req.body.kp);
ki = parseFloat(req.body.ki);
kd = parseFloat(req.body.kd);
if (req.body.rpm == '') {
rpm = 80;
}
if (req.body.kp == '') {
kp = 5;
}
if (req.body.ki == '') {
ki = 0.001;
}
if (req.body.kd == '') {
kd = 0.25;
}
console.log("RPM:", rpm);
console.log("Kp:", kp);
console.log("Ki:", ki);
console.log("Kd:", kd);
count++;
res.send("OK");
});
app.get('/api/getdata', (req, res) => {
res.send({ RPM: rpm, Kp: kp, Ki: ki, Kd: kd });
}
);
// app.get('/api/getkp', (req, res) => {
// if (count > 0) {
// res.send(kp);
// }
// else {
// res.send("No data");
// }
// });
// app.get('/api/getki', (req, res) => {
// if (count > 0) {
// res.send(ki);
// }
// else {
// res.send("No data");
// }
// }
// );
// app.get('/api/getkd', (req, res) => {
// if (count > 0) {
// res.send(kd);
// }
// else {
// res.send("No data");
// }
// }
// );
app.post('/api/updatecurrRPM', (req, res) => {
console.log(req.body);
currrpm = parseFloat(req.body.currRPM);
console.log("RPM:", currrpm);
count1++;
res.send("OK");
}
);
app.get('/api/getCurrRPM', (req, res) => {
if (count1 > 0) {
const data = {
RPM: currrpm
};
res.send(data);
}
else {
res.send("0");
}
}
);
app.post('/api/updateOM2MRPM', (req, res) => {
console.log(req.body);
om2mrpm=req.body.rpm;
cin=req.body.cin;
console.log("CIN:", cin);
console.log("RPM:", om2mrpm);
om2mrpm = parseInt(om2mrpm);
console.log("RPM:", om2mrpm);
res.send("OK");
}
);
app.get('/api/getOM2MRPM', (req, res) => {
if (cin==prev_cin){
om2mrpm=-1;
}
res.send({ RPM: om2mrpm , kp: kp, ki: ki, kd: kd});
prev_cin=cin;
}
);
// Start the server
app.listen(8080, () => {
console.log('Server started on port 8080');
});