Skip to content

Commit 724f030

Browse files
authored
Merge pull request #71 from tilak-io/tlogparser
Tlogparser
2 parents ed71659 + 11a3b4c commit 724f030

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

api/parsers/tlogparser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def parse(self,filename):
2121
data = m.to_dict()
2222
name = data['mavpackettype']
2323
data['timestamp_tiplot'] = m._timestamp
24+
data['time_utc_usec'] = m._timestamp*1e6
2425
try:
2526
data['time_utc'] = str(datetime.datetime.fromtimestamp(m._timestamp))
2627
except:

src/views/SyncTimestamp.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ function SyncTimestamp() {
6363
}
6464
break;
6565

66+
case "closest-point":
67+
if ("y" in mainData && "y" in extraData) {
68+
const extra_y = extraData.y[0];
69+
const extra_x = extraData.x[0]; // Time reference
70+
console.log("Extra Y", extra_y);
71+
// Find time whe,e we have the closest value of main_y in extra_y
72+
console.log("Closest is", mainData.x[findClosestIndex(mainData.y, extra_y)]);
73+
const main_x = mainData.x[findClosestIndex(mainData.y, extra_y)];
74+
75+
setDelta(main_x - extra_x);
76+
updateXAxis();
77+
}
78+
break;
79+
6680
case "back-to-back":
6781
case "btb-inversed":
6882
const inv = document.getElementById("btb-inversed").checked;
@@ -155,7 +169,7 @@ function SyncTimestamp() {
155169
const handleRadioChange = (event) => {
156170
var selected = event.target.id;
157171
setSyncType(selected);
158-
setTimeout(function () {
172+
setTimeout(function() {
159173
autoRange();
160174
}, 200);
161175
};
@@ -164,7 +178,7 @@ function SyncTimestamp() {
164178
var selected = event.target.id;
165179
if (event.target.checked) setSyncType(selected);
166180
else setSyncType("back-to-back");
167-
setTimeout(function () {
181+
setTimeout(function() {
168182
autoRange();
169183
}, 200);
170184
};
@@ -178,6 +192,20 @@ function SyncTimestamp() {
178192
return data.x[0];
179193
};
180194

195+
const findClosestIndex = (arr, value) => {
196+
let minDiff = Number.MAX_VALUE;
197+
let closestIndex = -1;
198+
199+
for (let i = 0; i < arr.length; i++) {
200+
const diff = Math.abs(arr[i] - value);
201+
if (diff < minDiff) {
202+
minDiff = diff;
203+
closestIndex = i;
204+
}
205+
}
206+
return closestIndex;
207+
}
208+
181209
const handleApply = async () => {
182210
const req = {
183211
prefix: prefix,
@@ -211,7 +239,7 @@ function SyncTimestamp() {
211239
setStep(stp);
212240
}
213241

214-
setTimeout(function () {
242+
setTimeout(function() {
215243
autoRange();
216244
}, 200);
217245
};
@@ -227,7 +255,7 @@ function SyncTimestamp() {
227255

228256
const setupControls = () => {
229257
// TODO: Add Keyboard controls
230-
document.onkeyup = function (e) {
258+
document.onkeyup = function(e) {
231259
switch (e.code) {
232260
case "ArrowRight":
233261
case "ArrowLeft":
@@ -292,6 +320,13 @@ function SyncTimestamp() {
292320
label="Sync on first point"
293321
onChange={handleRadioChange}
294322
/>
323+
<Form.Check
324+
name="sync-type"
325+
id="closest-point"
326+
type="radio"
327+
label="Sync on closest point"
328+
onChange={handleRadioChange}
329+
/>
295330
<div className="mb-3">
296331
<Form.Check
297332
inline

0 commit comments

Comments
 (0)