Add live transmitter position (status) alongside logged points
devices/<serial>/log messages now carry a "type": "log" or "status". "log" persists a LocatePoint as before; "status" carries the same position + telemetry shape but is broadcast live over the job's realtime channel without touching locate_points — it's a current- position update, not a recorded point. The job map renders the latest status as a blue "you are here" marker (with a soft accuracy-radius halo) that moves in place as new updates arrive, separate from the colored polyline of logged points. Clicking it shows the same detail readout as a logged point. The simulator gained a message-type toggle (Log point / Status update) so both paths can be exercised from /sim. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
IsArray,
|
IsArray,
|
||||||
IsDateString,
|
IsDateString,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
|
IsIn,
|
||||||
IsInt,
|
IsInt,
|
||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
@@ -139,10 +140,18 @@ export class MqttPointsMessageDto {
|
|||||||
points: MqttPointDto[];
|
points: MqttPointDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single-reading log entry for a locator that publishes directly (or is
|
export const MQTT_LOG_MESSAGE_TYPES = ['log', 'status'] as const;
|
||||||
// relayed) to devices/<serial>/log — the serial comes from the topic itself,
|
export type MqttLogMessageType = (typeof MQTT_LOG_MESSAGE_TYPES)[number];
|
||||||
// so identity is job-anchored rather than publisher-credential-anchored.
|
|
||||||
|
// Single reading for a locator that publishes directly (or is relayed) to
|
||||||
|
// devices/<serial>/log — the serial comes from the topic itself, so identity
|
||||||
|
// is job-anchored rather than publisher-credential-anchored. `type` decides
|
||||||
|
// what happens to it: "log" persists a LocatePoint; "status" is an ephemeral
|
||||||
|
// current-position update, broadcast live but never written to the DB.
|
||||||
export class MqttLogMessageDto extends MqttPointDto {
|
export class MqttLogMessageDto extends MqttPointDto {
|
||||||
|
@IsIn(MQTT_LOG_MESSAGE_TYPES)
|
||||||
|
type: MqttLogMessageType;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
jobId: string;
|
jobId: string;
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ export class LogIngestService {
|
|||||||
// devices/<serial>/log carries the locator's identity in the topic itself
|
// devices/<serial>/log carries the locator's identity in the topic itself
|
||||||
// (no publisher device needs to be pre-registered); the job named in the
|
// (no publisher device needs to be pre-registered); the job named in the
|
||||||
// payload supplies the org, since the topic alone doesn't identify one.
|
// payload supplies the org, since the topic alone doesn't identify one.
|
||||||
|
// `type` decides what happens to the reading: "log" persists a LocatePoint;
|
||||||
|
// "status" is an ephemeral current-position update, broadcast live but
|
||||||
|
// never written to locate_points.
|
||||||
async handle(serial: string, rawPayload: string) {
|
async handle(serial: string, rawPayload: string) {
|
||||||
const msg = plainToInstance(MqttLogMessageDto, JSON.parse(rawPayload) as object);
|
const msg = plainToInstance(MqttLogMessageDto, JSON.parse(rawPayload) as object);
|
||||||
const errors = await validate(msg, { whitelist: true });
|
const errors = await validate(msg, { whitelist: true });
|
||||||
@@ -36,6 +39,35 @@ export class LogIngestService {
|
|||||||
|
|
||||||
const locator = await this.locatorRegistry.resolve(job.orgId, serial);
|
const locator = await this.locatorRegistry.resolve(job.orgId, serial);
|
||||||
|
|
||||||
|
if (msg.type === 'status') {
|
||||||
|
this.realtime.publish(`job:${job.id}`, {
|
||||||
|
type: 'status',
|
||||||
|
jobId: job.id,
|
||||||
|
deviceId: locator.id,
|
||||||
|
serial,
|
||||||
|
lat: msg.lat,
|
||||||
|
lng: msg.lng,
|
||||||
|
altitude: msg.alt ?? null,
|
||||||
|
fixType: msg.fix ?? 'NONE',
|
||||||
|
utilityType: msg.utility ?? 'UNKNOWN',
|
||||||
|
hAccuracy: msg.hAcc ?? null,
|
||||||
|
vAccuracy: msg.vAcc ?? null,
|
||||||
|
satellites: msg.sats ?? null,
|
||||||
|
hdop: msg.hdop ?? null,
|
||||||
|
depth: msg.depth ?? null,
|
||||||
|
frequencyHz: msg.freqHz ?? null,
|
||||||
|
currentMa: msg.currentMa ?? null,
|
||||||
|
signalDb: msg.signalDb ?? null,
|
||||||
|
gainDb: msg.gainDb ?? null,
|
||||||
|
locateMode: msg.mode ?? null,
|
||||||
|
phaseDeg: msg.phaseDeg ?? null,
|
||||||
|
compassDeg: msg.compassDeg ?? null,
|
||||||
|
distortionPct: msg.distortionPct ?? null,
|
||||||
|
recordedAt: msg.ts,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const point = await this.prisma.locatePoint.create({
|
const point = await this.prisma.locatePoint.create({
|
||||||
data: {
|
data: {
|
||||||
jobId: job.id,
|
jobId: job.id,
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
import { IsNotEmpty, IsString, MaxLength } from 'class-validator';
|
import { IsNotEmpty, IsString, MaxLength } from 'class-validator';
|
||||||
import { MqttPointDto } from '../../ingest/dto/mqtt-messages.dto';
|
import { MqttLogMessageDto } from '../../ingest/dto/mqtt-messages.dto';
|
||||||
|
|
||||||
// What the simulator UI sends the backend. Mirrors a devices/<serial>/log
|
// What the simulator UI sends the backend: a devices/<serial>/log payload
|
||||||
// payload plus the two fields that live in the topic/routing rather than the
|
// (type: "log" persists a point, "status" is a live-only position update)
|
||||||
// wire payload itself (serial, jobId) so this DTO doubles as validation for
|
// plus "serial", which lives in the topic rather than the wire payload.
|
||||||
// both the REST call and the outgoing MQTT message.
|
export class SimPublishPointDto extends MqttLogMessageDto {
|
||||||
export class SimPublishPointDto extends MqttPointDto {
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@MaxLength(64)
|
@MaxLength(64)
|
||||||
serial: string;
|
serial: string;
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
jobId: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/// <reference types="google.maps" />
|
/// <reference types="google.maps" />
|
||||||
import { APIProvider, InfoWindow, Map as GoogleMap, useMap } from '@vis.gl/react-google-maps';
|
import { APIProvider, InfoWindow, Map as GoogleMap, useMap } from '@vis.gl/react-google-maps';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { JobMapProps, MapPoint, pointDetailRows, UTILITY_COLORS } from '../types';
|
import { JobMapProps, LiveStatus, liveStatusToMapPoint, MapPoint, pointDetailRows, UTILITY_COLORS } from '../types';
|
||||||
|
|
||||||
const API_KEY = process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY || '';
|
const API_KEY = process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY || '';
|
||||||
|
const LIVE_COLOR = '#1a73e8';
|
||||||
|
|
||||||
const DEFAULT_CENTER = { lat: 39.5, lng: -98.35 }; // continental US
|
const DEFAULT_CENTER = { lat: 39.5, lng: -98.35 }; // continental US
|
||||||
const DEFAULT_ZOOM = 4;
|
const DEFAULT_ZOOM = 4;
|
||||||
@@ -95,6 +96,80 @@ function PointsLayer({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renders the transmitter's current position as a "blue dot" (marker + soft
|
||||||
|
// accuracy halo), updated in place as new status messages arrive.
|
||||||
|
function LiveMarker({ status, onSelect }: { status: LiveStatus | null; onSelect: (point: MapPoint) => void }) {
|
||||||
|
const map = useMap();
|
||||||
|
const markerRef = useRef<google.maps.Marker | null>(null);
|
||||||
|
const haloRef = useRef<google.maps.Circle | null>(null);
|
||||||
|
const statusRef = useRef(status);
|
||||||
|
statusRef.current = status;
|
||||||
|
const onSelectRef = useRef(onSelect);
|
||||||
|
onSelectRef.current = onSelect;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!map) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!status) {
|
||||||
|
markerRef.current?.setMap(null);
|
||||||
|
haloRef.current?.setMap(null);
|
||||||
|
markerRef.current = null;
|
||||||
|
haloRef.current = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const position = { lat: status.lat, lng: status.lng };
|
||||||
|
|
||||||
|
if (!markerRef.current) {
|
||||||
|
markerRef.current = new google.maps.Marker({
|
||||||
|
map,
|
||||||
|
position,
|
||||||
|
zIndex: 999,
|
||||||
|
cursor: 'pointer',
|
||||||
|
icon: {
|
||||||
|
path: google.maps.SymbolPath.CIRCLE,
|
||||||
|
scale: 8,
|
||||||
|
fillColor: LIVE_COLOR,
|
||||||
|
fillOpacity: 1,
|
||||||
|
strokeColor: '#ffffff',
|
||||||
|
strokeWeight: 2,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
markerRef.current.addListener('click', () => {
|
||||||
|
if (statusRef.current) {
|
||||||
|
onSelectRef.current(liveStatusToMapPoint(statusRef.current));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
haloRef.current = new google.maps.Circle({
|
||||||
|
map,
|
||||||
|
center: position,
|
||||||
|
radius: status.hAccuracy ?? 5,
|
||||||
|
fillColor: LIVE_COLOR,
|
||||||
|
fillOpacity: 0.15,
|
||||||
|
strokeColor: LIVE_COLOR,
|
||||||
|
strokeOpacity: 0.3,
|
||||||
|
strokeWeight: 1,
|
||||||
|
clickable: false,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
markerRef.current.setPosition(position);
|
||||||
|
haloRef.current?.setCenter(position);
|
||||||
|
haloRef.current?.setRadius(status.hAccuracy ?? 5);
|
||||||
|
}
|
||||||
|
}, [map, status]);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
markerRef.current?.setMap(null);
|
||||||
|
haloRef.current?.setMap(null);
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function PointDetails({ point, onClose }: { point: MapPoint; onClose: () => void }) {
|
function PointDetails({ point, onClose }: { point: MapPoint; onClose: () => void }) {
|
||||||
return (
|
return (
|
||||||
<InfoWindow position={{ lat: point.lat, lng: point.lng }} onCloseClick={onClose}>
|
<InfoWindow position={{ lat: point.lat, lng: point.lng }} onCloseClick={onClose}>
|
||||||
@@ -114,7 +189,7 @@ function PointDetails({ point, onClose }: { point: MapPoint; onClose: () => void
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GoogleJobMap({ points, fitBounds = true, heightPx = 480 }: JobMapProps) {
|
export default function GoogleJobMap({ points, liveStatus = null, fitBounds = true, heightPx = 480 }: JobMapProps) {
|
||||||
const [selected, setSelected] = useState<MapPoint | null>(null);
|
const [selected, setSelected] = useState<MapPoint | null>(null);
|
||||||
|
|
||||||
if (!API_KEY) {
|
if (!API_KEY) {
|
||||||
@@ -136,8 +211,17 @@ export default function GoogleJobMap({ points, fitBounds = true, heightPx = 480
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A point can be re-fetched (new object identity) between renders; keep the
|
// A point can be re-fetched (new object identity) between renders; keep the
|
||||||
// InfoWindow anchored to the latest copy of the same point by id.
|
// InfoWindow anchored to the latest copy of the same point by id. The live
|
||||||
const selectedCurrent = selected ? (points.find((p) => p.id === selected.id) ?? selected) : null;
|
// marker's "point" is synthesized fresh from liveStatus each time.
|
||||||
|
const selectedCurrent = (() => {
|
||||||
|
if (!selected) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (selected.id.startsWith('live-')) {
|
||||||
|
return liveStatus ? liveStatusToMapPoint(liveStatus) : null;
|
||||||
|
}
|
||||||
|
return points.find((p) => p.id === selected.id) ?? selected;
|
||||||
|
})();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ height: heightPx, borderRadius: 8, overflow: 'hidden' }}>
|
<div style={{ height: heightPx, borderRadius: 8, overflow: 'hidden' }}>
|
||||||
@@ -150,6 +234,7 @@ export default function GoogleJobMap({ points, fitBounds = true, heightPx = 480
|
|||||||
onClick={() => setSelected(null)}
|
onClick={() => setSelected(null)}
|
||||||
>
|
>
|
||||||
<PointsLayer points={points} fitBounds={fitBounds} onSelect={setSelected} />
|
<PointsLayer points={points} fitBounds={fitBounds} onSelect={setSelected} />
|
||||||
|
<LiveMarker status={liveStatus} onSelect={setSelected} />
|
||||||
{selectedCurrent && <PointDetails point={selectedCurrent} onClose={() => setSelected(null)} />}
|
{selectedCurrent && <PointDetails point={selectedCurrent} onClose={() => setSelected(null)} />}
|
||||||
</GoogleMap>
|
</GoogleMap>
|
||||||
</APIProvider>
|
</APIProvider>
|
||||||
|
|||||||
@@ -67,8 +67,41 @@ export function pointDetailRows(p: MapPoint): Array<[string, string]> {
|
|||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A transmitter's current position, pushed live over the job's realtime
|
||||||
|
// channel. Never persisted as a LocatePoint — just the latest "where is it
|
||||||
|
// right now," replaced in place as new status updates arrive.
|
||||||
|
export interface LiveStatus {
|
||||||
|
deviceId: string;
|
||||||
|
serial: string;
|
||||||
|
lat: number;
|
||||||
|
lng: number;
|
||||||
|
altitude: number | null;
|
||||||
|
utilityType: string;
|
||||||
|
fixType: string;
|
||||||
|
hAccuracy: number | null;
|
||||||
|
vAccuracy: number | null;
|
||||||
|
satellites: number | null;
|
||||||
|
hdop: number | null;
|
||||||
|
depth: number | null;
|
||||||
|
frequencyHz: number | null;
|
||||||
|
currentMa: number | null;
|
||||||
|
signalDb: number | null;
|
||||||
|
gainDb: number | null;
|
||||||
|
locateMode: string | null;
|
||||||
|
phaseDeg: number | null;
|
||||||
|
compassDeg: number | null;
|
||||||
|
distortionPct: number | null;
|
||||||
|
recordedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function liveStatusToMapPoint(s: LiveStatus): MapPoint {
|
||||||
|
return { ...s, id: `live-${s.serial}`, sequence: null };
|
||||||
|
}
|
||||||
|
|
||||||
export interface JobMapProps {
|
export interface JobMapProps {
|
||||||
points: MapPoint[];
|
points: MapPoint[];
|
||||||
|
// Live current position of a transmitter, shown as a distinct marker
|
||||||
|
liveStatus?: LiveStatus | null;
|
||||||
// Pan/zoom to fit all points whenever their count changes
|
// Pan/zoom to fit all points whenever their count changes
|
||||||
fitBounds?: boolean;
|
fitBounds?: boolean;
|
||||||
heightPx?: number;
|
heightPx?: number;
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import type { MapPoint } from '../components/map/types';
|
import type { LiveStatus, MapPoint } from '../components/map/types';
|
||||||
|
|
||||||
// Subscribes to live points for a job over the backend WebSocket.
|
// Subscribes to live points + live position status for a job over the
|
||||||
// Reconnects with capped exponential backoff; resubscribes on reconnect.
|
// backend WebSocket. Reconnects with capped exponential backoff; resubscribes
|
||||||
export function useJobStream(jobId: string | null, onPoints: (points: MapPoint[]) => void) {
|
// on reconnect.
|
||||||
const handlerRef = useRef(onPoints);
|
export function useJobStream(
|
||||||
handlerRef.current = onPoints;
|
jobId: string | null,
|
||||||
|
onPoints: (points: MapPoint[]) => void,
|
||||||
|
onStatus?: (status: LiveStatus) => void,
|
||||||
|
) {
|
||||||
|
const pointsRef = useRef(onPoints);
|
||||||
|
pointsRef.current = onPoints;
|
||||||
|
const statusRef = useRef(onStatus);
|
||||||
|
statusRef.current = onStatus;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!jobId) {
|
if (!jobId) {
|
||||||
@@ -29,8 +36,13 @@ export function useJobStream(jobId: string | null, onPoints: (points: MapPoint[]
|
|||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
try {
|
try {
|
||||||
const msg = JSON.parse(event.data);
|
const msg = JSON.parse(event.data);
|
||||||
if (msg.type === 'points' && msg.jobId === jobId) {
|
if (msg.jobId !== jobId) {
|
||||||
handlerRef.current(msg.points);
|
return;
|
||||||
|
}
|
||||||
|
if (msg.type === 'points') {
|
||||||
|
pointsRef.current(msg.points);
|
||||||
|
} else if (msg.type === 'status') {
|
||||||
|
statusRef.current?.(msg as LiveStatus);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore malformed frames
|
// ignore malformed frames
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useRouter } from 'next/router';
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import Layout from '../../components/Layout';
|
import Layout from '../../components/Layout';
|
||||||
import JobMap from '../../components/map/JobMap';
|
import JobMap from '../../components/map/JobMap';
|
||||||
import { pointSummary, type MapPoint } from '../../components/map/types';
|
import { pointSummary, type LiveStatus, type MapPoint } from '../../components/map/types';
|
||||||
import { api } from '../../lib/api';
|
import { api } from '../../lib/api';
|
||||||
import { useRequireAuth } from '../../lib/auth-context';
|
import { useRequireAuth } from '../../lib/auth-context';
|
||||||
import { useJobStream } from '../../lib/use-job-stream';
|
import { useJobStream } from '../../lib/use-job-stream';
|
||||||
@@ -32,6 +32,7 @@ export default function JobDetailPage() {
|
|||||||
const [job, setJob] = useState<JobDetail | null>(null);
|
const [job, setJob] = useState<JobDetail | null>(null);
|
||||||
const [points, setPoints] = useState<MapPoint[]>([]);
|
const [points, setPoints] = useState<MapPoint[]>([]);
|
||||||
const [live, setLive] = useState(0);
|
const [live, setLive] = useState(0);
|
||||||
|
const [liveStatus, setLiveStatus] = useState<LiveStatus | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -57,7 +58,9 @@ export default function JobDetailPage() {
|
|||||||
setLive((n) => n + incoming.length);
|
setLive((n) => n + incoming.length);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useJobStream(jobId, onLivePoints);
|
const onStatus = useCallback((status: LiveStatus) => setLiveStatus(status), []);
|
||||||
|
|
||||||
|
useJobStream(jobId, onLivePoints, onStatus);
|
||||||
|
|
||||||
const updateStatus = async (status: string) => {
|
const updateStatus = async (status: string) => {
|
||||||
if (!orgId || !jobId) {
|
if (!orgId || !jobId) {
|
||||||
@@ -108,9 +111,14 @@ export default function JobDetailPage() {
|
|||||||
{points.length > 0 && (
|
{points.length > 0 && (
|
||||||
<span style={{ color: '#777' }}>latest: {pointSummary(points[points.length - 1])}</span>
|
<span style={{ color: '#777' }}>latest: {pointSummary(points[points.length - 1])}</span>
|
||||||
)}
|
)}
|
||||||
|
{liveStatus && (
|
||||||
|
<span style={{ color: '#1a73e8' }}>
|
||||||
|
● transmitter {liveStatus.serial} live ({new Date(liveStatus.recordedAt).toLocaleTimeString()})
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<JobMap points={points} heightPx={520} />
|
<JobMap points={points} liveStatus={liveStatus} heightPx={520} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|||||||
@@ -14,11 +14,14 @@ interface JobOption {
|
|||||||
interface SentEntry {
|
interface SentEntry {
|
||||||
at: string;
|
at: string;
|
||||||
seq: number;
|
seq: number;
|
||||||
|
type: MessageType;
|
||||||
lat: number;
|
lat: number;
|
||||||
lng: number;
|
lng: number;
|
||||||
depth: number;
|
depth: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MessageType = 'log' | 'status';
|
||||||
|
|
||||||
const UTILITIES = ['GAS', 'WATER', 'ELECTRIC', 'SEWER', 'TELECOM', 'CATV', 'FIBER', 'STEAM', 'UNKNOWN'];
|
const UTILITIES = ['GAS', 'WATER', 'ELECTRIC', 'SEWER', 'TELECOM', 'CATV', 'FIBER', 'STEAM', 'UNKNOWN'];
|
||||||
const FIX_TYPES = ['FIXED_RTK', 'FLOAT_RTK', 'DGPS', 'AUTONOMOUS', 'NONE'];
|
const FIX_TYPES = ['FIXED_RTK', 'FLOAT_RTK', 'DGPS', 'AUTONOMOUS', 'NONE'];
|
||||||
const LOCATE_MODES = ['PEAK', 'NULL', 'BROAD_PEAK', 'SONDE'];
|
const LOCATE_MODES = ['PEAK', 'NULL', 'BROAD_PEAK', 'SONDE'];
|
||||||
@@ -47,6 +50,7 @@ export default function SimulatorPage() {
|
|||||||
const [newTicket, setNewTicket] = useState('');
|
const [newTicket, setNewTicket] = useState('');
|
||||||
const [newTitle, setNewTitle] = useState('');
|
const [newTitle, setNewTitle] = useState('');
|
||||||
|
|
||||||
|
const [messageType, setMessageType] = useState<MessageType>('log');
|
||||||
const [serial, setSerial] = useState('');
|
const [serial, setSerial] = useState('');
|
||||||
const [utility, setUtility] = useState('GAS');
|
const [utility, setUtility] = useState('GAS');
|
||||||
const [fixType, setFixType] = useState('FIXED_RTK');
|
const [fixType, setFixType] = useState('FIXED_RTK');
|
||||||
@@ -131,6 +135,7 @@ export default function SimulatorPage() {
|
|||||||
const pointDepth = Math.max(0.1, jitter(depth, 0.15));
|
const pointDepth = Math.max(0.1, jitter(depth, 0.15));
|
||||||
try {
|
try {
|
||||||
await api.post(`/api/orgs/${orgId}/sim/publish`, {
|
await api.post(`/api/orgs/${orgId}/sim/publish`, {
|
||||||
|
type: messageType,
|
||||||
serial,
|
serial,
|
||||||
jobId,
|
jobId,
|
||||||
lat: pos.lat,
|
lat: pos.lat,
|
||||||
@@ -153,7 +158,12 @@ export default function SimulatorPage() {
|
|||||||
ts: new Date().toISOString(),
|
ts: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
setCount(seq);
|
setCount(seq);
|
||||||
setSent((prev) => [{ at: new Date().toLocaleTimeString(), seq, lat: pos.lat, lng: pos.lng, depth: pointDepth }, ...prev].slice(0, 25));
|
setSent((prev) =>
|
||||||
|
[
|
||||||
|
{ at: new Date().toLocaleTimeString(), seq, type: messageType, lat: pos.lat, lng: pos.lng, depth: pointDepth },
|
||||||
|
...prev,
|
||||||
|
].slice(0, 25),
|
||||||
|
);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
@@ -210,6 +220,18 @@ export default function SimulatorPage() {
|
|||||||
</p>
|
</p>
|
||||||
{error && <p style={{ color: '#c62828' }}>{error}</p>}
|
{error && <p style={{ color: '#c62828' }}>{error}</p>}
|
||||||
|
|
||||||
|
<fieldset style={{ marginBottom: '1rem', border: '1px solid #ddd', borderRadius: 8, padding: '1rem' }}>
|
||||||
|
<legend>Message type</legend>
|
||||||
|
<label style={{ marginRight: '1.5rem' }}>
|
||||||
|
<input type="radio" checked={messageType === 'log'} onChange={() => setMessageType('log')} /> Log point{' '}
|
||||||
|
<span style={{ color: '#888' }}>— persisted, appears on the utility line</span>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" checked={messageType === 'status'} onChange={() => setMessageType('status')} /> Status
|
||||||
|
update <span style={{ color: '#888' }}>— live position only, not saved</span>
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<fieldset style={{ marginBottom: '1rem', border: '1px solid #ddd', borderRadius: 8, padding: '1rem' }}>
|
<fieldset style={{ marginBottom: '1rem', border: '1px solid #ddd', borderRadius: 8, padding: '1rem' }}>
|
||||||
<legend>Job</legend>
|
<legend>Job</legend>
|
||||||
{!creatingJob ? (
|
{!creatingJob ? (
|
||||||
@@ -371,10 +393,10 @@ export default function SimulatorPage() {
|
|||||||
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem', marginBottom: '1rem' }}>
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem', marginBottom: '1rem' }}>
|
||||||
<button onClick={sendPoint} disabled={!jobId || autoSending} style={{ padding: '0.6rem 1rem' }}>
|
<button onClick={sendPoint} disabled={!jobId || autoSending} style={{ padding: '0.6rem 1rem' }}>
|
||||||
Send point
|
Send {messageType === 'log' ? 'log point' : 'status update'}
|
||||||
</button>
|
</button>
|
||||||
<button onClick={toggleAutoSend} disabled={!jobId} style={{ padding: '0.6rem 1rem' }}>
|
<button onClick={toggleAutoSend} disabled={!jobId} style={{ padding: '0.6rem 1rem' }}>
|
||||||
{autoSending ? 'Stop auto-send' : 'Start auto-send'}
|
{autoSending ? 'Stop auto-send' : `Start auto-send (${messageType})`}
|
||||||
</button>
|
</button>
|
||||||
<label>
|
<label>
|
||||||
every{' '}
|
every{' '}
|
||||||
@@ -398,6 +420,7 @@ export default function SimulatorPage() {
|
|||||||
<tr style={{ textAlign: 'left', borderBottom: '2px solid #ddd' }}>
|
<tr style={{ textAlign: 'left', borderBottom: '2px solid #ddd' }}>
|
||||||
<th style={{ padding: '0.4rem' }}>Time</th>
|
<th style={{ padding: '0.4rem' }}>Time</th>
|
||||||
<th>Seq</th>
|
<th>Seq</th>
|
||||||
|
<th>Type</th>
|
||||||
<th>Lat</th>
|
<th>Lat</th>
|
||||||
<th>Lng</th>
|
<th>Lng</th>
|
||||||
<th>Depth</th>
|
<th>Depth</th>
|
||||||
@@ -408,6 +431,7 @@ export default function SimulatorPage() {
|
|||||||
<tr key={s.seq} style={{ borderBottom: '1px solid #eee' }}>
|
<tr key={s.seq} style={{ borderBottom: '1px solid #eee' }}>
|
||||||
<td style={{ padding: '0.4rem' }}>{s.at}</td>
|
<td style={{ padding: '0.4rem' }}>{s.at}</td>
|
||||||
<td>{s.seq}</td>
|
<td>{s.seq}</td>
|
||||||
|
<td style={{ color: s.type === 'log' ? '#333' : '#1a73e8' }}>{s.type}</td>
|
||||||
<td>{s.lat.toFixed(7)}</td>
|
<td>{s.lat.toFixed(7)}</td>
|
||||||
<td>{s.lng.toFixed(7)}</td>
|
<td>{s.lng.toFixed(7)}</td>
|
||||||
<td>{s.depth} m</td>
|
<td>{s.depth} m</td>
|
||||||
@@ -415,7 +439,7 @@ export default function SimulatorPage() {
|
|||||||
))}
|
))}
|
||||||
{sent.length === 0 && (
|
{sent.length === 0 && (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={5} style={{ padding: '1.5rem', textAlign: 'center', color: '#888' }}>
|
<td colSpan={6} style={{ padding: '1.5rem', textAlign: 'center', color: '#888' }}>
|
||||||
No points sent yet.
|
No points sent yet.
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user