实现多开并且串口数据处理后传递至渲染端
parent
027efdd745
commit
46ac007a4f
|
@ -13,11 +13,11 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"echarts": "^5.2.2",
|
"echarts": "^5.2.2",
|
||||||
"echarts-china-cities-js": "^0.1.1",
|
|
||||||
"echarts-gl": "^2.0.8",
|
"echarts-gl": "^2.0.8",
|
||||||
"echarts-liquidfill": "^3.1.0",
|
"echarts-liquidfill": "^3.1.0",
|
||||||
"electron-store": "^8.0.1",
|
"electron-store": "^8.0.1",
|
||||||
"serialport": "^9.2.5",
|
"nmea": "git+https://e.coding.net/hwasmart/beidou-satellite-data-monitor/node-nmea.git",
|
||||||
|
"serialport": "9.2.4",
|
||||||
"vue": "^3.0.5",
|
"vue": "^3.0.5",
|
||||||
"vue-echarts": "^6.0.0"
|
"vue-echarts": "^6.0.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
import nmea from 'nmea'
|
||||||
|
|
||||||
|
let events = {}
|
||||||
|
const on = (eventName, callback) => {
|
||||||
|
if (!(eventName in events)) {
|
||||||
|
events[eventName] = []
|
||||||
|
}
|
||||||
|
|
||||||
|
events[eventName].push(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
const emit = (eventName, ...args) => {
|
||||||
|
if (!(eventName in events)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cbs = events[eventName]
|
||||||
|
|
||||||
|
cbs.forEach(cb => {
|
||||||
|
cb.call(this, ...args)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const handle = (value) => {
|
||||||
|
if (value.length <= 0) return
|
||||||
|
|
||||||
|
emit('received', value)
|
||||||
|
|
||||||
|
const strArr = value.split('\r\n')
|
||||||
|
for (let i = 0; i < strArr.length; i++) {
|
||||||
|
const element = strArr[i];
|
||||||
|
doHandle(element)
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('handled', nmeaObj)
|
||||||
|
nmeaObj = resetNMEAObj()
|
||||||
|
}
|
||||||
|
|
||||||
|
const doHandle = (value) => {
|
||||||
|
if (!verify(value)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = nmea.parse(value)
|
||||||
|
switch (result.sentence) {
|
||||||
|
case 'RMC':
|
||||||
|
nmeaObj.RMC = result
|
||||||
|
break;
|
||||||
|
case 'GGA':
|
||||||
|
nmeaObj.GGA = result
|
||||||
|
break;
|
||||||
|
case 'GSA':
|
||||||
|
if (result.talker_id === 'BD') nmeaObj.GSA.push(result)
|
||||||
|
break;
|
||||||
|
case 'GSV':
|
||||||
|
if (result.talker_id === 'BD') nmeaObj.GSV.push(result)
|
||||||
|
break;
|
||||||
|
case 'TXT':
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const verify = (value) => {
|
||||||
|
if (!value) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const dollar_index = value.indexOf('$')
|
||||||
|
const star_index = value.indexOf('*')
|
||||||
|
if (value.indexOf('$') !== 0 || star_index <= dollar_index) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const [sentence, checksum, ] = value.split('*')
|
||||||
|
return nmea.Helpers.verifyChecksum(sentence, checksum)
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetNMEAObj = () => {
|
||||||
|
return {
|
||||||
|
'RMC': null,
|
||||||
|
'GGA': null,
|
||||||
|
'GSA': [],
|
||||||
|
'GSV': []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let nmeaObj = resetNMEAObj()
|
||||||
|
|
||||||
|
module.exports = { on, handle }
|
|
@ -2,36 +2,62 @@ import { app, BrowserWindow } from 'electron'
|
||||||
import {join} from "path";
|
import {join} from "path";
|
||||||
import './load-serialport'
|
import './load-serialport'
|
||||||
|
|
||||||
function createWindow() {
|
|
||||||
const win = new BrowserWindow({
|
|
||||||
width: 800,
|
|
||||||
height: 600,
|
|
||||||
webPreferences: {
|
|
||||||
nodeIntegration: true,
|
|
||||||
preload: join(__dirname, 'preload.js')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
win.loadURL('http://localhost:3000/')
|
function createWindow(page: String) {
|
||||||
win.webContents.openDevTools()
|
|
||||||
} else {
|
const win = new BrowserWindow({
|
||||||
win.loadFile('dist/render/index.html')
|
fullscreen: true,
|
||||||
|
frame: false,
|
||||||
|
webPreferences: {
|
||||||
|
// webSecurity: false,
|
||||||
|
nodeIntegration: true,
|
||||||
|
preload: join(__dirname, 'preload.js')
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
win.loadURL(`http://localhost:3000/${page}.html`)
|
||||||
|
win.webContents.openDevTools()
|
||||||
|
} else {
|
||||||
|
win.loadFile(`dist/render/${page}.html`)
|
||||||
|
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()
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
app.whenReady().then(createWindow)
|
function launch() {
|
||||||
|
|
||||||
|
createWindow('satellite-data-monitor-platform')
|
||||||
|
createWindow('satellite-info-monitor-platform')
|
||||||
|
createWindow('satellite-signal-monitor-platform')
|
||||||
|
createWindow('satellite-state-monitor-platform')
|
||||||
|
|
||||||
|
|
||||||
|
// createWindow('DataMonitorPage')
|
||||||
|
// createWindow('InfoMonitorPage')
|
||||||
|
// createWindow('SignalMonitorPage')
|
||||||
|
// createWindow('StateMonitorPage')
|
||||||
|
}
|
||||||
|
|
||||||
|
app.whenReady().then(launch)
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
createWindow()
|
launch()
|
||||||
}
|
}
|
||||||
})
|
})
|
|
@ -1,8 +1,11 @@
|
||||||
const { ipcMain } = require('electron')
|
const { ipcMain } = require('electron')
|
||||||
const SerialPort = require('serialport')
|
const SerialPort = require('serialport')
|
||||||
const Readline = require('@serialport/parser-readline')
|
// const Readline = require('@serialport/parser-readline')
|
||||||
|
const InterByteTimeout = require('@serialport/parser-inter-byte-timeout')
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
|
|
||||||
|
const NMEAHandler = require('./api/NMEAHandler')
|
||||||
|
|
||||||
const DEFAULT_BAUDRATE = 9600
|
const DEFAULT_BAUDRATE = 9600
|
||||||
const getSerialPortConstructorArguments = (ports) => {
|
const getSerialPortConstructorArguments = (ports) => {
|
||||||
let serialport = config.get('serialport')
|
let serialport = config.get('serialport')
|
||||||
|
@ -26,9 +29,9 @@ SerialPort.list().then((ports, err) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(ports, '=====================')
|
// console.log(ports, '=====================')
|
||||||
|
|
||||||
// 过滤到COM1口,很多电脑自带COM1接口
|
// 过滤掉COM1口,很多电脑自带COM1接口
|
||||||
ports.filter((port) => port.path != 'COM1')
|
ports.filter((port) => port.path != 'COM1')
|
||||||
if (ports.length == 0) {
|
if (ports.length == 0) {
|
||||||
console.error('设备为连接')
|
console.error('设备为连接')
|
||||||
|
@ -38,8 +41,15 @@ SerialPort.list().then((ports, err) => {
|
||||||
try {
|
try {
|
||||||
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' }))
|
|
||||||
parser.on('data', (data) => { sendMsg('NMEA', data) })
|
// const parser = serialPort.pipe(new Readline({ delimiter: '\r\n' }))
|
||||||
|
const parser = serialPort.pipe(new InterByteTimeout({interval: 30}))
|
||||||
|
|
||||||
|
NMEAHandler.on('handled' , (nmeaObj) => {
|
||||||
|
sendMsg('nmea', JSON.stringify(nmeaObj))
|
||||||
|
})
|
||||||
|
|
||||||
|
parser.on('data', (data) => NMEAHandler.handle(data.toString()))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,16 @@ import Clock from '../components/Clock.vue'
|
||||||
import Compass from '../components/Compass.vue'
|
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'
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if ('ipcRenderer' in window) {
|
||||||
|
ipcRenderer.receive('nmea', console.log)
|
||||||
|
|
||||||
|
ipcRenderer.send('APP_MOUNTED')
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
@ -19,4 +19,14 @@ import FullScreenContainer from '../components/Layout/FullScreenContainer.vue'
|
||||||
import TheHeader from '../components/Layout/TheHeader.vue'
|
import TheHeader from '../components/Layout/TheHeader.vue'
|
||||||
import BorderBox3 from '../components/Layout/BorderBox3.vue'
|
import BorderBox3 from '../components/Layout/BorderBox3.vue'
|
||||||
import ScrollBoardTable from '../components/ScrollBoardTable.vue'
|
import ScrollBoardTable from '../components/ScrollBoardTable.vue'
|
||||||
|
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if ('ipcRenderer' in window) {
|
||||||
|
ipcRenderer.receive('nmea', console.log)
|
||||||
|
|
||||||
|
ipcRenderer.send('APP_MOUNTED')
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -23,4 +23,14 @@
|
||||||
import FullScreenContainer from '../components/Layout/FullScreenContainer.vue'
|
import FullScreenContainer from '../components/Layout/FullScreenContainer.vue'
|
||||||
import TheHeader from '../components/Layout/TheHeader.vue'
|
import TheHeader from '../components/Layout/TheHeader.vue'
|
||||||
import SNRView from '../components/SNRView.vue'
|
import SNRView from '../components/SNRView.vue'
|
||||||
|
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if ('ipcRenderer' in window) {
|
||||||
|
ipcRenderer.receive('nmea', console.log)
|
||||||
|
|
||||||
|
ipcRenderer.send('APP_MOUNTED')
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -23,4 +23,14 @@
|
||||||
import FullScreenContainer from '../components/Layout/FullScreenContainer.vue'
|
import FullScreenContainer from '../components/Layout/FullScreenContainer.vue'
|
||||||
import TheHeader from '../components/Layout/TheHeader.vue'
|
import TheHeader from '../components/Layout/TheHeader.vue'
|
||||||
import PlanisphereView from '../components/PlanisphereView.vue'
|
import PlanisphereView from '../components/PlanisphereView.vue'
|
||||||
|
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if ('ipcRenderer' in window) {
|
||||||
|
ipcRenderer.receive('nmea', console.log)
|
||||||
|
|
||||||
|
ipcRenderer.send('APP_MOUNTED')
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -6,6 +6,7 @@ const outDir = join(__dirname, 'dist/render')
|
||||||
const renderDir = join(__dirname, 'src/render')
|
const renderDir = join(__dirname, 'src/render')
|
||||||
const publicDir = join(__dirname, 'public')
|
const publicDir = join(__dirname, 'public')
|
||||||
|
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
publicDir,
|
publicDir,
|
||||||
|
@ -14,6 +15,14 @@ export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
outDir,
|
outDir,
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
|
rollupOptions: {
|
||||||
|
input: [
|
||||||
|
'./satellite-data-monitor-platform.html',
|
||||||
|
'./satellite-info-monitor-platform.html',
|
||||||
|
'./satellite-signal-monitor-platform.html',
|
||||||
|
'./satellite-state-monitor-platform.html'
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|
Loading…
Reference in New Issue