实现基本信息的变更

master
yezhichao 2021-11-23 01:17:36 +08:00
parent 46ac007a4f
commit 59521a7501
9 changed files with 99 additions and 53 deletions

View File

@ -2,15 +2,11 @@ import { app, BrowserWindow } from 'electron'
import {join} from "path"; import {join} from "path";
import './load-serialport' import './load-serialport'
function createWindow(page: String) { function createWindow(page: String) {
const win = new BrowserWindow({ const win = new BrowserWindow({
fullscreen: true, fullscreen: true,
frame: false, frame: false,
webPreferences: { webPreferences: {
// webSecurity: false,
nodeIntegration: true, nodeIntegration: true,
preload: join(__dirname, 'preload.js') preload: join(__dirname, 'preload.js')
} }
@ -23,29 +19,13 @@ function createWindow(page: String) {
win.loadFile(`dist/render/${page}.html`) win.loadFile(`dist/render/${page}.html`)
win.webContents.openDevTools() win.webContents.openDevTools()
} }
// if (process.env.NODE_ENV === 'development') {
// win.loadURL(`http://localhost:3000/?page=${page}`)
// win.webContents.openDevTools()
// } else {
// win.loadFile(`dist/render/index.html?page=${page}`)
// // win.loadURL(`file://${__dirname}/dist/render/index.html?page=${page}`);
// win.webContents.openDevTools()
// }
} }
function launch() { function launch() {
createWindow('satellite-data-monitor-platform') createWindow('satellite-data-monitor-platform')
createWindow('satellite-info-monitor-platform') // createWindow('satellite-info-monitor-platform')
createWindow('satellite-signal-monitor-platform') // createWindow('satellite-signal-monitor-platform')
createWindow('satellite-state-monitor-platform') // createWindow('satellite-state-monitor-platform')
// createWindow('DataMonitorPage')
// createWindow('InfoMonitorPage')
// createWindow('SignalMonitorPage')
// createWindow('StateMonitorPage')
} }
app.whenReady().then(launch) app.whenReady().then(launch)

View File

@ -1,6 +1,5 @@
const { ipcMain } = require('electron') const { ipcMain } = require('electron')
const SerialPort = require('serialport') const SerialPort = require('serialport')
// const Readline = require('@serialport/parser-readline')
const InterByteTimeout = require('@serialport/parser-inter-byte-timeout') const InterByteTimeout = require('@serialport/parser-inter-byte-timeout')
const config = require('./config') const config = require('./config')
@ -42,7 +41,6 @@ SerialPort.list().then((ports, err) => {
const { path, baudRate } = getSerialPortConstructorArguments(ports) const { path, baudRate } = getSerialPortConstructorArguments(ports)
const serialPort = new SerialPort(path, { baudRate }) const serialPort = new SerialPort(path, { baudRate })
// const parser = serialPort.pipe(new Readline({ delimiter: '\r\n' }))
const parser = serialPort.pipe(new InterByteTimeout({interval: 30})) const parser = serialPort.pipe(new InterByteTimeout({interval: 30}))
NMEAHandler.on('handled' , (nmeaObj) => { NMEAHandler.on('handled' , (nmeaObj) => {

View File

@ -34,3 +34,9 @@ export function get_in_positioning_id(GSAArr) {
return in_positioning_id return in_positioning_id
} }
export function getNMEAObj(nmeaStr) {
if (!nmeaStr) return
return JSON.parse(nmeaStr)
}

View File

@ -128,7 +128,7 @@ const option = ref({
] ]
}); });
const update = () => console.log const update = console.log
defineExpose({ update }) defineExpose({ update })
</script> </script>

View File

@ -76,7 +76,7 @@ const option = ref({
] ]
}); });
const update = () => console.log const update = console.log
defineExpose({ update }) defineExpose({ update })
</script> </script>

View File

@ -1,14 +1,12 @@
<template> <template>
<div class="digital-flop text-3xl font-bold" :style="style"> <div v-if="value" class="digital-flop text-3xl font-bold" :style="style">
{{ value }} {{ value }}
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import Vue from 'vue'
const props = defineProps({ const props = defineProps({
value: Number, value: Number || String,
style: String style: String
}) })
</script> </script>

View File

@ -2,13 +2,14 @@
<div class="digital-flop-container h-1/6 relative flex flex-shrink-0 justify-between items-center"> <div class="digital-flop-container h-1/6 relative flex flex-shrink-0 justify-between items-center">
<div class="digital-flop-item w-1/6 h-4/5 flex flex-col justify-center items-center" <div class="digital-flop-item w-1/6 h-4/5 flex flex-col justify-center items-center"
v-for="item in digitalFlopData" v-for="item in digitalFlopData"
:key="item.title" :key="item.key"
> >
<div class="digital-flop-title text-2xl mb-5">{{ item.title }}</div> <div class="digital-flop-title text-2xl mb-5">{{ item.title }}</div>
<div class="digital-flop flex"> <div class="digital-flop flex">
<DigitalFlop <DigitalFlop
:value="item.value" :value="item.value"
:style="item.style" :style="item.style"
:ref="item.key + 'Digital'"
/> />
<div class="unit ml-2.5 leading-10">{{ item.unit }}</div> <div class="unit ml-2.5 leading-10">{{ item.unit }}</div>
</div> </div>
@ -23,38 +24,56 @@ import DigitalFlop from './DigitalFlop.vue'
const digitalFlopData = reactive([ const digitalFlopData = reactive([
{ {
title: '日  期', title: '日  期',
value: 28, value: '',
style: 'color: #4d99fc', style: 'color: #4d99fc',
unit : '' unit : ''
}, { }, {
title: '时  间', title: '时  间',
value: 28, value: '',
style: 'color: #f46827', style: 'color: #f46827',
unit : '' unit : ''
}, { }, {
title: '经  度', title: '经  度',
value: 28, value: '',
style: 'color: #40faee', style: 'color: #40faee',
unit : '' unit : ''
}, { }, {
title: '纬  度', title: '纬  度',
value: 28, value: '',
style: 'color: #4d99fc', style: 'color: #4d99fc',
unit : '' unit : ''
}, { }, {
title: '海  拔', title: '海  拔',
value: 28, value: null,
style: 'color: #f46827', style: 'color: #f46827',
unit : '' unit : ''
}, { }, {
title: '定位卫星数目', title: '定位卫星数目',
value: 28, value: 0,
style: 'color: #40faee', style: 'color: #40faee',
unit : '' unit : ''
} }
]) ])
const update = console.log const update = (
dateTime: Date,
longitude: Number,
latitude: Number,
alt: number,
numSat: number) => {
//
digitalFlopData[0].value = dateTime.toLocaleDateString()
//
digitalFlopData[1].value = dateTime.toLocaleTimeString()
//
digitalFlopData[2].value = `${longitude} ${longitude >= 0 ? 'E' : 'W'}`
//
digitalFlopData[3].value = `${latitude} ${latitude >= 0 ? 'N' : 'S'}`
//
digitalFlopData[4].value = `${alt}`
//
digitalFlopData[5].value = numSat
}
defineExpose({ update }) defineExpose({ update })
</script> </script>

View File

@ -30,7 +30,7 @@ const option = reactive({
} }
}); });
const update = () => console.log const update = console.log
defineExpose({ update }) defineExpose({ update })
</script> </script>

View File

@ -3,22 +3,22 @@
<TheHeader title="卫星数据监控平台" /> <TheHeader title="卫星数据监控平台" />
<div class="main-content flex flex-1 flex-col"> <div class="main-content flex flex-1 flex-col">
<DigitalFlopContainer /> <DigitalFlopContainer ref="digitalFlopContainer" />
<div class="block-left-right-content flex flex-1 mt-5"> <div class="block-left-right-content flex flex-1 mt-5">
<div class="block-left-content w-1/5 flex flex-col"> <div class="block-left-content w-1/5 flex flex-col">
<div class="clock-content mb-2 flex-1"> <div class="clock-content mb-2 flex-1">
<Clock /> <Clock ref="clock" />
</div> </div>
<div class="compass-content mb-2 flex-1"> <div class="compass-content mb-2 flex-1">
<Compass /> <Compass ref="compass" />
</div> </div>
<div class="water-level-content flex-1"> <div class="water-level-content flex-1">
<WaterLevel /> <WaterLevel ref="waterLevel" />
</div> </div>
</div> </div>
<div class="block-right-content ml-2 flex flex-1"> <div class="block-right-content ml-2 flex flex-1">
<Map /> <Map ref="map" />
</div> </div>
</div> </div>
</div> </div>
@ -34,15 +34,60 @@ import Compass from '../components/Compass.vue'
import WaterLevel from '../components/WaterLevel.vue' import WaterLevel from '../components/WaterLevel.vue'
import Map from '../components/Map.vue' import Map from '../components/Map.vue'
import { onMounted } from 'vue' import { ref, onMounted } from 'vue'
import { Helpers } from 'nmea'
import { getNMEAObj } from '../api/util'
const digitalFlopContainer = ref(null)
const clock = ref(null)
const compass = ref(null)
const waterLevel = ref(null)
const map = ref(null)
const update = (nmeaStr: string) => {
const data: any = getMonitoringData(nmeaStr)
if (!data) return
const { dateTime, longitude, latitude, alt, variation, variationPole, numSat } = data
digitalFlopContainer.value.update(dateTime, longitude, latitude, alt, numSat)
// clock.value.update(dateTime)
// compass.value.update(variation, variationPole)
// waterLevel.value.update(alt)
// map.value.update(lon, lonPole, lat, latPole)
}
onMounted(() => { onMounted(() => {
if ('ipcRenderer' in window) { if ('ipcRenderer' in window) {
ipcRenderer.receive('nmea', console.log) ipcRenderer.receive('nmea', update)
ipcRenderer.send('APP_MOUNTED') ipcRenderer.send('APP_MOUNTED')
} }
}) })
const getMonitoringData = (nmeaStr: string) => {
const nmeaObj: any = getNMEAObj(nmeaStr)
console.log(nmeaObj, '================')
if (!nmeaObj || !nmeaObj.RMC || !nmeaObj.GGA) return null
const { RMC, GGA } = nmeaObj
//
const { date, timestamp, variation, variationPole } = RMC
//
const { lon, lonPole, lat, latPole, alt, numSat } = GGA
const year = date.substring(4)
const month = date.substring(2, 4)
const day = date.substring(0, 2)
const hours = timestamp.substring(0, 2)
const minutes = timestamp.substring(2, 4)
const seconds = timestamp.substring(4, 6)
const dateTimeStr = `20${year}-${month}-${day}T${hours}:${minutes}:${seconds}+00:00`
const dateTime = new Date(dateTimeStr)
const longitude = Helpers.parseLongitude(lon, lonPole)
const latitude = Helpers.parseLatitude(lat, latPole)
return { dateTime, longitude, latitude, alt, variation, variationPole, numSat }
}
</script> </script>
<style scoped> <style scoped>