diff --git a/src/App.vue b/src/App.vue index e0eca93..a6641b2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -13,6 +13,7 @@ import {globalNotify} from "@/composables/notification"; import {isDevMode} from "@/composables/buildMode"; import {ElMessageBox} from "element-plus"; import {useSystemModule} from "@/composables/useSystemModule"; +import {useDataFlowModule} from "@/composables/useDataFlowModule"; const wsState = useWsStore(); @@ -49,7 +50,9 @@ onMounted(() => { websocketService = getWebsocketService(); websocketService.init(host, onServerMsg, onClientCtrl); changeFavicon(); + useSystemModule(); + useDataFlowModule(); }); onUnmounted(() => { diff --git a/src/api/apiDataFlow.ts b/src/api/apiDataFlow.ts index b6a1031..1b8613a 100644 --- a/src/api/apiDataFlow.ts +++ b/src/api/apiDataFlow.ts @@ -55,13 +55,26 @@ export interface ISocketInfo { local_port: number; } +export interface InstanceInfo { + ins_idx: number, + mod_idx: number, + mod_type: number, + port_info: ISocketInfo | IPeriphInfo; +} + export interface IInstanceList extends ApiJsonMsg { - instances: { - ins_idx: number, - mod_idx: number, - mod_type: number, - port_info: ISocketInfo | IPeriphInfo; - }[], + instances: InstanceInfo[], +} + +export interface AttachInfo { + attach_idx: number, + s_ins_idx: number, + r_ins_idx: number, + data_type: 3 | 4, +} + +export interface IAttachList extends ApiJsonMsg { + attaches: AttachInfo[], } export function wt_data_flow_get_instance_list() { diff --git a/src/api/apiUart.ts b/src/api/apiUart.ts index d52b970..789532c 100644 --- a/src/api/apiUart.ts +++ b/src/api/apiUart.ts @@ -22,6 +22,8 @@ export enum WtUartCmd { SET_STATUS, /* set specific uart port disable */ GET_DATA_TYPE = 22, // 0x03 or 0x04 SET_DATA_TYPE = 23, // 0x03 or 0x04 + + GET_DEFAULT_NUM = 24, } enum ANSI_ESCAPE_CODE { @@ -44,6 +46,10 @@ export interface IUartMsgBaud extends ApiJsonMsg { baud: number; } +export interface IUartMsgNum extends ApiJsonMsg { + num: number; +} + export function uart_send_msg(payload: Uint8Array, sub_mod: number) { /* hard code uart num for now */ const msg: ApiBinaryMsg = { @@ -93,4 +99,12 @@ export function uart_set_config(uart_config: IUartConfig, uart_num: number) { stop_bits: uart_config.stop_bits, } sendJsonMsg(cmd); -} \ No newline at end of file +} + +export function uart_get_default_num() { + const cmd = { + cmd: WtUartCmd.GET_DEFAULT_NUM, + module: WtModuleID.UART, + } + sendJsonMsg(cmd); +} diff --git a/src/api/index.ts b/src/api/index.ts index 840a092..cc8b218 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -31,11 +31,11 @@ export interface ServerMsg { } export enum WtModuleID { + SYSTEM = 0, WIFI = 1, DATA_FLOW = 2, UART = 4, OTA = 5, - SYSTEM = 6, } export function sendJsonMsg(apiJsonMsg: ApiJsonMsg) { diff --git a/src/composables/useDataFlowModule.ts b/src/composables/useDataFlowModule.ts new file mode 100644 index 0000000..7735a44 --- /dev/null +++ b/src/composables/useDataFlowModule.ts @@ -0,0 +1,44 @@ +import {registerModule} from "@/router/msgRouter"; +import {type ApiJsonMsg, ControlEvent, type ControlMsg, ControlMsgType, WtModuleID} from "@/api"; +import {isDevMode} from "@/composables/buildMode"; +import {useDataFlowStore} from "@/stores/useDataFlowStore"; +import {type IInstanceList, WtDataFlowCmd} from "@/api/apiDataFlow"; + + +export function useDataFlowModule() { + const dfStore = useDataFlowStore() + + function onClientCtrl(msg: ControlMsg) { + if (msg.type !== ControlMsgType.WS_EVENT) { + return + } + } + + function onClientMsg(msg: ApiJsonMsg) { + switch (msg.cmd as WtDataFlowCmd) { + case WtDataFlowCmd.GET_INS_LIST: { + const insList = msg as IInstanceList; + dfStore.instanceList = insList.instances; + break; + } + case WtDataFlowCmd.GET_ATTACH_LIST: { + break; + } + default: + break; + } + if (isDevMode()) { + console.log(msg); + } + } + + registerModule(WtModuleID.DATA_FLOW, { + ctrlCallback: onClientCtrl, + serverJsonMsgCallback: onClientMsg, + serverBinMsgCallback: () => {}, + }); +} + + + + diff --git a/src/router/msgRouter.ts b/src/router/msgRouter.ts index 368df05..0dbffa0 100644 --- a/src/router/msgRouter.ts +++ b/src/router/msgRouter.ts @@ -12,6 +12,9 @@ const moduleMap = new Map(); export function registerModule(moduleId: number, moduleCallback: IModuleCallback): boolean { if (moduleMap.has(moduleId)) { + if (isDevMode()) { + console.log("module ", moduleId, "already registered"); + } return false; } diff --git a/src/stores/useDataFlowStore.ts b/src/stores/useDataFlowStore.ts new file mode 100644 index 0000000..ce5a9f3 --- /dev/null +++ b/src/stores/useDataFlowStore.ts @@ -0,0 +1,11 @@ +import {defineStore} from "pinia"; +import {type Ref, ref} from "vue"; +import type {AttachInfo, InstanceInfo} from "@/api/apiDataFlow"; + +export const useDataFlowStore = defineStore('data_flow', () => { + const instanceList: Ref = ref([]); + + return { + instanceList, + } +}); diff --git a/src/views/Uart.vue b/src/views/Uart.vue index 55807e1..3841ddf 100644 --- a/src/views/Uart.vue +++ b/src/views/Uart.vue @@ -65,8 +65,10 @@ import * as uart from '@/api/apiUart'; import { type IUartMsgBaud, type IUartMsgConfig, + type IUartMsgNum, uart_get_baud, uart_get_config, + uart_get_default_num, uart_set_baud, uart_set_config, WtUartCmd @@ -363,6 +365,11 @@ const onUartJsonMsg = (msg: api.ApiJsonMsg) => { store.uartConfig.parity = uartMsg.parity; break; } + case WtUartCmd.GET_DEFAULT_NUM: + uartStore.uartNum = (msg as IUartMsgNum).num; + uart_get_baud(uartStore.uartNum); + uart_get_config(uartStore.uartNum); + break; default: if (isDevMode()) { console.log("uart not treated", msg); @@ -379,32 +386,6 @@ const onUartBinaryMsg = (msg: ApiBinaryMsg) => { store.addSegment(new Uint8Array(msg.payload), true); }; -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) => { - if (isDevMode()) { - console.log("Dflow Bin", msg); - } -}; - const onClientCtrl = (msg: api.ControlMsg) => { if (msg.type !== api.ControlMsgType.WS_EVENT) { return @@ -420,7 +401,7 @@ const onClientCtrl = (msg: api.ControlMsg) => { function updateUartData() { /* TODO: hard code for the moment, 0 is UART instance id (can be changed in the future) */ - df.wt_data_flow_get_instance_list(); + uart_get_default_num(); df.wt_data_flow_attach_cur_to_sender(0); } @@ -439,12 +420,6 @@ onMounted(() => { serverBinMsgCallback: onUartBinaryMsg, }); - registerModule(api.WtModuleID.DATA_FLOW, { - ctrlCallback: () => {}, - serverJsonMsgCallback: onDataFlowJsonMsg, - serverBinMsgCallback: onDataFlowBinaryMsg, - }); - firstWinResizeRef.value.style.borderWidth = win1.borderSize + "px"; thirdWinResizeRef.value.style.borderWidth = win2.borderSize + "px"; updateCursors() diff --git a/src/views/text-data-viewer/textDataConfig.vue b/src/views/text-data-viewer/textDataConfig.vue index 0a68d50..88483c1 100644 --- a/src/views/text-data-viewer/textDataConfig.vue +++ b/src/views/text-data-viewer/textDataConfig.vue @@ -310,6 +310,24 @@ + + + +
+
+ TCP服务器端口 + 1346 +
+
+

刷新 已连接的客户端:

+ + + + + +
+
+
@@ -323,9 +341,13 @@ import {globalNotify} from "@/composables/notification"; import {ControlEvent} from "@/api"; import type {MoveEvent} from "sortablejs"; import InlineSvg from "@/components/InlineSvg.vue"; +import {useDataFlowStore} from "@/stores/useDataFlowStore"; +import {wt_data_flow_get_instance_list, type ISocketInfo} from "@/api/apiDataFlow"; const store = useDataViewerStore() const wsStore = useWsStore() +const dfStore = useDataFlowStore() + const collapseActiveName = ref(["1", "2", "3"]) const uartCustomBaud = ref(114514) @@ -387,6 +409,11 @@ function checkMove(event: MoveEvent) { return !!store.frameBreakRules[toIndex].draggable; } +function refreshTCPClientList() { + dfStore.instanceList = []; + wt_data_flow_get_instance_list(); +} +