113 lines
3.1 KiB
JavaScript
113 lines
3.1 KiB
JavaScript
import { Helpers } from 'nmea'
|
|
|
|
const getPosition = (nmea) => {
|
|
if (!nmea) return
|
|
|
|
const { RMC } = nmea
|
|
const position = { lng: Helpers.parseLongitude(RMC.lon, RMC.lonPole), lat: Helpers.parseLatitude(RMC.lat, RMC.latPole) }
|
|
|
|
return position
|
|
}
|
|
|
|
const getBaseInfo = (nmea) => {
|
|
if (!nmea) return
|
|
|
|
const { RMC, GGA } = nmea
|
|
try {
|
|
const longitude = (!RMC.lon || !RMC.lonPole) ? '' : Helpers.parseLongitude(RMC.lon, RMC.lonPole)
|
|
const latitude = (!RMC.lat || !RMC.latPole) ? '' : Helpers.parseLatitude(RMC.lat, RMC.latPole)
|
|
const altitude = GGA.alt + GGA.altUnit
|
|
const date = (!RMC.date) ? '' : '20' + RMC.date.slice(4, 6) + '-' + RMC.date.slice(2, 4) + '-' + RMC.date.slice(0, 2)
|
|
let UTCTime = '', BJTime = ''
|
|
if (RMC.timestamp) {
|
|
const hour = parseInt(RMC.timestamp.slice(0, 2))
|
|
const bjHour = (hour + 8) % 24
|
|
UTCTime = hour.toString().padStart(2, '0') + ':' + RMC.timestamp.slice(2, 4) + ':' + RMC.timestamp.slice(4, 6)
|
|
BJTime = bjHour.toString().padStart(2, '0') + ':' + RMC.timestamp.slice(2, 4) + ':' + RMC.timestamp.slice(4, 6)
|
|
}
|
|
|
|
const baseInfo = { longitude, latitude, altitude, date, UTCTime, BJTime }
|
|
return baseInfo
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
const getSNROption = (nmea) => {
|
|
if (!nmea) return
|
|
|
|
const { GSV, GSA } = nmea
|
|
const GSVArr = GSV.filter((gsv) => gsv.talker_id === 'BD')
|
|
const GSAArr = GSA.filter((gsa) => gsa.talker_id === 'BD')
|
|
|
|
try {
|
|
let yAxis_data = [], series_data = []
|
|
const in_positioning_id = get_in_positioning_id(GSAArr)
|
|
|
|
GSVArr.forEach(({ satellites }) => {
|
|
satellites.forEach(({ id, SNRdB }) => {
|
|
yAxis_data.push(id)
|
|
if (in_positioning_id.indexOf(parseInt(id)) < 0) {
|
|
series_data.push([SNRdB, id, false])
|
|
} else {
|
|
series_data.push([SNRdB, id, true])
|
|
}
|
|
});
|
|
});
|
|
|
|
const SNROption = {
|
|
yAxis: {
|
|
data: yAxis_data
|
|
},
|
|
series: [{
|
|
data: series_data
|
|
}]
|
|
}
|
|
|
|
return SNROption
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
const getPlanisphereOption = (nmea) => {
|
|
if (!nmea) return
|
|
|
|
const { GSV, GSA } = nmea
|
|
const GSVArr = GSV.filter((gsv) => gsv.talker_id === 'BD')
|
|
const GSAArr = GSA.filter((gsa) => gsa.talker_id === 'BD')
|
|
|
|
try {
|
|
let data = []
|
|
const in_positioning_id = get_in_positioning_id(GSAArr)
|
|
|
|
GSVArr.forEach(({ satellites }) => {
|
|
satellites.forEach(({ id, elevationDeg, azimuthTrue }) => {
|
|
if (in_positioning_id.indexOf(parseInt(id)) < 0) {
|
|
data.push([parseInt(elevationDeg), azimuthTrue, id, false])
|
|
} else {
|
|
data.push([parseInt(elevationDeg), azimuthTrue, id, true])
|
|
}
|
|
});
|
|
});
|
|
|
|
const planisphereOption = {
|
|
series: [{ data }]
|
|
}
|
|
|
|
return planisphereOption
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
const get_in_positioning_id = (GSAArr) => {
|
|
let in_positioning_id = []
|
|
GSAArr.forEach(({ satellites }) => {
|
|
in_positioning_id.push(...satellites)
|
|
});
|
|
|
|
return in_positioning_id
|
|
}
|
|
|
|
export { getPosition, getBaseInfo, getSNROption, getPlanisphereOption } |