mirror of
https://github.com/silenty4ng/k5web
synced 2025-01-06 20:02:38 +00:00
update
This commit is contained in:
parent
05d5bbbf6a
commit
38c134f2c0
3 changed files with 59 additions and 13 deletions
BIN
public/sms_test.bin
Normal file
BIN
public/sms_test.bin
Normal file
Binary file not shown.
|
@ -749,10 +749,14 @@ const FONT_MAPPING_118_MAP = ['啊', '阿', '埃', '挨', '哎', '唉', '哀', '
|
||||||
let globalWriteReader = null
|
let globalWriteReader = null
|
||||||
let globalReadReader = null
|
let globalReadReader = null
|
||||||
|
|
||||||
function globalRelease(){
|
function globalRelease(target = 'all'){
|
||||||
try {
|
try {
|
||||||
if(globalReadReader)globalReadReader.releaseLock()
|
if(target != 'read'){
|
||||||
if(globalWriteReader)globalWriteReader.releaseLock()
|
if(globalWriteReader)globalWriteReader.releaseLock()
|
||||||
|
}
|
||||||
|
if(target != 'write'){
|
||||||
|
if(globalReadReader)globalReadReader.releaseLock()
|
||||||
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -869,7 +873,7 @@ async function readPacket(port, expectedData, timeout = 1000) {
|
||||||
return unpacketize(new Uint8Array(sessionStorage.getItem('webusb').split(',')));
|
return unpacketize(new Uint8Array(sessionStorage.getItem('webusb').split(',')));
|
||||||
}
|
}
|
||||||
// Create a reader to read data from the serial port
|
// Create a reader to read data from the serial port
|
||||||
globalRelease()
|
globalRelease('read')
|
||||||
const reader = port.readable.getReader();
|
const reader = port.readable.getReader();
|
||||||
globalReadReader = reader;
|
globalReadReader = reader;
|
||||||
let buffer = new Uint8Array();
|
let buffer = new Uint8Array();
|
||||||
|
@ -974,7 +978,7 @@ async function readPacket(port, expectedData, timeout = 1000) {
|
||||||
*/
|
*/
|
||||||
async function readPacketNoVerify(port, timeout = 1000) {
|
async function readPacketNoVerify(port, timeout = 1000) {
|
||||||
// Create a reader to read data from the serial port
|
// Create a reader to read data from the serial port
|
||||||
globalRelease()
|
globalRelease('read')
|
||||||
const reader = port.readable.getReader();
|
const reader = port.readable.getReader();
|
||||||
globalReadReader = reader;
|
globalReadReader = reader;
|
||||||
let buffer = new Uint8Array();
|
let buffer = new Uint8Array();
|
||||||
|
@ -1063,7 +1067,7 @@ async function sendPacket(port, data) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// create writer for port
|
// create writer for port
|
||||||
globalRelease()
|
globalRelease('write')
|
||||||
const writer = port.writable.getWriter();
|
const writer = port.writable.getWriter();
|
||||||
globalWriteReader = writer;
|
globalWriteReader = writer;
|
||||||
// prepare packet
|
// prepare packet
|
||||||
|
@ -1514,12 +1518,11 @@ function unpackVersion(encoded_firmware) {
|
||||||
|
|
||||||
async function sendSMSPacket(port, message){
|
async function sendSMSPacket(port, message){
|
||||||
try {
|
try {
|
||||||
globalRelease()
|
globalRelease('write')
|
||||||
const writer = port.writable.getWriter();
|
const writer = port.writable.getWriter();
|
||||||
globalWriteReader = writer;
|
globalWriteReader = writer;
|
||||||
const formattedMessage = `SMS:${message}\r\n`;
|
const formattedMessage = `SMS:${message}\r\n`;
|
||||||
const packet = new TextEncoder().encode(formattedMessage);
|
const packet = new TextEncoder().encode(formattedMessage);
|
||||||
console.log(packet)
|
|
||||||
await writer.write(packet);
|
await writer.write(packet);
|
||||||
writer.releaseLock();
|
writer.releaseLock();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1530,7 +1533,7 @@ async function sendSMSPacket(port, message){
|
||||||
}
|
}
|
||||||
|
|
||||||
function readSMSPacket(port) {
|
function readSMSPacket(port) {
|
||||||
globalRelease()
|
globalRelease('read')
|
||||||
const reader = port.readable.getReader();
|
const reader = port.readable.getReader();
|
||||||
globalReadReader = reader;
|
globalReadReader = reader;
|
||||||
return reader;
|
return reader;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<Breadcrumb :items="[$t('menu.list'), $t('menu.flash')]" />
|
<Breadcrumb :items="[$t('menu.list'), $t('menu.flash')]" />
|
||||||
<a-card class="general-card">
|
<a-card class="general-card">
|
||||||
<template #title>
|
<template #title>
|
||||||
【开发中】无线电聊天(需使用<a-link @click="downloadFirmware">这个</a-link>固件)
|
【无法正常使用】【开发中!!!】无线电聊天(需使用<a-link @click="downloadFirmware">这个</a-link>固件)
|
||||||
</template>
|
</template>
|
||||||
<div style="display: flex; align-items: center; margin: 10px;">
|
<div style="display: flex; align-items: center; margin: 10px;">
|
||||||
<span>呼号:</span>
|
<span>呼号:</span>
|
||||||
|
@ -41,10 +41,12 @@
|
||||||
import { computed, reactive, watch, nextTick, ref, onUnmounted } from 'vue';
|
import { computed, reactive, watch, nextTick, ref, onUnmounted } from 'vue';
|
||||||
import { eeprom_init, sendSMSPacket, readSMSPacket } from '@/utils/serial.js';
|
import { eeprom_init, sendSMSPacket, readSMSPacket } from '@/utils/serial.js';
|
||||||
import { useAppStore } from '@/store';
|
import { useAppStore } from '@/store';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
import { Message, Modal } from '@arco-design/web-vue';
|
import { Message, Modal } from '@arco-design/web-vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
|
|
||||||
const msgList: any = ref(null)
|
const msgList: any = ref(null)
|
||||||
|
@ -90,7 +92,29 @@ const scrollIt = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadFirmware = () => {
|
const downloadFirmware = () => {
|
||||||
Message.error('敬请期待')
|
router.push({
|
||||||
|
path: '/tool/flash',
|
||||||
|
query: {
|
||||||
|
url: "/sms_test.bin"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringToUtf8Hex(str: string) {
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
const utf8Bytes = encoder.encode(str);
|
||||||
|
let hex = '';
|
||||||
|
utf8Bytes.forEach(byte => {
|
||||||
|
hex += byte.toString(16).padStart(2, '0').toUpperCase();
|
||||||
|
});
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hexToUtf8String(hex: string) {
|
||||||
|
// 将十六进制字符串转换为字节数组
|
||||||
|
const bytes = new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
return decoder.decode(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendMsg = async () => {
|
const sendMsg = async () => {
|
||||||
|
@ -99,8 +123,7 @@ const sendMsg = async () => {
|
||||||
Message.error('请输入正确的呼号')
|
Message.error('请输入正确的呼号')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log(state.callsign.trim() + ":" + state.devid + ":" + state.sendInput.trim())
|
sendSMSPacket(appStore.connectPort,"START:" + state.callsign.trim() + ":" + state.devid + ":" + stringToUtf8Hex(state.sendInput.trim()) + ":END")
|
||||||
sendSMSPacket(appStore.connectPort, state.callsign.trim() + ":" + state.devid + ":" + state.sendInput.trim())
|
|
||||||
state.msgList.push({
|
state.msgList.push({
|
||||||
callsign: state.callsign.trim(),
|
callsign: state.callsign.trim(),
|
||||||
devid: state.devid,
|
devid: state.devid,
|
||||||
|
@ -128,6 +151,7 @@ const connectIt = async () => {
|
||||||
const asyncMsg = async (reader: any) => {
|
const asyncMsg = async (reader: any) => {
|
||||||
let buffer = '';
|
let buffer = '';
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
const regex = /START:[A-Z0-9]+:[0-9]+:[A-F0-9]+:END/g;
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
const { value, done } = await reader.read();
|
const { value, done } = await reader.read();
|
||||||
|
@ -138,7 +162,26 @@ const asyncMsg = async (reader: any) => {
|
||||||
message = message.trim();
|
message = message.trim();
|
||||||
buffer += message;
|
buffer += message;
|
||||||
console.log(buffer)
|
console.log(buffer)
|
||||||
|
const matches = buffer.match(regex);
|
||||||
|
if (matches && matches.length > 0) {
|
||||||
|
buffer = ''
|
||||||
|
try {
|
||||||
|
const content = matches[matches.length - 1].split(':');
|
||||||
|
state.msgList.push({
|
||||||
|
callsign: content[1],
|
||||||
|
devid: content[2],
|
||||||
|
content: hexToUtf8String(content[3])
|
||||||
|
})
|
||||||
|
scrollIt()
|
||||||
|
} catch {
|
||||||
|
console.log('ERROR')
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log('已断开')
|
||||||
|
state.connect = false
|
||||||
|
state.reader.releaseLock();
|
||||||
|
state.startChat = '开始聊天'
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue