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

Added support for PIRCS

parent 81cd95af
Branches
No related tags found
No related merge requests found
...@@ -1416,33 +1416,43 @@ $( document ).ready(function() { ...@@ -1416,33 +1416,43 @@ $( document ).ready(function() {
// CONTROL PANEL INIT START // CONTROL PANEL INIT START
$("#control-slot button").click(function() { $("#control-slot button").click(function() {
var lh = $("#dserverurl").val(); var lh = $("#dserverurl").val();
$.ajax({url: lh+"/vent.html", $.ajax({url: lh+"/vent.html"})
success: function(result) { .done(function(result) {
//console.log("result "+ result); // Show the control panel
$("#control-slot").html(result); $("#control-slot").html(result);
// Send PIRCS commands when START button is pressed
$("#control-start").click(function(event) { $("#control-start").click(function(event) {
// Send a command to a connected device via serial port // Send a command to a connected device via serial port
console.log("Sending PIRCS...");
var rr = $("#control-rr").val(); var dict = {
console.log("rr: " + rr); M: $("#control-mode").val(),
var lh = "http://localhost:5000"; B: $("#control-rr").val(),
$.ajax({url: lh+"/api/set?rr="+rr, I: $("#control-ie").val(),
success: function(result) { P: $("#control-pinsp").val(),
E: $("#control-peep").val()
}
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)); console.log("result: " + JSON.stringify(result));
}, }).fail(function(xhr, ajaxOptions, thrownError) {
error: function(xhr, ajaxOptions, thrownError) {
console.log("Error! " + xhr.status); console.log("Error! " + xhr.status);
console.log(thrownError); console.log(thrownError);
} })
});
}
}); });
// Update values on slider change
$("#control-mode").on("input", () => { $("#control-mode").on("input", () => {
var m = $("#control-mode").val(); var m = $("#control-mode").val();
if (m === "0"){ if (m === "0"){
...@@ -1468,15 +1478,14 @@ $( document ).ready(function() { ...@@ -1468,15 +1478,14 @@ $( document ).ready(function() {
$("#control-peep").on("input", () => { $("#control-peep").on("input", () => {
$("#control-peep-val").html($("#control-peep").val()); $("#control-peep-val").html($("#control-peep").val());
}); });
})
}, .fail(function(){
error: function(xhr, ajaxOptions, thrownError) { console.log("Couldn't open control panel!");
console.log("Error! " + xhr.status);
console.log(thrownError);
}
}); });
}); });
// CONTROL PANEL INIT END // CONTROL PANEL INIT END
......
var express = require('express'); var express = require('express');
const cors = require('cors');
var app = express(); var app = express();
app.use(cors());
const SerialPort = require('serialport'); //https://serialport.io/docs/guide-usage const SerialPort = require('serialport'); //https://serialport.io/docs/guide-usage
const Readline = require('@serialport/parser-readline'); const Readline = require('@serialport/parser-readline');
...@@ -43,6 +45,70 @@ app.get('/api/set', function(req, res) { ...@@ -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) { /*app.get('/rr/:rr', function(req,res) {
res.send(req.params); res.send(req.params);
port.write(JSON.stringify(req.params)+'\n', (err) => { port.write(JSON.stringify(req.params)+'\n', (err) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment