Skip to content
Snippets Groups Projects
Commit 592794ba authored by Robert L. Read's avatar Robert L. Read
Browse files

handling arduion resets

parent 6b8b3dff
No related branches found
Tags v0.3T
No related merge requests found
...@@ -1184,8 +1184,8 @@ function process(samples) { ...@@ -1184,8 +1184,8 @@ function process(samples) {
$("#time_start").text((start) ? start.toISOStringSeconds() : null); $("#time_start").text((start) ? start.toISOStringSeconds() : null);
$("#time_finish").text((finish) ? finish.toISOStringSeconds() : null); $("#time_finish").text((finish) ? finish.toISOStringSeconds() : null);
LAST_SAMPLE_DATE = finish; LAST_SAMPLE_DATE = finish;
console.log("process",start); // console.log("process",start);
console.log("process",finish); // console.log("process",finish);
} }
// WARNING: This is a hack...if the timestamp is negative, // WARNING: This is a hack...if the timestamp is negative,
...@@ -1247,7 +1247,7 @@ function retrieveAndPlot(){ ...@@ -1247,7 +1247,7 @@ function retrieveAndPlot(){
// console.log("Z",currentDate); // console.log("Z",currentDate);
} else { } else {
} }
// console.log("url =",url); // console.log("url =",decodeURI(url));
$.ajax({url: url, $.ajax({url: url,
success: function(cur_sam){ success: function(cur_sam){
...@@ -1260,7 +1260,7 @@ function retrieveAndPlot(){ ...@@ -1260,7 +1260,7 @@ function retrieveAndPlot(){
console.log("No return"); console.log("No return");
return; return;
} }
// console.log("returned ",cur_sam.length); // console.log("returned ",cur_sam.length,cur_sam);
if (cur_sam && cur_sam.length == 0) { if (cur_sam && cur_sam.length == 0) {
// This is no longer true now that we are asking for time... // This is no longer true now that we are asking for time...
// console.log("no samples; potential misconfiguration!"); // console.log("no samples; potential misconfiguration!");
...@@ -1270,13 +1270,20 @@ function retrieveAndPlot(){ ...@@ -1270,13 +1270,20 @@ function retrieveAndPlot(){
console.log("Error!"); console.log("Error!");
stop_interval_timer(); stop_interval_timer();
$("#livetoggle").prop("checked",false); $("#livetoggle").prop("checked",false);
console.log(cur_sam); // console.log(cur_sam);
} else { } else {
cur_sam = sanitize_samples(cur_sam); cur_sam = sanitize_samples(cur_sam);
if (INITS_ONLY) { if (INITS_ONLY) {
samples = cur_sam; samples = cur_sam;
INITS_ONLY = false; INITS_ONLY = false;
} else { } else {
var first_new_ms = cur_sam[0].ms;
var cur_first_ms = samples[0].ms;
if (first_new_ms < cur_first_ms) { // This means a reset of the Arduino, we will dump samples..
samples = [];
console.log("DETECTED ARDUINO RESET, DUMPING CURRENT SAMPLES");
}
var discard = Math.max(0, var discard = Math.max(0,
samples.length + cur_sam.length - MAX_SAMPLES_TO_STORE_S); samples.length + cur_sam.length - MAX_SAMPLES_TO_STORE_S);
samples = samples.slice(discard); samples = samples.slice(discard);
...@@ -1289,6 +1296,7 @@ function retrieveAndPlot(){ ...@@ -1289,6 +1296,7 @@ function retrieveAndPlot(){
// This would be more efficient if done after sorting.. // This would be more efficient if done after sorting..
var n = samples.length; var n = samples.length;
// I think this is de-dupeing code...
samples = samples.filter((s, index, self) => samples = samples.filter((s, index, self) =>
self.findIndex(t => t.ms === s.ms self.findIndex(t => t.ms === s.ms
&& t.type === s.type && t.type === s.type
...@@ -1297,26 +1305,20 @@ function retrieveAndPlot(){ ...@@ -1297,26 +1305,20 @@ function retrieveAndPlot(){
&& t.event === s.event && t.event === s.event
&& t.val === s.val) === index); && t.val === s.val) === index);
} }
samples = samples.filter((s, index, self) =>
self.findIndex(t => t.ms === s.ms
&& t.type === s.type
&& t.loc === s.loc
&& t.num === s.num
&& t.event === s.event
&& t.val === s.val) === index);
if (n != samples.length) { if (n != samples.length) {
console.log("deduped:",n-samples.length); // console.log("deduped:",n-samples.length);
} }
samples = samples.sort((a,b) => a.ms - b.ms);
// Now we will trim off samples if we are live... // Now we will trim off samples if we are live...
if (intervalID) { if (intervalID) {
var last_ms = samples[samples.length-1].ms var last_ms = samples[samples.length-1].ms
samples = samples.filter((s, index, self) => samples = samples.filter((s, index, self) =>
s.ms >= (last_ms - DESIRED_DURATION_S*1000)); s.ms >= (last_ms - DESIRED_DURATION_S*1000));
} }
// console.log(samples);
process(samples); process(samples);
console.log("END",LAST_SAMPLE_DATE); // console.log("END",LAST_SAMPLE_DATE);
} }
}, },
error: function(xhr, ajaxOptions, thrownError) { error: function(xhr, ajaxOptions, thrownError) {
......
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