@ingissa/navcore-simulator 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -10
- package/dist/index-i9TY71RY.d.mts +494 -0
- package/dist/index-i9TY71RY.d.ts +494 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -28
- package/dist/index.js +937 -29
- package/dist/index.mjs +929 -0
- package/dist/node.d.mts +1 -0
- package/dist/node.d.ts +1 -26
- package/dist/node.js +937 -25
- package/dist/node.mjs +929 -0
- package/dist/react-native.d.mts +82 -0
- package/dist/react-native.d.ts +82 -0
- package/dist/react-native.js +1370 -0
- package/dist/react-native.mjs +1360 -0
- package/package.json +15 -5
- package/dist/core/NoiseEngine.d.ts +0 -46
- package/dist/core/NoiseEngine.d.ts.map +0 -1
- package/dist/core/NoiseEngine.js +0 -106
- package/dist/core/RouteWalker.d.ts +0 -75
- package/dist/core/RouteWalker.d.ts.map +0 -1
- package/dist/core/RouteWalker.js +0 -177
- package/dist/core/SimulatorEngine.d.ts +0 -53
- package/dist/core/SimulatorEngine.d.ts.map +0 -1
- package/dist/core/SimulatorEngine.js +0 -283
- package/dist/core/types.d.ts +0 -129
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -7
- package/dist/fleet/FleetSimulator.d.ts +0 -60
- package/dist/fleet/FleetSimulator.d.ts.map +0 -1
- package/dist/fleet/FleetSimulator.js +0 -114
- package/dist/index.d.ts.map +0 -1
- package/dist/node.d.ts.map +0 -1
- package/dist/react-native/SimulatorControls.d.ts +0 -35
- package/dist/react-native/SimulatorControls.d.ts.map +0 -1
- package/dist/react-native/SimulatorControls.js +0 -254
- package/dist/react-native/useSimulator.d.ts +0 -55
- package/dist/react-native/useSimulator.d.ts.map +0 -1
- package/dist/react-native/useSimulator.js +0 -97
- package/dist/replay/GpxParser.d.ts +0 -40
- package/dist/replay/GpxParser.d.ts.map +0 -1
- package/dist/replay/GpxParser.js +0 -95
- package/dist/replay/SessionRecorder.d.ts +0 -37
- package/dist/replay/SessionRecorder.d.ts.map +0 -1
- package/dist/replay/SessionRecorder.js +0 -120
- package/dist/scenarios/ScenarioInjector.d.ts +0 -55
- package/dist/scenarios/ScenarioInjector.d.ts.map +0 -1
- package/dist/scenarios/ScenarioInjector.js +0 -150
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SessionRecorder — Record and export simulation sessions.
|
|
3
|
-
*
|
|
4
|
-
* Supports JSON, GPX 1.1, and CSV export formats.
|
|
5
|
-
*
|
|
6
|
-
* The GPX export is the critical format: a session recorded in the simulator
|
|
7
|
-
* can be exported as GPX, then replayed via GpxParser on a future run.
|
|
8
|
-
* This creates a full regression test loop:
|
|
9
|
-
* real GPS trace → gpx → GpxParser → SimulatorEngine → CI test
|
|
10
|
-
*/
|
|
11
|
-
/** Generate a UUID v4 without external dependencies */
|
|
12
|
-
function uuidV4() {
|
|
13
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
14
|
-
const r = (Math.random() * 16) | 0;
|
|
15
|
-
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
16
|
-
return v.toString(16);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export class SessionRecorder {
|
|
20
|
-
constructor() {
|
|
21
|
-
this._sessionId = null;
|
|
22
|
-
this._startedAt = null;
|
|
23
|
-
this._session = null;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Start a new recording.
|
|
27
|
-
* If the engine already has a session via startRecording(), you can pass
|
|
28
|
-
* the existing sessionId to keep IDs consistent.
|
|
29
|
-
*/
|
|
30
|
-
start(sessionId) {
|
|
31
|
-
this._sessionId = sessionId ?? uuidV4();
|
|
32
|
-
this._startedAt = Date.now();
|
|
33
|
-
this._session = null;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Stop recording and return the captured session.
|
|
37
|
-
* If called with an existing SimSession (from SimulatorEngine.stopRecording()),
|
|
38
|
-
* it stores that session for subsequent export() calls.
|
|
39
|
-
*/
|
|
40
|
-
stop(existing) {
|
|
41
|
-
if (existing) {
|
|
42
|
-
this._session = existing;
|
|
43
|
-
return existing;
|
|
44
|
-
}
|
|
45
|
-
// Minimal empty session if stop() is called without an engine session
|
|
46
|
-
const session = {
|
|
47
|
-
id: this._sessionId ?? uuidV4(),
|
|
48
|
-
startedAt: new Date(this._startedAt ?? Date.now()).toISOString(),
|
|
49
|
-
endedAt: new Date().toISOString(),
|
|
50
|
-
route: [],
|
|
51
|
-
positions: [],
|
|
52
|
-
scenarios: [],
|
|
53
|
-
stats: {
|
|
54
|
-
durationMs: Date.now() - (this._startedAt ?? Date.now()),
|
|
55
|
-
distanceTravelledM: 0,
|
|
56
|
-
avgSpeedKmh: 0,
|
|
57
|
-
noiseSamplesAdded: 0,
|
|
58
|
-
scenariosFired: 0,
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
this._session = session;
|
|
62
|
-
return session;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Export the most recent session in the specified format.
|
|
66
|
-
* Must call stop() first.
|
|
67
|
-
*/
|
|
68
|
-
export(format) {
|
|
69
|
-
const session = this._session;
|
|
70
|
-
if (!session)
|
|
71
|
-
throw new Error('SessionRecorder: call stop() before export()');
|
|
72
|
-
switch (format) {
|
|
73
|
-
case 'json':
|
|
74
|
-
return JSON.stringify(session, null, 2);
|
|
75
|
-
case 'gpx':
|
|
76
|
-
return SessionRecorder._toGpx(session);
|
|
77
|
-
case 'csv':
|
|
78
|
-
return SessionRecorder._toCsv(session);
|
|
79
|
-
default:
|
|
80
|
-
throw new Error(`SessionRecorder: unknown format "${format}"`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// ── Static export helpers ───────────────────────────────────────────────────
|
|
84
|
-
static _toGpx(session) {
|
|
85
|
-
const trkpts = session.positions
|
|
86
|
-
.map((p) => {
|
|
87
|
-
const time = new Date(p.timestamp).toISOString();
|
|
88
|
-
return (` <trkpt lat="${p.coord[1]}" lon="${p.coord[0]}">\n` +
|
|
89
|
-
` <time>${time}</time>\n` +
|
|
90
|
-
` <extensions>\n` +
|
|
91
|
-
` <speed>${p.speed.toFixed(4)}</speed>\n` +
|
|
92
|
-
` <bearing>${p.bearing.toFixed(4)}</bearing>\n` +
|
|
93
|
-
` <accuracy>${p.accuracy.toFixed(2)}</accuracy>\n` +
|
|
94
|
-
` </extensions>\n` +
|
|
95
|
-
` </trkpt>`);
|
|
96
|
-
})
|
|
97
|
-
.join('\n');
|
|
98
|
-
return (`<?xml version="1.0" encoding="UTF-8"?>\n` +
|
|
99
|
-
`<gpx version="1.1" creator="@ingissa/navcore-simulator"\n` +
|
|
100
|
-
` xmlns="http://www.topografix.com/GPX/1/1"\n` +
|
|
101
|
-
` xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n` +
|
|
102
|
-
` xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n` +
|
|
103
|
-
` <metadata>\n` +
|
|
104
|
-
` <name>${session.id}</name>\n` +
|
|
105
|
-
` <time>${session.startedAt}</time>\n` +
|
|
106
|
-
` </metadata>\n` +
|
|
107
|
-
` <trk>\n` +
|
|
108
|
-
` <name>${session.id}</name>\n` +
|
|
109
|
-
` <trkseg>\n` +
|
|
110
|
-
trkpts + '\n' +
|
|
111
|
-
` </trkseg>\n` +
|
|
112
|
-
` </trk>\n` +
|
|
113
|
-
`</gpx>`);
|
|
114
|
-
}
|
|
115
|
-
static _toCsv(session) {
|
|
116
|
-
const header = 'timestamp,lng,lat,bearing,speed,accuracy';
|
|
117
|
-
const rows = session.positions.map((p) => `${p.timestamp},${p.coord[0]},${p.coord[1]},${p.bearing.toFixed(4)},${p.speed.toFixed(4)},${p.accuracy.toFixed(2)}`);
|
|
118
|
-
return [header, ...rows].join('\n');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ScenarioInjector — Registers and fires Scenario objects at geometry indices.
|
|
3
|
-
*
|
|
4
|
-
* Called internally by SimulatorEngine on each tick.
|
|
5
|
-
* Also provides static factory methods for the built-in scenario types.
|
|
6
|
-
*/
|
|
7
|
-
import type { Scenario } from '../core/types';
|
|
8
|
-
export type ScenarioFireCallback = (scenario: Scenario) => void;
|
|
9
|
-
export type ScenarioEndCallback = (scenario: Scenario) => void;
|
|
10
|
-
export declare class ScenarioInjector {
|
|
11
|
-
/** Map from triggerIndex → Scenario */
|
|
12
|
-
private readonly scenarios;
|
|
13
|
-
/** Tracks which scenarios have already fired (by name) to avoid double-fire */
|
|
14
|
-
private readonly fired;
|
|
15
|
-
/** Currently active scenario, if any */
|
|
16
|
-
private _activeScenario;
|
|
17
|
-
private _activeEndTimer;
|
|
18
|
-
private onStart;
|
|
19
|
-
private onEnd;
|
|
20
|
-
constructor(onStart?: ScenarioFireCallback, onEnd?: ScenarioEndCallback);
|
|
21
|
-
register(scenario: Scenario): void;
|
|
22
|
-
remove(name: string): void;
|
|
23
|
-
clear(): void;
|
|
24
|
-
/**
|
|
25
|
-
* Check and fire any scenario whose triggerIndex matches (or was passed) by
|
|
26
|
-
* currentIndex. Called by SimulatorEngine on every tick.
|
|
27
|
-
*
|
|
28
|
-
* Returns the name of the active scenario (if any), for metadata injection.
|
|
29
|
-
*/
|
|
30
|
-
tick(currentIndex: number): string | undefined;
|
|
31
|
-
get activeScenario(): Scenario | null;
|
|
32
|
-
/** Clean up any pending timers */
|
|
33
|
-
destroy(): void;
|
|
34
|
-
/**
|
|
35
|
-
* GPS blackout: no position updates for `durationMs`.
|
|
36
|
-
* Engine handles signal loss; this scenario signals the blackout period.
|
|
37
|
-
*/
|
|
38
|
-
static gpsBlackout(atIndex: number, durationMs: number): Scenario;
|
|
39
|
-
/**
|
|
40
|
-
* Wrong-side road: offset the simulated position by `offsetM` metres
|
|
41
|
-
* perpendicular to the route to stress-test the parallel road resolver.
|
|
42
|
-
*/
|
|
43
|
-
static wrongSideRoad(atIndex: number, offsetM: number): Scenario;
|
|
44
|
-
/** U-turn at the given index — stress-tests U-turn protection. */
|
|
45
|
-
static uTurn(atIndex: number): Scenario;
|
|
46
|
-
/** Speed spike: briefly report spikeKmh instead of the configured speed. */
|
|
47
|
-
static speedSpike(atIndex: number, spikeKmh: number, durationMs?: number): Scenario;
|
|
48
|
-
/**
|
|
49
|
-
* Accuracy drop: GPS accuracy degrades to newAccuracyM for durationMs.
|
|
50
|
-
*/
|
|
51
|
-
static accuracyDrop(atIndex: number, newAccuracyM: number, durationMs: number): Scenario;
|
|
52
|
-
private _fire;
|
|
53
|
-
private _clearActiveTimer;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=ScenarioInjector.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ScenarioInjector.d.ts","sourceRoot":"","sources":["../../src/scenarios/ScenarioInjector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,MAAM,oBAAoB,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;AAChE,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;AAE/D,qBAAa,gBAAgB;IAC3B,uCAAuC;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA+B;IACzD,+EAA+E;IAC/E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,wCAAwC;IACxC,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,eAAe,CAA8C;IAErE,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,KAAK,CAAsB;gBAEvB,OAAO,CAAC,EAAE,oBAAoB,EAAE,KAAK,CAAC,EAAE,mBAAmB;IAOvE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAIlC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAS1B,KAAK,IAAI,IAAI;IASb;;;;;OAKG;IACH,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAa9C,IAAI,cAAc,IAAI,QAAQ,GAAG,IAAI,CAEpC;IAED,kCAAkC;IAClC,OAAO,IAAI,IAAI;IAMf;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,QAAQ;IAUjE;;;OAGG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ;IAShE,kEAAkE;IAClE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ;IASvC,4EAA4E;IAC5E,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,SAAO,GAAG,QAAQ;IAUjF;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,QAAQ;IAYxF,OAAO,CAAC,KAAK;IAiBb,OAAO,CAAC,iBAAiB;CAM1B"}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ScenarioInjector — Registers and fires Scenario objects at geometry indices.
|
|
3
|
-
*
|
|
4
|
-
* Called internally by SimulatorEngine on each tick.
|
|
5
|
-
* Also provides static factory methods for the built-in scenario types.
|
|
6
|
-
*/
|
|
7
|
-
export class ScenarioInjector {
|
|
8
|
-
constructor(onStart, onEnd) {
|
|
9
|
-
/** Map from triggerIndex → Scenario */
|
|
10
|
-
this.scenarios = new Map();
|
|
11
|
-
/** Tracks which scenarios have already fired (by name) to avoid double-fire */
|
|
12
|
-
this.fired = new Set();
|
|
13
|
-
/** Currently active scenario, if any */
|
|
14
|
-
this._activeScenario = null;
|
|
15
|
-
this._activeEndTimer = null;
|
|
16
|
-
this.onStart = onStart ?? (() => undefined);
|
|
17
|
-
this.onEnd = onEnd ?? (() => undefined);
|
|
18
|
-
}
|
|
19
|
-
// ── Registration ────────────────────────────────────────────────────────────
|
|
20
|
-
register(scenario) {
|
|
21
|
-
this.scenarios.set(scenario.triggerIndex, scenario);
|
|
22
|
-
}
|
|
23
|
-
remove(name) {
|
|
24
|
-
for (const [idx, s] of this.scenarios) {
|
|
25
|
-
if (s.name === name) {
|
|
26
|
-
this.scenarios.delete(idx);
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
clear() {
|
|
32
|
-
this.scenarios.clear();
|
|
33
|
-
this.fired.clear();
|
|
34
|
-
this._clearActiveTimer();
|
|
35
|
-
this._activeScenario = null;
|
|
36
|
-
}
|
|
37
|
-
// ── Tick ────────────────────────────────────────────────────────────────────
|
|
38
|
-
/**
|
|
39
|
-
* Check and fire any scenario whose triggerIndex matches (or was passed) by
|
|
40
|
-
* currentIndex. Called by SimulatorEngine on every tick.
|
|
41
|
-
*
|
|
42
|
-
* Returns the name of the active scenario (if any), for metadata injection.
|
|
43
|
-
*/
|
|
44
|
-
tick(currentIndex) {
|
|
45
|
-
const floorIdx = Math.floor(currentIndex);
|
|
46
|
-
for (const [triggerIdx, scenario] of this.scenarios) {
|
|
47
|
-
if (floorIdx >= triggerIdx && !this.fired.has(scenario.name)) {
|
|
48
|
-
this.fired.add(scenario.name);
|
|
49
|
-
this._fire(scenario);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return this._activeScenario?.name;
|
|
53
|
-
}
|
|
54
|
-
get activeScenario() {
|
|
55
|
-
return this._activeScenario;
|
|
56
|
-
}
|
|
57
|
-
/** Clean up any pending timers */
|
|
58
|
-
destroy() {
|
|
59
|
-
this._clearActiveTimer();
|
|
60
|
-
}
|
|
61
|
-
// ── Static factories ────────────────────────────────────────────────────────
|
|
62
|
-
/**
|
|
63
|
-
* GPS blackout: no position updates for `durationMs`.
|
|
64
|
-
* Engine handles signal loss; this scenario signals the blackout period.
|
|
65
|
-
*/
|
|
66
|
-
static gpsBlackout(atIndex, durationMs) {
|
|
67
|
-
return {
|
|
68
|
-
name: `gps-blackout-@${atIndex}`,
|
|
69
|
-
triggerIndex: atIndex,
|
|
70
|
-
type: 'GPS_BLACKOUT',
|
|
71
|
-
durationMs,
|
|
72
|
-
params: { durationMs },
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Wrong-side road: offset the simulated position by `offsetM` metres
|
|
77
|
-
* perpendicular to the route to stress-test the parallel road resolver.
|
|
78
|
-
*/
|
|
79
|
-
static wrongSideRoad(atIndex, offsetM) {
|
|
80
|
-
return {
|
|
81
|
-
name: `wrong-side-@${atIndex}`,
|
|
82
|
-
triggerIndex: atIndex,
|
|
83
|
-
type: 'WRONG_SIDE_ROAD',
|
|
84
|
-
params: { offsetM },
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/** U-turn at the given index — stress-tests U-turn protection. */
|
|
88
|
-
static uTurn(atIndex) {
|
|
89
|
-
return {
|
|
90
|
-
name: `uturn-@${atIndex}`,
|
|
91
|
-
triggerIndex: atIndex,
|
|
92
|
-
type: 'UTURN',
|
|
93
|
-
params: {},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/** Speed spike: briefly report spikeKmh instead of the configured speed. */
|
|
97
|
-
static speedSpike(atIndex, spikeKmh, durationMs = 2000) {
|
|
98
|
-
return {
|
|
99
|
-
name: `speed-spike-@${atIndex}`,
|
|
100
|
-
triggerIndex: atIndex,
|
|
101
|
-
type: 'SPEED_SPIKE',
|
|
102
|
-
durationMs,
|
|
103
|
-
params: { spikeKmh },
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Accuracy drop: GPS accuracy degrades to newAccuracyM for durationMs.
|
|
108
|
-
*/
|
|
109
|
-
static accuracyDrop(atIndex, newAccuracyM, durationMs) {
|
|
110
|
-
return {
|
|
111
|
-
name: `accuracy-drop-@${atIndex}`,
|
|
112
|
-
triggerIndex: atIndex,
|
|
113
|
-
type: 'ACCURACY_DROP',
|
|
114
|
-
durationMs,
|
|
115
|
-
params: { newAccuracyM },
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
// ── Private ─────────────────────────────────────────────────────────────────
|
|
119
|
-
_fire(scenario) {
|
|
120
|
-
this._activeScenario = scenario;
|
|
121
|
-
try {
|
|
122
|
-
this.onStart(scenario);
|
|
123
|
-
}
|
|
124
|
-
catch (_) { /* never throw from callback */ }
|
|
125
|
-
if (scenario.durationMs != null && scenario.durationMs > 0) {
|
|
126
|
-
this._clearActiveTimer();
|
|
127
|
-
this._activeEndTimer = setTimeout(() => {
|
|
128
|
-
this._activeScenario = null;
|
|
129
|
-
try {
|
|
130
|
-
this.onEnd(scenario);
|
|
131
|
-
}
|
|
132
|
-
catch (_) { /* never throw */ }
|
|
133
|
-
}, scenario.durationMs);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
// Instantaneous scenario — end immediately
|
|
137
|
-
this._activeScenario = null;
|
|
138
|
-
try {
|
|
139
|
-
this.onEnd(scenario);
|
|
140
|
-
}
|
|
141
|
-
catch (_) { /* never throw */ }
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
_clearActiveTimer() {
|
|
145
|
-
if (this._activeEndTimer !== null) {
|
|
146
|
-
clearTimeout(this._activeEndTimer);
|
|
147
|
-
this._activeEndTimer = null;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|