Files

66 lines
1.7 KiB
Vue
Raw Normal View History

2023-10-13 16:43:53 +08:00
<template>
<n-card title="卫星时间" class="h-full">
<n-space vertical justify="space-around" class="h-full">
<n-descriptions label-placement="left">
<n-descriptions-item label="  日   期  ">
{{ date }}
</n-descriptions-item>
</n-descriptions>
<n-descriptions label-placement="left">
<n-descriptions-item label="  时   间  ">
{{ time }}
</n-descriptions-item>
</n-descriptions>
</n-space>
</n-card>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
2023-11-29 16:08:12 +08:00
import { NCard, NSpace, NDescriptions, NDescriptionsItem, useMessage } from 'naive-ui'
2023-10-13 16:43:53 +08:00
import { LineBreakParser } from '@/utils/parser'
const date = ref()
const time = ref()
const handle = (data: string) => {
const startMarkIndex = data.indexOf('@')
const checksumMarkIndex = data.indexOf('*')
if (startMarkIndex < 0 || checksumMarkIndex < startMarkIndex) return
// 校验和验证
const info = data.substring(startMarkIndex + 1, checksumMarkIndex)
const cs = parseInt(data.substring(checksumMarkIndex + 1))
if (cs != info.length + 2) return
const infoArr = info.split(',')
if (infoArr.length != 3 || infoArr[0] != 'TIME') return
date.value = infoArr[1]
time.value = infoArr[2]
}
const decoder = new TextDecoder()
const parser = new LineBreakParser()
2023-11-29 16:08:12 +08:00
const onSerialPortData = (value: Uint8Array) => {
const lineArr = parser.parse(decoder.decode(value))
2023-10-13 16:43:53 +08:00
lineArr.forEach(line => handle(line))
}
2023-11-29 16:08:12 +08:00
window.ipcRenderer.send('COM_ON')
window.ipcRenderer.receive('COM_LISTENER',onSerialPortData)
2023-10-13 16:43:53 +08:00
</script>
<style scoped lang="less">
:deep(.n-card-header) {
font-size: 4vh;
}
:deep(.n-descriptions) {
font-size: 3vh;
}
</style>