AIS, ADSB, and Range
This commit is contained in:
@@ -1,14 +1,57 @@
|
||||
import {cfg} from './config.mjs';
|
||||
|
||||
const CHANNEL_MAP = {0: 'A, B', 1: 'A', 2: 'B'};
|
||||
const SENDER_TYPE = {
|
||||
0: 'Unknown',
|
||||
1: 'Base Station',
|
||||
2: 'Class A',
|
||||
3: 'Class B',
|
||||
4: 'SAR Aircraft',
|
||||
5: 'Aid to Navigation',
|
||||
6: 'Class B CS',
|
||||
7: 'Sart/Epirb/MOB'
|
||||
};
|
||||
|
||||
function decodeMsgTypes(status_raw) {
|
||||
const types = [];
|
||||
for (let i = 0; i < 32; i++) {
|
||||
if (status_raw & (1 << i)) types.push(i); // was i + 1
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
export async function getAIS() {
|
||||
const {ADSB_URL} = cfg();
|
||||
if(!ADSB_URL) return {data: []};
|
||||
const r = await fetch(`${ADSB_URL}:9990/api/ships_array.json`);
|
||||
const j = await r.json();
|
||||
|
||||
const {keys, values} = j;
|
||||
const {values} = j;
|
||||
const boats = values.map(row => {
|
||||
const obj = {type: 'vessel'};
|
||||
keys.forEach((key, i) => obj[key] = row[i]);
|
||||
return obj;
|
||||
const [
|
||||
mmsi, lat, lon, distance, bearing, rssi, count, drift,
|
||||
unknown_bool, speed, heading, course, altitude,
|
||||
destination, eta, dimension, receiver, sources, channels,
|
||||
msg_type, msg_type2, status_raw, country,
|
||||
ship_type, callsign, imo, draught,
|
||||
unknown1, unknown2, unknown3,
|
||||
name, name2, name3,
|
||||
last_signal, count2, sender_type, channels2, unknown4, in_range
|
||||
] = row;
|
||||
|
||||
return {
|
||||
mmsi, type: SENDER_TYPE[sender_type],
|
||||
lat, lon, altitude,
|
||||
heading, drift, speed,
|
||||
distance, bearing, course,
|
||||
destination, eta,
|
||||
rssi, count, receiver, sources,
|
||||
msg_type: decodeMsgTypes(status_raw),
|
||||
channels: CHANNEL_MAP[channels] ?? channels,
|
||||
ship_type, imo, draught,
|
||||
country, callsign, name: name || name2 || name3,
|
||||
last_signal, in_range
|
||||
};
|
||||
});
|
||||
|
||||
return boats;
|
||||
|
||||
Reference in New Issue
Block a user