diff --git a/src/api/apiDataFlow.ts b/src/api/apiDataFlow.ts index 9e380f4..b6a1031 100644 --- a/src/api/apiDataFlow.ts +++ b/src/api/apiDataFlow.ts @@ -1,6 +1,31 @@ import {type ApiJsonMsg} from '@/api' 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 { UNKNOWN = 0, GET_INS_LIST = 1, @@ -20,6 +45,25 @@ export interface IWtDataFlowJsonMsg extends ApiJsonMsg { 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() { const jsonMsg: IWtDataFlowJsonMsg = { cmd: WtDataFlowCmd.GET_INS_LIST, diff --git a/src/api/apiUart.ts b/src/api/apiUart.ts index 52a75b1..d52b970 100644 --- a/src/api/apiUart.ts +++ b/src/api/apiUart.ts @@ -44,7 +44,7 @@ export interface IUartMsgBaud extends ApiJsonMsg { 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 */ const msg: ApiBinaryMsg = { sub_mod: sub_mod, @@ -55,7 +55,7 @@ export function uart_send_msg(payload: Uint8Array, sub_mod: number = 1) { sendBinMsg(msg); } -export function uart_get_baud(uart_num: number = 1) { +export function uart_get_baud(uart_num: number) { const cmd = { cmd: WtUartCmd.GET_BAUD, module: WtModuleID.UART, @@ -64,7 +64,7 @@ export function uart_get_baud(uart_num: number = 1) { 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 = { cmd: WtUartCmd.SET_BAUD, module: WtModuleID.UART, @@ -74,7 +74,7 @@ export function uart_set_baud(baud: number, uart_num: number = 1) { sendJsonMsg(cmd); } -export function uart_get_config(uart_num: number = 1) { +export function uart_get_config(uart_num: number) { const cmd = { cmd: WtUartCmd.GET_CONFIG, module: WtModuleID.UART, @@ -83,7 +83,7 @@ export function uart_get_config(uart_num: number = 1) { 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 = { cmd: WtUartCmd.SET_CONFIG, module: WtModuleID.UART, diff --git a/src/stores/dataViewerStore.ts b/src/stores/dataViewerStore.ts index be502ee..40e66c2 100644 --- a/src/stores/dataViewerStore.ts +++ b/src/stores/dataViewerStore.ts @@ -11,6 +11,7 @@ import {AnsiUp} from 'ansi_up' import {debouncedWatch} from "@vueuse/core"; import {type IUartConfig, uart_send_msg} from "@/api/apiUart"; import {isDevMode} from "@/composables/buildMode"; +import {useUartStore} from "@/stores/useUartStore"; interface IDataArchive { time: number; @@ -180,6 +181,8 @@ function generateBaudArr(results: { baud: number; }[]) { } export const useDataViewerStore = defineStore('text-viewer', () => { + const uartStore = useUartStore() + /* private value */ const predefineColors = [ '#f0f9eb', @@ -628,7 +631,7 @@ export const useDataViewerStore = defineStore('text-viewer', () => { if (acceptIncomingData.value) { if (doSend) { /* INFO: hard coded for the moment */ - uart_send_msg(item); + uart_send_msg(item, uartStore.uartNum); } } else { type = 1; diff --git a/src/stores/useUartStore.ts b/src/stores/useUartStore.ts new file mode 100644 index 0000000..c8faff2 --- /dev/null +++ b/src/stores/useUartStore.ts @@ -0,0 +1,8 @@ +import { ref } from 'vue' +import { defineStore } from 'pinia' + +export const useUartStore = defineStore('uart', () => { + const uartNum = ref(1); + + return { uartNum } +}) diff --git a/src/views/Uart.vue b/src/views/Uart.vue index d3d37f2..02d53b1 100644 --- a/src/views/Uart.vue +++ b/src/views/Uart.vue @@ -78,15 +78,17 @@ import { WtUartCmd } from '@/api/apiUart'; 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 textDataConfig from "@/views/text-data-viewer/textDataConfig.vue" import {registerModule} from "@/router/msgRouter"; import {isDevMode} from "@/composables/buildMode"; import {useWsStore} from "@/stores/websocket"; +import {useUartStore} from "@/stores/useUartStore"; const store = useDataViewerStore() const wsStore = useWsStore() +const uartStore = useUartStore() const firstWinResizeRef = ref(document.body); const thirdWinResizeRef = ref(document.body); @@ -376,12 +378,6 @@ const onUartBinaryMsg = (msg: ApiBinaryMsg) => { 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); }; @@ -389,6 +385,20 @@ const onDataFlowJsonMsg = (msg: api.ApiJsonMsg) => { if (isDevMode()) { 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) => { @@ -412,17 +422,16 @@ const onClientCtrl = (msg: api.ControlMsg) => { function updateUartData() { /* 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); - uart_get_baud(); - uart_get_config(); + df.wt_data_flow_get_instance_list(); + df.wt_data_flow_attach_cur_to_sender(0); } watch(() => store.uartBaud, value => { - uart_set_baud(value); + uart_set_baud(value, uartStore.uartNum); }); watch(() => store.uartConfig, value => { - uart_set_config(value); + uart_set_config(value, uartStore.uartNum); }, {deep: true}); onMounted(() => { diff --git a/src/views/text-data-viewer/textDataConfig.vue b/src/views/text-data-viewer/textDataConfig.vue index ba5907a..0a10cd4 100644 --- a/src/views/text-data-viewer/textDataConfig.vue +++ b/src/views/text-data-viewer/textDataConfig.vue @@ -236,16 +236,8 @@
- - - 新数据自动刷新 - + 新数据自动刷新