diff --git a/breath_plot.html b/breath_plot.html index c570058ad05c5bf316bc22ac046fca4d3890da95..5f78ed04b8b8ada2b3f7178f7b6bd54ac7e31d5c 100644 --- a/breath_plot.html +++ b/breath_plot.html @@ -28,7 +28,7 @@ Breath Plot: COVID-19 Respiration Analysis Software <!-- Load plotly.js into the DOM --> <script src='https://cdn.plot.ly/plotly-latest.min.js'></script> - <script src='./js/respiration_math.js'></script> + <script src='/respiration_math.js'></script> <title>Public Invention Respiration Analysis</title> @@ -585,7 +585,7 @@ var intervalID = null; // This sould be better as time, but is easier // to do as number of samples. -var MAX_SAMPLES_TO_STORE_S = 160; +var MAX_SAMPLES_TO_STORE_S = 2000; var MAX_REFRESH = false; var samples = []; var INITS_ONLY = true; @@ -1380,7 +1380,7 @@ function retrieveAndPlot(){ samples = samples.filter((s, index, self) => s.ms >= (last_ms - DESIRED_DURATION_S*1000)); } - console.log(samples); +// console.log(samples); if (samples.length > 0) process(samples); console.log("END",LAST_SAMPLE_DATE); diff --git a/js/respiration_math.js b/js/respiration_math.js index 55c3b70ce6d2f1f30560363c527ad555f51606fc..09790d4d1f7b926bae1cadb874224bf8f8d71697 100644 --- a/js/respiration_math.js +++ b/js/respiration_math.js @@ -122,7 +122,7 @@ function compute_fio2_mean(secs,samples) { } } - +// WARNING! With a low number of breaths, this may be wrong. function compute_respiration_rate(secs,samples,transitions,breaths) { // In order to compute the number of breaths // in the last s seconds, I compute those breaths @@ -175,6 +175,7 @@ function compute_respiration_rate(secs,samples,transitions,breaths) { i--; } if ((cnt > 1) && (first_inhale_ms != last_inhale_ms)) { + // I now think this math is specious!! var inhalation_duration = last_inhale_ms - first_inhale_ms; var inhalation_duration_min = inhalation_duration / (60.0 * 1000.0); var rr = (cnt - 1) / inhalation_duration_min; @@ -588,7 +589,7 @@ function testWorkSynthetic(){ // breaths give us inspiration transition points var vole = 0; var breaths = []; - var expiring = true; + var expiring = false; for(var i = 0; i < transitions.length; i++) { // We're looking for the end of the inhalation here!! @@ -676,6 +677,12 @@ function computeMovingWindowTrace(samples,t,v) { var voli = 0; var vole = 0; + // This code was robust when I breathed through a mask, + // but on clean simulations with negative flow, seemes to + // go awry... + // It think really it makes more sense to find the first + // transition from a non-inspiring state to an inspiring state + // and start there. for(var i = 0; i < transitions.length; i++) { // We're looking for the end of the inhalation here!! if (((i -1) >= 0) && transitions[i-1].state == 1 && (transitions[i].state == 0 || transitions[i].state == -1 )) { @@ -698,7 +705,7 @@ function computeMovingWindowTrace(samples,t,v) { vole = integrateSamples(last,transitions[i].sample,flows); last = transitions[i].sample; } - if (!expiring && transitions[i].state == -1) { + if (!expiring && (transitions[i].state == -1)) { expiring = true; voli = integrateSamples(last,transitions[i].sample,flows); last = transitions[i].sample; diff --git a/node_modules/@serialport/bindings/build/Release/bindings.node b/node_modules/@serialport/bindings/build/Release/bindings.node index 39bf8d4022b7bcd4b02aca29aa55228e808d17c6..0334927bbb4cbf9267d3375558293a5ae20a66a4 100755 Binary files a/node_modules/@serialport/bindings/build/Release/bindings.node and b/node_modules/@serialport/bindings/build/Release/bindings.node differ diff --git a/server.js b/server.js index add905f45625f3c8ad34c41f84124a08b326a92b..95e8c5e2165e26570efd912e4bb38453b7a580e3 100755 --- a/server.js +++ b/server.js @@ -8,6 +8,10 @@ var express = require('express'); const cors = require('cors'); var app = express(); app.use(cors()); + +// NOTE: We could enumerate porst with "SerialPort.list()"... +// that would be a little friendlier for people who can't find +// the filename of their serial port! const SerialPort = require('serialport'); //https://serialport.io/docs/guide-usage const Readline = require('@serialport/parser-readline'); @@ -43,6 +47,9 @@ sport.on('error', function(err) { console.log('Error: ', err.message) }) +// Note: I now believe we need to listen here for +// Acknowledgements and do something special with them to +// thottle the serial buffer. parser.on('data', data =>{ // Let's see if the data is a PIRDS event... @@ -139,12 +146,21 @@ app.get('/api/pircs', function(req, res) { res.setHeader("Content-Type", "application/json"); res.setHeader('Access-Control-Allow-Origin', '*'); - res.status(200).send(x); + res.status(200).send(x); +// The documentaiton supports this: +// function writeAndDrain (data, callback) { +// port.write(data) +// port.drain(callback) +// } + // Howewver, we are fundamentally asynchronous in processing + // requests, so it is unclear how this would work! + // Possibly we could call drain first! + sport.drain( () => sport.write(x, (err) => { if (err) { return console.log('Error on write: ', err.message); } - }); + })); } });