From 8f7ed9e39f712ee8b054aa342287b5fd70329dc4 Mon Sep 17 00:00:00 2001 From: fangxiang Date: Wed, 2 Nov 2022 17:14:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E6=8E=A7=E6=B7=BB=E5=8A=A0TCP?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=92=8CUDP=E8=BF=9E=E6=8E=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- src/common/ClientConnection.ts | 27 +- src/components/CenterControlDialog.vue | 508 ++++++++++++++++++------- src/entities/WSProtocol.ts | 80 ++-- src/i18n/en-US/index.ts | 7 + src/i18n/zh-CN/index.ts | 6 + yarn.lock | 8 +- 7 files changed, 476 insertions(+), 164 deletions(-) diff --git a/package.json b/package.json index e5756bf..b038358 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "media_player_client", - "version": "1.5.4", + "version": "1.5.5", "description": "A Quasar Framework app", "productName": "MediaPlayerClient", "author": "fangxiang ", @@ -18,7 +18,7 @@ "core-js": "^3.21.0", "element-resize-detector": "^1.2.4", "qrcode.vue": "^3.3.3", - "quasar": "^2.10.0", + "quasar": "^2.10.1", "reconnecting-websocket": "^4.4.0", "sortablejs": "^1.15.0", "to": "^0.2.9", diff --git a/src/common/ClientConnection.ts b/src/common/ClientConnection.ts index fd5624f..fbe62b8 100644 --- a/src/common/ClientConnection.ts +++ b/src/common/ClientConnection.ts @@ -1055,9 +1055,9 @@ export default class ClientConnection { ); } - public async deleteExternalControlData(uuid: string) { + public async deleteExternalControlData(number: number) { return await this.doRpc( - new Protocol.RpcDeleteExternalControlDataRequestEntity(uuid) + new Protocol.RpcDeleteExternalControlDataRequestEntity(number) ); } @@ -1080,18 +1080,31 @@ export default class ClientConnection { } public async setExternalControlSerialPortConfig( - config: SerialPortConfigEntity + serial_port: SerialPortConfigEntity, + tcp_address: string, + tcp_port: number, + udp_address: string, + udp_port: number, + current_type: string ) { return await this.doRpc( - new Protocol.RpcSetExternalControlSerialPortConfigRequestEntity(config) + new Protocol.RpcSetExternalControlSerialPortConfigRequestEntity( + serial_port, + tcp_address, + tcp_port, + udp_address, + udp_port, + current_type + ) ); } - public callExternalControlData(uuid: string) { - this.ws?.send( - JSON.stringify(new Protocol.CallExternalControlDataRequestEntity(uuid)) + public async callExternalControlData(number: number) { + return await this.doRpc( + new Protocol.RpcCallExternalControlDataRequestEntity(number) ); } + public setEdgeBlendingPoint(point: EdgeBlendingPoint) { this.ws?.send( JSON.stringify(new Protocol.SetEdgeBlendingPointRequestEntity(point)) diff --git a/src/components/CenterControlDialog.vue b/src/components/CenterControlDialog.vue index 30123b5..0b9ed23 100644 --- a/src/components/CenterControlDialog.vue +++ b/src/components/CenterControlDialog.vue @@ -57,9 +57,9 @@ :disable="loading" /> @@ -90,7 +90,7 @@ :label="buttons[(row - 1) * 4 + (col - 1)].name" @click=" centerControlCommand( - buttons[(row - 1) * 4 + (col - 1)].uuid + buttons[(row - 1) * 4 + (col - 1)].number ) " > @@ -122,101 +122,232 @@ - {{ $t("baud rate") }} + {{ $t("connection type") }} + + + +
+ + + {{ $t("baud rate") }} + + + - - - - - {{ $t("character size") }} - - - - - - - - {{ $t("parity") }} - - - - - - - - {{ $t("stop bits") }} - - - - - + ]" + /> + + + + + {{ $t("character size") }} + + + + + + + + {{ $t("parity") }} + + + + + + + + {{ $t("stop bits") }} + + + + + +
+
+ + + {{ $t("ip address") }} + + + + + + + + {{ $t("port") }} + + + + + +
+
+ + + {{ $t("ip address") }} + + + + + + + + {{ $t("port") }} + + + + + +
+
+ {{ $t("unknow type") }} +
@@ -229,7 +360,7 @@ :label="$t('revert')" :loading="loading" color="primary" - @click="onRevertSerialportConfig" + @click="onRevertConfig" />
@@ -239,7 +370,7 @@ :label="$t('submit')" :loading="loading" color="primary" - @click="onSubmitSerialportConfig" + @click="onSubmitConfig" />
@@ -255,11 +386,7 @@ @@ -278,6 +405,7 @@ import { ESerialPortStopBitsHelper, SerialPortConfigEntity, } from "src/entities/SerialPortConfigEntity"; +import { Protocol } from "src/entities/WSProtocol"; export default defineComponent({ name: "ComponentCenterControlDialog", @@ -297,6 +425,21 @@ export default defineComponent({ ); const old_serial_port_setting = new SerialPortConfigEntity(); + const current_type = ref("SERIAL_PORT"); + const tcp_address = ref("192.168.2.2"); + const tcp_port = ref("10000"); + const udp_address = ref("192.168.2.2"); + const udp_port = ref("10000"); + + let old_current_type = "SERIAL_PORT"; + let old_tcp_address = "192.168.2.2"; + let old_tcp_port = "10000"; + let old_udp_address = "192.168.2.2"; + let old_udp_port = "10000"; + + let old_response: Protocol.RpcGetExternalControlSerialPortConfigResponseEntity = + new Protocol.RpcGetExternalControlSerialPortConfigResponseEntity(); + const center_control_button_dialog: Ref = ref(null); return { @@ -306,6 +449,11 @@ export default defineComponent({ buttons, serial_port_setting, center_control_button_dialog, + current_type, + tcp_address, + tcp_port, + udp_address, + udp_port, copyToClipboard, loga(a: any) { console.log(a); @@ -336,20 +484,27 @@ export default defineComponent({ .getCurrentClient() ?.getExternalControlSerialPortConfig(); if (response) { - serial_port_setting.baud_rate = response.config.baud_rate; - serial_port_setting.character_size = response.config.character_size; + serial_port_setting.baud_rate = response.serial_port.baud_rate; + serial_port_setting.character_size = + response.serial_port.character_size; serial_port_setting.parity = ESerialPortParityHelper.fromString( - (response.config.parity) as string + (response.serial_port.parity) as string ); serial_port_setting.stop_bits = ESerialPortStopBitsHelper.fromString( - (response.config.stop_bits) as string + (response.serial_port.stop_bits) as string ); serial_port_setting.flow_control = ESerialPortFlowControlHelper.fromString( - (response.config.flow_control) as string + (response.serial_port.flow_control) as string ); + current_type.value = response.current_type; + tcp_address.value = response.tcp_address; + tcp_port.value = response.tcp_port.toString(); + udp_address.value = response.udp_address; + udp_port.value = response.udp_port.toString(); + old_serial_port_setting.baud_rate = serial_port_setting.baud_rate; old_serial_port_setting.character_size = serial_port_setting.character_size; @@ -357,6 +512,14 @@ export default defineComponent({ old_serial_port_setting.stop_bits = serial_port_setting.stop_bits; old_serial_port_setting.flow_control = serial_port_setting.flow_control; + + old_current_type = current_type.value; + old_tcp_address = tcp_address.value; + old_tcp_port = tcp_port.value; + old_udp_address = udp_address.value; + old_udp_port = udp_port.value; + + old_response = response; } } catch {} @@ -366,41 +529,98 @@ export default defineComponent({ loading.value = false; }, - async onRevertSerialportConfig() { + async onRevertConfig() { serial_port_setting.baud_rate = old_serial_port_setting.baud_rate; serial_port_setting.character_size = old_serial_port_setting.character_size; serial_port_setting.parity = old_serial_port_setting.parity; serial_port_setting.stop_bits = old_serial_port_setting.stop_bits; serial_port_setting.flow_control = old_serial_port_setting.flow_control; + + tcp_address.value = old_tcp_address; + tcp_port.value = old_tcp_port; + + udp_address.value = old_udp_address; + udp_port.value = old_udp_port; + current_type.value = old_current_type; }, - async onSubmitSerialportConfig() { + async onSubmitConfig() { loading.value = true; let success = false; + let request_current_type = current_type.value; + console.log(request_current_type); + if ( + request_current_type != "SERIAL_PORT" && + request_current_type != "UDP" && + request_current_type != "TCP" + ) { + request_current_type = "SERIAL_PORT"; + } + try { - const request_param = new SerialPortConfigEntity(); - request_param.baud_rate = serial_port_setting.baud_rate; - request_param.character_size = serial_port_setting.character_size; - (request_param.parity) = ESerialPortParityHelper.toString( - serial_port_setting.parity - ); - (request_param.stop_bits) = ESerialPortStopBitsHelper.toString( - serial_port_setting.stop_bits - ); - (request_param.flow_control) = - ESerialPortFlowControlHelper.toString( - serial_port_setting.flow_control - ); + let request_serial_prot_config = + old_response.serial_port ?? new SerialPortConfigEntity(); + let request_tcp_address = old_response.tcp_address ?? "192.168.2.2"; + let request_tcp_port = old_response.tcp_port ?? 1000; + let request_udp_address = old_response.udp_address ?? "192.168.2.2"; + let request_udp_port = old_response.udp_port ?? 1000; + + switch (request_current_type) { + case "SERIAL_PORT": + request_serial_prot_config.baud_rate = + serial_port_setting.baud_rate; + request_serial_prot_config.character_size = + serial_port_setting.character_size; + (request_serial_prot_config.parity) = + ESerialPortParityHelper.toString(serial_port_setting.parity); + (request_serial_prot_config.stop_bits) = + ESerialPortStopBitsHelper.toString( + serial_port_setting.stop_bits + ); + (request_serial_prot_config.flow_control) = + ESerialPortFlowControlHelper.toString( + serial_port_setting.flow_control + ); + break; + case "TCP": + { + request_tcp_address = tcp_address.value; + const temp = parseInt(tcp_port.value); + if (isNaN(temp)) { + request_tcp_port = 1000; + } else { + request_tcp_port = temp; + } + } + break; + case "UDP": + { + request_udp_address = udp_address.value; + const temp = parseInt(udp_port.value); + if (isNaN(temp)) { + request_udp_port = 1000; + } else { + request_udp_port = temp; + } + } + break; + } + const response = await GlobalData.getInstance() .getCurrentClient() - ?.setExternalControlSerialPortConfig(request_param); + ?.setExternalControlSerialPortConfig( + request_serial_prot_config, + request_tcp_address, + request_tcp_port, + request_udp_address, + request_udp_port, + request_current_type + ); if (response) { success = response.success; - console.log(response); - console.log(success); old_serial_port_setting.baud_rate = serial_port_setting.baud_rate; old_serial_port_setting.character_size = @@ -409,6 +629,13 @@ export default defineComponent({ old_serial_port_setting.stop_bits = serial_port_setting.stop_bits; old_serial_port_setting.flow_control = serial_port_setting.flow_control; + + old_current_type = current_type.value; + old_tcp_address = tcp_address.value; + old_tcp_port = tcp_port.value; + old_udp_address = udp_address.value; + old_udp_port = udp_port.value; + old_current_type = current_type.value; } } catch {} @@ -424,19 +651,38 @@ export default defineComponent({ }); loading.value = false; }, - centerControlCommand(uuid?: string) { - if (uuid) { - GlobalData.getInstance() - .getCurrentClient() - ?.callExternalControlData(uuid); - $q.notify({ - color: "positive", - icon: "done", - message: $t.t("send command") + $t.t("success") + "!", - position: "top", - timeout: 1500, - }); + async centerControlCommand(number?: number) { + let success = false; + try { + if ( + typeof number != "undefined" && + number != null && + !isNaN(number) + ) { + const resposne = await GlobalData.getInstance() + .getCurrentClient() + ?.callExternalControlData(number); + + if (resposne) { + success = resposne.success; + } + } + } catch (e) { + console.error(e); } + $q.notify({ + color: success ? "positive" : "negative", + icon: success ? "done" : "warning", + message: + $t.t("send command") + + $t.t(success ? "success" : "failed") + + (success + ? "" + : "," + $t.t(" ") + $t.t("please check connection config")) + + "!", + position: "top", + timeout: 2500, + }); }, async editCenterControlButton(data?: ExternalControlTableEntity) { if (data) { @@ -487,6 +733,14 @@ export default defineComponent({ } } }, + isIpAddress(str: string) { + return ( + str == "localhost" || + /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test( + str + ) + ); + }, }; }, }); diff --git a/src/entities/WSProtocol.ts b/src/entities/WSProtocol.ts index 96e1c83..6295c68 100644 --- a/src/entities/WSProtocol.ts +++ b/src/entities/WSProtocol.ts @@ -380,14 +380,14 @@ export namespace Protocol { public static get kRpcAddExternalControlData() { return Commands.PROTOCOL_PREFIX + "RpcAddExternalControlData"; } - public static get kCallExternalControlData() { - return Commands.PROTOCOL_PREFIX + "CallExternalControlData"; + public static get kRpcCallExternalControlData() { + return Commands.PROTOCOL_PREFIX + "RpcCallExternalControlData"; } - public static get kRpcGetExternalControlSerialPortConfig() { - return Commands.PROTOCOL_PREFIX + "RpcGetExternalControlSerialPortConfig"; + public static get kRpcGetExternalControlConfig() { + return Commands.PROTOCOL_PREFIX + "RpcGetExternalControlConfig"; } - public static get kRpcSetExternalControlSerialPortConfig() { - return Commands.PROTOCOL_PREFIX + "RpcSetExternalControlSerialPortConfig"; + public static get kRpcSetExternalControlConfig() { + return Commands.PROTOCOL_PREFIX + "RpcSetExternalControlConfig"; } public static get kRpcGetConnectionList() { return Commands.PROTOCOL_PREFIX + "RpcGetConnectionList"; @@ -555,9 +555,9 @@ export namespace Protocol { Commands.kRpcDeleteExternalControlData, Commands.kRpcEditExternalControlData, Commands.kRpcAddExternalControlData, - Commands.kCallExternalControlData, - Commands.kRpcGetExternalControlSerialPortConfig, - Commands.kRpcSetExternalControlSerialPortConfig, + Commands.kRpcCallExternalControlData, + Commands.kRpcGetExternalControlConfig, + Commands.kRpcSetExternalControlConfig, Commands.kRpcGetConnectionList, Commands.kRpcSetConnectionItem, Commands.kWindowFullScreen, @@ -2426,15 +2426,15 @@ export namespace Protocol { } export class RpcDeleteExternalControlDataRequestEntity extends PacketEntity { - constructor(uuid: string, rpc_id = 0) { + constructor(number: number, rpc_id = 0) { super(); super.command = Commands.kRpcDeleteExternalControlData; super.flag = PacketEntity.FLAG_REQUEST; super.rpc_id = rpc_id; - this.uuid = uuid; + this.number = number ?? -1; } - uuid = ""; + number = -1; } export class RpcDeleteExternalControlDataResponseEntity extends PacketEntity { @@ -2513,7 +2513,7 @@ export namespace Protocol { export class ExternalControlDataAddNotifyEntity extends PacketEntity { constructor() { super(); - super.command = Commands.kRpcDeleteExternalControlData; + super.command = Commands.kRpcAddExternalControlData; super.flag = PacketEntity.FLAG_NOTIFY; super.rpc_id = 0; } @@ -2521,22 +2521,31 @@ export namespace Protocol { entity = new ExternalControlTableEntity(); } - export class CallExternalControlDataRequestEntity extends PacketEntity { - constructor(uuid: string) { + export class RpcCallExternalControlDataRequestEntity extends PacketEntity { + constructor(number: number) { super(); - super.command = Commands.kCallExternalControlData; + super.command = Commands.kRpcCallExternalControlData; super.flag = PacketEntity.FLAG_REQUEST; super.rpc_id = 0; - this.uuid = uuid; + this.number = number; } - uuid: string; + number: number; + } + + export class RpcCallExternalControlDataResponseEntity extends PacketEntity { + constructor() { + super(); + super.flag = PacketEntity.FLAG_RESPONSE; + } + + success: boolean = false; } export class RpcGetExternalControlSerialPortConfigRequestEntity extends PacketEntity { constructor(rpc_id = 0) { super(); - super.command = Commands.kRpcGetExternalControlSerialPortConfig; + super.command = Commands.kRpcGetExternalControlConfig; super.flag = PacketEntity.FLAG_REQUEST; super.rpc_id = rpc_id; } @@ -2550,19 +2559,42 @@ export namespace Protocol { super.flag = PacketEntity.FLAG_RESPONSE; } - config = new SerialPortConfigEntity(); + serial_port = new SerialPortConfigEntity(); + tcp_address = "192.168.2.2"; + tcp_port = 1000; + udp_address = "192.168.2.2"; + udp_port = 1000; + current_type = "SERIAL_PORT"; } export class RpcSetExternalControlSerialPortConfigRequestEntity extends PacketEntity { - constructor(config: SerialPortConfigEntity, rpc_id = 0) { + constructor( + serial_port: SerialPortConfigEntity, + tcp_address: string, + tcp_port: number, + udp_address: string, + udp_port: number, + current_type: string, + rpc_id = 0 + ) { super(); - super.command = Commands.kRpcSetExternalControlSerialPortConfig; + super.command = Commands.kRpcSetExternalControlConfig; super.flag = PacketEntity.FLAG_REQUEST; super.rpc_id = rpc_id; - this.config = config; + this.serial_port = serial_port ?? new SerialPortConfigEntity(); + this.tcp_address = tcp_address ?? "192.168.2.2"; + this.tcp_port = tcp_port ?? 1000; + this.udp_address = udp_address ?? "192.168.2.2"; + this.udp_port = udp_port ?? 1000; + this.current_type = current_type ?? "SERIAL_PORT"; } - config: SerialPortConfigEntity; + serial_port = new SerialPortConfigEntity(); + tcp_address = "192.168.2.2"; + tcp_port = 1000; + udp_address = "192.168.2.2"; + udp_port = 1000; + current_type = "SERIAL_PORT"; } export class RpcSetExternalControlSerialPortConfigResponseEntity extends PacketEntity { diff --git a/src/i18n/en-US/index.ts b/src/i18n/en-US/index.ts index d7c89f9..5d3b970 100644 --- a/src/i18n/en-US/index.ts +++ b/src/i18n/en-US/index.ts @@ -376,4 +376,11 @@ export default { "row multiply column should be less than or equal to ": "Row Multiply Column Should Be Less Than Or Equal To ", "please select window rotation": "Please Select Window Rotation", + "send command": "Send Command", + "please check connection config": "Please Check Connection Config", + "connection setting": "Connection Setting", + "connection type": "Connection Type", + tcp: "TCP", + udp: "UDP", + "serial port": "Serial Port", }; diff --git a/src/i18n/zh-CN/index.ts b/src/i18n/zh-CN/index.ts index e64f07d..00f8a5f 100644 --- a/src/i18n/zh-CN/index.ts +++ b/src/i18n/zh-CN/index.ts @@ -648,4 +648,10 @@ export default { "row multiply column should be less than or equal to ": "行乘以列的值不能大于", "please select window rotation": "请选择窗口旋转", + "please check connection config": "请检查连接配置", + "connection setting": "连接设置", + "connection type": "连接类型", + tcp: "TCP", + udp: "UDP", + "serial port": "串口", }; diff --git a/yarn.lock b/yarn.lock index 101e229..e0d8953 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8890,10 +8890,10 @@ qs@6.9.6: resolved "https://registry.npmmirror.com/qs/-/qs-6.9.6.tgz#26ed3c8243a431b2924aca84cc90471f35d5a0ee" integrity sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ== -quasar@^2.10.0: - version "2.10.0" - resolved "https://registry.npmmirror.com/quasar/-/quasar-2.10.0.tgz#c9af5adad0d7ebe8f14c61c5403c943e7c935453" - integrity sha512-PHGcrzPQfFa4tv9a5Z/3D2uat48D4WC9Ad/imzHk/k3G41t0eFMH6glCjAvpCWF2q8dBYIg4nEchiPhlujbKsw== +quasar@^2.10.1: + version "2.10.1" + resolved "https://registry.npmmirror.com/quasar/-/quasar-2.10.1.tgz#843888c73d997a53b3808d7f4f358b1aee3a91f2" + integrity sha512-W0SEbTdfFS4xvO5OyTyuJent+11MpjBJUYLga69ZFigRh7SV6wFpGNfCuxAifM0L83bp4rWrL2KGoIjEoDsjOw== query-string@^5.0.1: version "5.1.1"