feat(uart): change hardcoded uart num to use the first instances num as uart num

This commit is contained in:
kerms 2024-05-25 14:42:57 +08:00
parent f0f11c0646
commit fb833e6af7
6 changed files with 83 additions and 27 deletions

View File

@ -1,6 +1,31 @@
import {type ApiJsonMsg} from '@/api' import {type ApiJsonMsg} from '@/api'
import * as api from "@/api/index"; import * as api from "@/api/index";
export enum WtDataFlowType {
NONE = 0,
SOCKET = 0x10,
WS_SERVER = 0x11,
WS_CLIENT,
WSS_SERVER,
WSS_CLIENT,
TCP_SERVER,
TCP_CLIENT,
TCP_TLS_SERVER,
TCP_TLS_CLIENT,
UDP_SERVER,
UDP_CLIENT,
PERIPHERAL = 0x80,
GPIO = 0x81,
UART = 0x82,
I2C,
I3C,
SPI,
I2S,
CAN,
RMT,
USB,
}
export enum WtDataFlowCmd { export enum WtDataFlowCmd {
UNKNOWN = 0, UNKNOWN = 0,
GET_INS_LIST = 1, GET_INS_LIST = 1,
@ -20,6 +45,25 @@ export interface IWtDataFlowJsonMsg extends ApiJsonMsg {
ins_idx?: number, ins_idx?: number,
} }
export interface IPeriphInfo {
periph_num: number;
}
export interface ISocketInfo {
foreign_port: number;
foreign_ip: string;
local_port: number;
}
export interface IInstanceList extends ApiJsonMsg {
instances: {
ins_idx: number,
mod_idx: number,
mod_type: number,
port_info: ISocketInfo | IPeriphInfo;
}[],
}
export function wt_data_flow_get_instance_list() { export function wt_data_flow_get_instance_list() {
const jsonMsg: IWtDataFlowJsonMsg = { const jsonMsg: IWtDataFlowJsonMsg = {
cmd: WtDataFlowCmd.GET_INS_LIST, cmd: WtDataFlowCmd.GET_INS_LIST,

View File

@ -44,7 +44,7 @@ export interface IUartMsgBaud extends ApiJsonMsg {
baud: number; baud: number;
} }
export function uart_send_msg(payload: Uint8Array, sub_mod: number = 1) { export function uart_send_msg(payload: Uint8Array, sub_mod: number) {
/* hard code uart num for now */ /* hard code uart num for now */
const msg: ApiBinaryMsg = { const msg: ApiBinaryMsg = {
sub_mod: sub_mod, sub_mod: sub_mod,
@ -55,7 +55,7 @@ export function uart_send_msg(payload: Uint8Array, sub_mod: number = 1) {
sendBinMsg(msg); sendBinMsg(msg);
} }
export function uart_get_baud(uart_num: number = 1) { export function uart_get_baud(uart_num: number) {
const cmd = { const cmd = {
cmd: WtUartCmd.GET_BAUD, cmd: WtUartCmd.GET_BAUD,
module: WtModuleID.UART, module: WtModuleID.UART,
@ -64,7 +64,7 @@ export function uart_get_baud(uart_num: number = 1) {
sendJsonMsg(cmd); sendJsonMsg(cmd);
} }
export function uart_set_baud(baud: number, uart_num: number = 1) { export function uart_set_baud(baud: number, uart_num: number) {
const cmd: IUartMsgBaud = { const cmd: IUartMsgBaud = {
cmd: WtUartCmd.SET_BAUD, cmd: WtUartCmd.SET_BAUD,
module: WtModuleID.UART, module: WtModuleID.UART,
@ -74,7 +74,7 @@ export function uart_set_baud(baud: number, uart_num: number = 1) {
sendJsonMsg(cmd); sendJsonMsg(cmd);
} }
export function uart_get_config(uart_num: number = 1) { export function uart_get_config(uart_num: number) {
const cmd = { const cmd = {
cmd: WtUartCmd.GET_CONFIG, cmd: WtUartCmd.GET_CONFIG,
module: WtModuleID.UART, module: WtModuleID.UART,
@ -83,7 +83,7 @@ export function uart_get_config(uart_num: number = 1) {
sendJsonMsg(cmd); sendJsonMsg(cmd);
} }
export function uart_set_config(uart_config: IUartConfig, uart_num: number = 1) { export function uart_set_config(uart_config: IUartConfig, uart_num: number) {
const cmd: IUartMsgConfig = { const cmd: IUartMsgConfig = {
cmd: WtUartCmd.SET_CONFIG, cmd: WtUartCmd.SET_CONFIG,
module: WtModuleID.UART, module: WtModuleID.UART,

View File

@ -11,6 +11,7 @@ import {AnsiUp} from 'ansi_up'
import {debouncedWatch} from "@vueuse/core"; import {debouncedWatch} from "@vueuse/core";
import {type IUartConfig, uart_send_msg} from "@/api/apiUart"; import {type IUartConfig, uart_send_msg} from "@/api/apiUart";
import {isDevMode} from "@/composables/buildMode"; import {isDevMode} from "@/composables/buildMode";
import {useUartStore} from "@/stores/useUartStore";
interface IDataArchive { interface IDataArchive {
time: number; time: number;
@ -180,6 +181,8 @@ function generateBaudArr(results: { baud: number; }[]) {
} }
export const useDataViewerStore = defineStore('text-viewer', () => { export const useDataViewerStore = defineStore('text-viewer', () => {
const uartStore = useUartStore()
/* private value */ /* private value */
const predefineColors = [ const predefineColors = [
'#f0f9eb', '#f0f9eb',
@ -628,7 +631,7 @@ export const useDataViewerStore = defineStore('text-viewer', () => {
if (acceptIncomingData.value) { if (acceptIncomingData.value) {
if (doSend) { if (doSend) {
/* INFO: hard coded for the moment */ /* INFO: hard coded for the moment */
uart_send_msg(item); uart_send_msg(item, uartStore.uartNum);
} }
} else { } else {
type = 1; type = 1;

View File

@ -0,0 +1,8 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useUartStore = defineStore('uart', () => {
const uartNum = ref(1);
return { uartNum }
})

View File

@ -78,15 +78,17 @@ import {
WtUartCmd WtUartCmd
} from '@/api/apiUart'; } from '@/api/apiUart';
import {type ApiBinaryMsg} from '@/api/binDataDef'; import {type ApiBinaryMsg} from '@/api/binDataDef';
import {wt_data_flow_attach_cur_to_sender} from '@/api/apiDataFlow'; import * as df from '@/api/apiDataFlow';
import textDataViewer from "@/views/text-data-viewer/textDataViewer.vue"; import textDataViewer from "@/views/text-data-viewer/textDataViewer.vue";
import textDataConfig from "@/views/text-data-viewer/textDataConfig.vue" import textDataConfig from "@/views/text-data-viewer/textDataConfig.vue"
import {registerModule} from "@/router/msgRouter"; import {registerModule} from "@/router/msgRouter";
import {isDevMode} from "@/composables/buildMode"; import {isDevMode} from "@/composables/buildMode";
import {useWsStore} from "@/stores/websocket"; import {useWsStore} from "@/stores/websocket";
import {useUartStore} from "@/stores/useUartStore";
const store = useDataViewerStore() const store = useDataViewerStore()
const wsStore = useWsStore() const wsStore = useWsStore()
const uartStore = useUartStore()
const firstWinResizeRef = ref(document.body); const firstWinResizeRef = ref(document.body);
const thirdWinResizeRef = ref(document.body); const thirdWinResizeRef = ref(document.body);
@ -376,12 +378,6 @@ const onUartBinaryMsg = (msg: ApiBinaryMsg) => {
console.log("uart", msg); console.log("uart", msg);
} }
if (msg.sub_mod !== 1) {
/* ignore other num for the moment */
return;
}
/* UART_NUM_1 msg */
store.addSegment(new Uint8Array(msg.payload), true); store.addSegment(new Uint8Array(msg.payload), true);
}; };
@ -389,6 +385,20 @@ const onDataFlowJsonMsg = (msg: api.ApiJsonMsg) => {
if (isDevMode()) { if (isDevMode()) {
console.log("Dflow Json", msg); console.log("Dflow Json", msg);
} }
if (msg.cmd === df.WtDataFlowCmd.GET_INS_LIST) {
const instances = msg as df.IInstanceList;
if (instances.instances.length) {
if (instances.instances[0].mod_type === df.WtDataFlowType.UART) {
uartStore.uartNum = (instances.instances[0].port_info as df.IPeriphInfo).periph_num;
uart_get_baud(uartStore.uartNum);
uart_get_config(uartStore.uartNum);
if (isDevMode()) {
console.log("set UART num to ", uartStore.uartNum);
}
}
}
}
}; };
const onDataFlowBinaryMsg = (msg: ApiBinaryMsg) => { const onDataFlowBinaryMsg = (msg: ApiBinaryMsg) => {
@ -412,17 +422,16 @@ const onClientCtrl = (msg: api.ControlMsg) => {
function updateUartData() { function updateUartData() {
/* TODO: hard code for the moment, 0 is UART instance id (can be changed in the future) */ /* TODO: hard code for the moment, 0 is UART instance id (can be changed in the future) */
wt_data_flow_attach_cur_to_sender(0); df.wt_data_flow_get_instance_list();
uart_get_baud(); df.wt_data_flow_attach_cur_to_sender(0);
uart_get_config();
} }
watch(() => store.uartBaud, value => { watch(() => store.uartBaud, value => {
uart_set_baud(value); uart_set_baud(value, uartStore.uartNum);
}); });
watch(() => store.uartConfig, value => { watch(() => store.uartConfig, value => {
uart_set_config(value); uart_set_config(value, uartStore.uartNum);
}, {deep: true}); }, {deep: true});
onMounted(() => { onMounted(() => {

View File

@ -236,16 +236,8 @@
</el-input> </el-input>
<div class="border rounded flex flex-col"> <div class="border rounded flex flex-col">
<el-tooltip
class="box-item"
effect="light"
placement="right-start"
>
<template #content>
</template>
<el-checkbox border v-model="store.dataFilterAutoUpdate">新数据自动刷新</el-checkbox> <el-checkbox border v-model="store.dataFilterAutoUpdate">新数据自动刷新</el-checkbox>
</el-tooltip>
<el-tooltip content="提高间隔可减少CPU资源的使用" placement="right" effect="light" <el-tooltip content="提高间隔可减少CPU资源的使用" placement="right" effect="light"
:show-after="500"> :show-after="500">