Skip to content
Snippets Groups Projects
Commit 2aa68475 authored by Ben Coombs's avatar Ben Coombs
Browse files

Added support for PIRCS

parent 81cd95af
No related branches found
No related tags found
No related merge requests found
......@@ -1416,33 +1416,43 @@ $( document ).ready(function() {
// CONTROL PANEL INIT START
$("#control-slot button").click(function() {
var lh = $("#dserverurl").val();
$.ajax({url: lh+"/vent.html",
success: function(result) {
//console.log("result "+ result);
$.ajax({url: lh+"/vent.html"})
.done(function(result) {
// Show the control panel
$("#control-slot").html(result);
// Send PIRCS commands when START button is pressed
$("#control-start").click(function(event) {
// Send a command to a connected device via serial port
console.log("Sending PIRCS...");
var dict = {
M: $("#control-mode").val(),
B: $("#control-rr").val(),
I: $("#control-ie").val(),
P: $("#control-pinsp").val(),
E: $("#control-peep").val()
}
var rr = $("#control-rr").val();
console.log("rr: " + rr);
var lh = "http://localhost:5000";
$.ajax({url: lh+"/api/set?rr="+rr,
success: function(result) {
for (var k in dict){
$.ajax({
//url: lh+"/api/pircs?com=C&par="+parName+"&int="+interp+"&mod="+modifier+"&val="+val,
type: 'GET',
url: 'http://localhost:5000/api/pircs/',
dataType: 'json',
data: { com: "C", par: k, int: "T", mod: 0, val: dict[k] }
}).done(function(result) {
console.log("result: " + JSON.stringify(result));
},
error: function(xhr, ajaxOptions, thrownError) {
}).fail(function(xhr, ajaxOptions, thrownError) {
console.log("Error! " + xhr.status);
console.log(thrownError);
}
});
})
}
});
// Update values on slider change
$("#control-mode").on("input", () => {
var m = $("#control-mode").val();
if (m === "0"){
......@@ -1468,15 +1478,14 @@ $( document ).ready(function() {
$("#control-peep").on("input", () => {
$("#control-peep-val").html($("#control-peep").val());
});
},
error: function(xhr, ajaxOptions, thrownError) {
console.log("Error! " + xhr.status);
console.log(thrownError);
}
});
})
.fail(function(){
console.log("Couldn't open control panel!");
});
});
// CONTROL PANEL INIT END
......
var express = require('express');
const cors = require('cors');
var app = express();
app.use(cors());
const SerialPort = require('serialport'); //https://serialport.io/docs/guide-usage
const Readline = require('@serialport/parser-readline');
......@@ -43,6 +45,70 @@ app.get('/api/set', function(req, res) {
});
});
// /api/pircs?com=C&par=P&int=T&mod=0&val=400
app.get('/api/pircs', function(req, res) {
var err = '';
var x = '{ ';
if (req.query.com){
x += '"com" : "' + req.query.com + '" , ';
} else {
err += "com not defined! ";
}
if (req.query.par){
x += '"par" : "' + req.query.par + '" , ';
} else {
err += "par not defined! ";
}
if (req.query.int){
x += '"int" : "' + req.query.int + '" , ';
} else {
err += "int not defined! ";
}
if (req.query.mod){
x += '"mod" : ' + req.query.mod + ' , ';
} else {
err += "mod not defined! ";
}
if (req.query.val){
x += '"val" : ' + req.query.val;
} else {
err += "val not defined! ";
}
x += ' }\n';
if (err.length > 0){
err += "\n"
res.setHeader("Content-Type", "text/plain");
res.setHeader('Access-Control-Allow-Origin', '*');
res.status(400).send(err);
} else {
res.setHeader("Content-Type", "application/json");
res.setHeader('Access-Control-Allow-Origin', '*');
res.status(200).send(x);
port.write(x, (err) => {
if (err) {
return console.log('Error on write: ', err.message);
}
});
}
// { "com" : "C" , "par" : "P" , "int" : "T" , "mod" : 0 , "val" : 400 }
});
// /api/pircs2/C/P/T/0/400
app.get('/api/pircs2/:com/:par/:int/:mod/:val', function(req,res) {
res.send(req.params);
port.write(JSON.stringify(req.params)+'\n', (err) => {
if (err) {
return console.log('Error on write: ', err.message);
}
});
// JSON.stringify returns: {"com":"C","par":"P","int":"T","mod":"0","val":"400"}
})
/*app.get('/rr/:rr', function(req,res) {
res.send(req.params);
port.write(JSON.stringify(req.params)+'\n', (err) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment