From fe56bdc27da8c492cbe1cf4c84f34c8774137fa3 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 21 Aug 2024 17:37:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=97=8B=E9=92=AE=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/Simulation.ts | 2 +- src/protos/request.ts | 57 +++++++++++++++++++++-------------------- src/stores/tcc-store.ts | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/api/Simulation.ts b/src/api/Simulation.ts index 753d809..26b250b 100644 --- a/src/api/Simulation.ts +++ b/src/api/Simulation.ts @@ -191,7 +191,7 @@ export interface TccOperationParams { controlType: request.TrainControl.TrainControlType; controlButton?: object; driverKey?: object; - dirKey?: object; + switchKey?: object; handler?: object; } export async function tccOperation(params: TccOperationParams) { diff --git a/src/protos/request.ts b/src/protos/request.ts index c23e593..1d99933 100644 --- a/src/protos/request.ts +++ b/src/protos/request.ts @@ -1423,7 +1423,7 @@ export namespace request { controlType?: TrainControl.TrainControlType; controlButton?: TrainControl.ControlButton; driverKey?: TrainControl.DriverKeySwitch; - dirKey?: TrainControl.DirectionKeySwitch; + switchKey?: TrainControl.SwitchKeyChange; handler?: TrainControl.PushHandler; }) { super(); @@ -1447,8 +1447,8 @@ export namespace request { if ("driverKey" in data && data.driverKey != undefined) { this.driverKey = data.driverKey; } - if ("dirKey" in data && data.dirKey != undefined) { - this.dirKey = data.dirKey; + if ("switchKey" in data && data.switchKey != undefined) { + this.switchKey = data.switchKey; } if ("handler" in data && data.handler != undefined) { this.handler = data.handler; @@ -1497,13 +1497,13 @@ export namespace request { get has_driverKey() { return pb_1.Message.getField(this, 6) != null; } - get dirKey() { - return pb_1.Message.getWrapperField(this, TrainControl.DirectionKeySwitch, 7) as TrainControl.DirectionKeySwitch; + get switchKey() { + return pb_1.Message.getWrapperField(this, TrainControl.SwitchKeyChange, 7) as TrainControl.SwitchKeyChange; } - set dirKey(value: TrainControl.DirectionKeySwitch) { + set switchKey(value: TrainControl.SwitchKeyChange) { pb_1.Message.setWrapperField(this, 7, value); } - get has_dirKey() { + get has_switchKey() { return pb_1.Message.getField(this, 7) != null; } get handler() { @@ -1522,7 +1522,7 @@ export namespace request { controlType?: TrainControl.TrainControlType; controlButton?: ReturnType; driverKey?: ReturnType; - dirKey?: ReturnType; + switchKey?: ReturnType; handler?: ReturnType; }): TrainControl { const message = new TrainControl({}); @@ -1544,8 +1544,8 @@ export namespace request { if (data.driverKey != null) { message.driverKey = TrainControl.DriverKeySwitch.fromObject(data.driverKey); } - if (data.dirKey != null) { - message.dirKey = TrainControl.DirectionKeySwitch.fromObject(data.dirKey); + if (data.switchKey != null) { + message.switchKey = TrainControl.SwitchKeyChange.fromObject(data.switchKey); } if (data.handler != null) { message.handler = TrainControl.PushHandler.fromObject(data.handler); @@ -1560,7 +1560,7 @@ export namespace request { controlType?: TrainControl.TrainControlType; controlButton?: ReturnType; driverKey?: ReturnType; - dirKey?: ReturnType; + switchKey?: ReturnType; handler?: ReturnType; } = {}; if (this.simulationId != null) { @@ -1581,8 +1581,8 @@ export namespace request { if (this.driverKey != null) { data.driverKey = this.driverKey.toObject(); } - if (this.dirKey != null) { - data.dirKey = this.dirKey.toObject(); + if (this.switchKey != null) { + data.switchKey = this.switchKey.toObject(); } if (this.handler != null) { data.handler = this.handler.toObject(); @@ -1605,8 +1605,8 @@ export namespace request { writer.writeMessage(5, this.controlButton, () => this.controlButton.serialize(writer)); if (this.has_driverKey) writer.writeMessage(6, this.driverKey, () => this.driverKey.serialize(writer)); - if (this.has_dirKey) - writer.writeMessage(7, this.dirKey, () => this.dirKey.serialize(writer)); + if (this.has_switchKey) + writer.writeMessage(7, this.switchKey, () => this.switchKey.serialize(writer)); if (this.has_handler) writer.writeMessage(8, this.handler, () => this.handler.serialize(writer)); if (!w) @@ -1637,7 +1637,7 @@ export namespace request { reader.readMessage(message.driverKey, () => message.driverKey = TrainControl.DriverKeySwitch.deserialize(reader)); break; case 7: - reader.readMessage(message.dirKey, () => message.dirKey = TrainControl.DirectionKeySwitch.deserialize(reader)); + reader.readMessage(message.switchKey, () => message.switchKey = TrainControl.SwitchKeyChange.deserialize(reader)); break; case 8: reader.readMessage(message.handler, () => message.handler = TrainControl.PushHandler.deserialize(reader)); @@ -1659,12 +1659,13 @@ export namespace request { EMERGENT_BUTTON = 0, DRIVER_KEY_SWITCH = 1, DIRECTION_KEY_SWITCH = 2, - HANDLER = 3 + HANDLER = 3, + TRAIN_DOOR_MODE_CHANGE = 4 } - export enum Direction { - BACKWARD = 0, - FORWARD = 1, - NEUTRALWARD = 2 + export enum KeyLocation { + KL_END = 0, + KL_FONT = 1, + KL_CENTER = 2 } export class ControlButton extends pb_1.Message { #one_of_decls: number[][] = []; @@ -1867,7 +1868,7 @@ export namespace request { return DriverKeySwitch.deserialize(bytes); } } - export class DirectionKeySwitch extends pb_1.Message { + export class SwitchKeyChange extends pb_1.Message { #one_of_decls: number[][] = []; constructor(data?: any[] | { val?: number; @@ -1888,8 +1889,8 @@ export namespace request { } static fromObject(data: { val?: number; - }): DirectionKeySwitch { - const message = new DirectionKeySwitch({}); + }): SwitchKeyChange { + const message = new SwitchKeyChange({}); if (data.val != null) { message.val = data.val; } @@ -1913,8 +1914,8 @@ export namespace request { if (!w) return writer.getResultBuffer(); } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): DirectionKeySwitch { - const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new DirectionKeySwitch(); + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): SwitchKeyChange { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new SwitchKeyChange(); while (reader.nextField()) { if (reader.isEndGroup()) break; @@ -1930,8 +1931,8 @@ export namespace request { serializeBinary(): Uint8Array { return this.serialize(); } - static deserializeBinary(bytes: Uint8Array): DirectionKeySwitch { - return DirectionKeySwitch.deserialize(bytes); + static deserializeBinary(bytes: Uint8Array): SwitchKeyChange { + return SwitchKeyChange.deserialize(bytes); } } export class PushHandler extends pb_1.Message { diff --git a/src/stores/tcc-store.ts b/src/stores/tcc-store.ts index 67892f8..29c2497 100644 --- a/src/stores/tcc-store.ts +++ b/src/stores/tcc-store.ts @@ -85,7 +85,7 @@ export const useTccStore = defineStore('tcc', { trainId: this.tccId + '', deviceId: this.tccKeyDirId, controlType: request.TrainControl.TrainControlType.DIRECTION_KEY_SWITCH, - dirKey: { + switchKey: { val: position, }, }) From 1b855710056f0d2c342cfe5e3c5082350eaf0094 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 21 Aug 2024 18:23:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=A9=BE=E9=A9=B6=E5=8F=B0=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9=EF=BC=88=E5=BE=85?= =?UTF-8?q?=E4=B8=8E=E5=90=8E=E7=AB=AF=E6=B5=8B=E8=AF=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drawApp/graphics/TccKeyInteraction.ts | 8 +- src/drawApp/tccScene.ts | 8 +- src/protos/device_state.ts | 100 ++++++++++++---------- 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/src/drawApp/graphics/TccKeyInteraction.ts b/src/drawApp/graphics/TccKeyInteraction.ts index d8477c6..d5986dc 100644 --- a/src/drawApp/graphics/TccKeyInteraction.ts +++ b/src/drawApp/graphics/TccKeyInteraction.ts @@ -57,20 +57,20 @@ export class TccKeyData extends GraphicDataBase implements ITccKeyData { } export class TccKeyState extends GraphicStateBase implements ITccKeyState { - constructor(data?: state.TrainControlState.DirectionKeySwitch) { + constructor(data?: state.TrainControlState.SwitchKeyChange) { let tccKeyState; if (data) { tccKeyState = data; } else { - tccKeyState = new state.TrainControlState.DirectionKeySwitch(); + tccKeyState = new state.TrainControlState.SwitchKeyChange(); } super(tccKeyState, TccKey.Type); } get code(): string { return this.states.id + ''; } - get states(): state.TrainControlState.DirectionKeySwitch { - return this.getState(); + get states(): state.TrainControlState.SwitchKeyChange { + return this.getState(); } get position(): number { return this.states.val; diff --git a/src/drawApp/tccScene.ts b/src/drawApp/tccScene.ts index 093165d..b29b6b8 100644 --- a/src/drawApp/tccScene.ts +++ b/src/drawApp/tccScene.ts @@ -90,11 +90,11 @@ function handleSubscribe(tccScene: IGraphicScene) { storage?.buttons.forEach((button) => { states.push(new TccButtonState(button)); }); - if (storage.dirKey) { - states.push(new TccKeyState(storage.dirKey)); - } + storage?.switchKeys.forEach((switchKey) => { + states.push(new TccKeyState(switchKey)); + }); storage?.driverKey.forEach((driverKey) => { - const data = new state.TrainControlState.DirectionKeySwitch({ + const data = new state.TrainControlState.SwitchKeyChange({ id: driverKey.id, val: driverKey.val ? 1 : 0, }); diff --git a/src/protos/device_state.ts b/src/protos/device_state.ts index 551e1d2..a491e92 100644 --- a/src/protos/device_state.ts +++ b/src/protos/device_state.ts @@ -10614,7 +10614,7 @@ export namespace state { constructor(data?: any[] | { buttons?: Map; driverKey?: TrainControlState.DriverKeySwitch[]; - dirKey?: TrainControlState.DirectionKeySwitch; + switchKeyMap?: Map; pushHandler?: TrainControlState.PushHandler; lightMaps?: Map; lineInitTimeStamp12?: number; @@ -10629,8 +10629,8 @@ export namespace state { if ("driverKey" in data && data.driverKey != undefined) { this.driverKey = data.driverKey; } - if ("dirKey" in data && data.dirKey != undefined) { - this.dirKey = data.dirKey; + if ("switchKeyMap" in data && data.switchKeyMap != undefined) { + this.switchKeyMap = data.switchKeyMap; } if ("pushHandler" in data && data.pushHandler != undefined) { this.pushHandler = data.pushHandler; @@ -10647,6 +10647,8 @@ export namespace state { } if (!this.buttons) this.buttons = new Map(); + if (!this.switchKeyMap) + this.switchKeyMap = new Map(); if (!this.lightMaps) this.lightMaps = new Map(); } @@ -10662,14 +10664,11 @@ export namespace state { set driverKey(value: TrainControlState.DriverKeySwitch[]) { pb_1.Message.setRepeatedWrapperField(this, 2, value); } - get dirKey() { - return pb_1.Message.getWrapperField(this, TrainControlState.DirectionKeySwitch, 3) as TrainControlState.DirectionKeySwitch; + get switchKeyMap() { + return pb_1.Message.getField(this, 3) as any as Map; } - set dirKey(value: TrainControlState.DirectionKeySwitch) { - pb_1.Message.setWrapperField(this, 3, value); - } - get has_dirKey() { - return pb_1.Message.getField(this, 3) != null; + set switchKeyMap(value: Map) { + pb_1.Message.setField(this, 3, value as any); } get pushHandler() { return pb_1.Message.getWrapperField(this, TrainControlState.PushHandler, 4) as TrainControlState.PushHandler; @@ -10703,7 +10702,9 @@ export namespace state { [key: string]: ReturnType; }; driverKey?: ReturnType[]; - dirKey?: ReturnType; + switchKeyMap?: { + [key: string]: ReturnType; + }; pushHandler?: ReturnType; lightMaps?: { [key: string]: ReturnType; @@ -10718,8 +10719,8 @@ export namespace state { if (data.driverKey != null) { message.driverKey = data.driverKey.map(item => TrainControlState.DriverKeySwitch.fromObject(item)); } - if (data.dirKey != null) { - message.dirKey = TrainControlState.DirectionKeySwitch.fromObject(data.dirKey); + if (typeof data.switchKeyMap == "object") { + message.switchKeyMap = new Map(Object.entries(data.switchKeyMap).map(([key, value]) => [key, TrainControlState.SwitchKeyChange.fromObject(value)])); } if (data.pushHandler != null) { message.pushHandler = TrainControlState.PushHandler.fromObject(data.pushHandler); @@ -10741,7 +10742,9 @@ export namespace state { [key: string]: ReturnType; }; driverKey?: ReturnType[]; - dirKey?: ReturnType; + switchKeyMap?: { + [key: string]: ReturnType; + }; pushHandler?: ReturnType; lightMaps?: { [key: string]: ReturnType; @@ -10755,8 +10758,8 @@ export namespace state { if (this.driverKey != null) { data.driverKey = this.driverKey.map((item: TrainControlState.DriverKeySwitch) => item.toObject()); } - if (this.dirKey != null) { - data.dirKey = this.dirKey.toObject(); + if (this.switchKeyMap != null) { + data.switchKeyMap = (Object.fromEntries)((Array.from)(this.switchKeyMap).map(([key, value]) => [key, value.toObject()])); } if (this.pushHandler != null) { data.pushHandler = this.pushHandler.toObject(); @@ -10784,8 +10787,12 @@ export namespace state { } if (this.driverKey.length) writer.writeRepeatedMessage(2, this.driverKey, (item: TrainControlState.DriverKeySwitch) => item.serialize(writer)); - if (this.has_dirKey) - writer.writeMessage(3, this.dirKey, () => this.dirKey.serialize(writer)); + for (const [key, value] of this.switchKeyMap) { + writer.writeMessage(3, this.switchKeyMap, () => { + writer.writeString(1, key); + writer.writeMessage(2, value, () => value.serialize(writer)); + }); + } if (this.has_pushHandler) writer.writeMessage(4, this.pushHandler, () => this.pushHandler.serialize(writer)); for (const [key, value] of this.lightMaps) { @@ -10818,7 +10825,11 @@ export namespace state { reader.readMessage(message.driverKey, () => pb_1.Message.addToRepeatedWrapperField(message, 2, TrainControlState.DriverKeySwitch.deserialize(reader), TrainControlState.DriverKeySwitch)); break; case 3: - reader.readMessage(message.dirKey, () => message.dirKey = TrainControlState.DirectionKeySwitch.deserialize(reader)); + reader.readMessage(message, () => pb_1.Map.deserializeBinary(message.switchKeyMap as any, reader, reader.readString, () => { + let value; + reader.readMessage(message, () => value = TrainControlState.SwitchKeyChange.deserialize(reader)); + return value; + })); break; case 4: reader.readMessage(message.pushHandler, () => message.pushHandler = TrainControlState.PushHandler.deserialize(reader)); @@ -11029,7 +11040,7 @@ export namespace state { return DriverKeySwitch.deserialize(bytes); } } - export class DirectionKeySwitch extends pb_1.Message { + export class SwitchKeyChange extends pb_1.Message { #one_of_decls: number[][] = []; constructor(data?: any[] | { id?: number; @@ -11061,8 +11072,8 @@ export namespace state { static fromObject(data: { id?: number; val?: number; - }): DirectionKeySwitch { - const message = new DirectionKeySwitch({}); + }): SwitchKeyChange { + const message = new SwitchKeyChange({}); if (data.id != null) { message.id = data.id; } @@ -11095,8 +11106,8 @@ export namespace state { if (!w) return writer.getResultBuffer(); } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): DirectionKeySwitch { - const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new DirectionKeySwitch(); + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): SwitchKeyChange { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new SwitchKeyChange(); while (reader.nextField()) { if (reader.isEndGroup()) break; @@ -11115,8 +11126,8 @@ export namespace state { serializeBinary(): Uint8Array { return this.serialize(); } - static deserializeBinary(bytes: Uint8Array): DirectionKeySwitch { - return DirectionKeySwitch.deserialize(bytes); + static deserializeBinary(bytes: Uint8Array): SwitchKeyChange { + return SwitchKeyChange.deserialize(bytes); } } export class PushHandler extends pb_1.Message { @@ -11305,12 +11316,12 @@ export namespace state { constructor(data?: any[] | { buttons?: TrainControlState.ControlButton[]; driverKey?: TrainControlState.DriverKeySwitch[]; - dirKey?: TrainControlState.DirectionKeySwitch; + switchKeys?: TrainControlState.SwitchKeyChange[]; pushHandler?: TrainControlState.PushHandler; lights?: TrainControlState.ControlLight[]; }) { super(); - pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1, 2, 5], this.#one_of_decls); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1, 2, 3, 5], this.#one_of_decls); if (!Array.isArray(data) && typeof data == "object") { if ("buttons" in data && data.buttons != undefined) { this.buttons = data.buttons; @@ -11318,8 +11329,8 @@ export namespace state { if ("driverKey" in data && data.driverKey != undefined) { this.driverKey = data.driverKey; } - if ("dirKey" in data && data.dirKey != undefined) { - this.dirKey = data.dirKey; + if ("switchKeys" in data && data.switchKeys != undefined) { + this.switchKeys = data.switchKeys; } if ("pushHandler" in data && data.pushHandler != undefined) { this.pushHandler = data.pushHandler; @@ -11341,14 +11352,11 @@ export namespace state { set driverKey(value: TrainControlState.DriverKeySwitch[]) { pb_1.Message.setRepeatedWrapperField(this, 2, value); } - get dirKey() { - return pb_1.Message.getWrapperField(this, TrainControlState.DirectionKeySwitch, 3) as TrainControlState.DirectionKeySwitch; + get switchKeys() { + return pb_1.Message.getRepeatedWrapperField(this, TrainControlState.SwitchKeyChange, 3) as TrainControlState.SwitchKeyChange[]; } - set dirKey(value: TrainControlState.DirectionKeySwitch) { - pb_1.Message.setWrapperField(this, 3, value); - } - get has_dirKey() { - return pb_1.Message.getField(this, 3) != null; + set switchKeys(value: TrainControlState.SwitchKeyChange[]) { + pb_1.Message.setRepeatedWrapperField(this, 3, value); } get pushHandler() { return pb_1.Message.getWrapperField(this, TrainControlState.PushHandler, 4) as TrainControlState.PushHandler; @@ -11368,7 +11376,7 @@ export namespace state { static fromObject(data: { buttons?: ReturnType[]; driverKey?: ReturnType[]; - dirKey?: ReturnType; + switchKeys?: ReturnType[]; pushHandler?: ReturnType; lights?: ReturnType[]; }): TrainControlStateMsg { @@ -11379,8 +11387,8 @@ export namespace state { if (data.driverKey != null) { message.driverKey = data.driverKey.map(item => TrainControlState.DriverKeySwitch.fromObject(item)); } - if (data.dirKey != null) { - message.dirKey = TrainControlState.DirectionKeySwitch.fromObject(data.dirKey); + if (data.switchKeys != null) { + message.switchKeys = data.switchKeys.map(item => TrainControlState.SwitchKeyChange.fromObject(item)); } if (data.pushHandler != null) { message.pushHandler = TrainControlState.PushHandler.fromObject(data.pushHandler); @@ -11394,7 +11402,7 @@ export namespace state { const data: { buttons?: ReturnType[]; driverKey?: ReturnType[]; - dirKey?: ReturnType; + switchKeys?: ReturnType[]; pushHandler?: ReturnType; lights?: ReturnType[]; } = {}; @@ -11404,8 +11412,8 @@ export namespace state { if (this.driverKey != null) { data.driverKey = this.driverKey.map((item: TrainControlState.DriverKeySwitch) => item.toObject()); } - if (this.dirKey != null) { - data.dirKey = this.dirKey.toObject(); + if (this.switchKeys != null) { + data.switchKeys = this.switchKeys.map((item: TrainControlState.SwitchKeyChange) => item.toObject()); } if (this.pushHandler != null) { data.pushHandler = this.pushHandler.toObject(); @@ -11423,8 +11431,8 @@ export namespace state { writer.writeRepeatedMessage(1, this.buttons, (item: TrainControlState.ControlButton) => item.serialize(writer)); if (this.driverKey.length) writer.writeRepeatedMessage(2, this.driverKey, (item: TrainControlState.DriverKeySwitch) => item.serialize(writer)); - if (this.has_dirKey) - writer.writeMessage(3, this.dirKey, () => this.dirKey.serialize(writer)); + if (this.switchKeys.length) + writer.writeRepeatedMessage(3, this.switchKeys, (item: TrainControlState.SwitchKeyChange) => item.serialize(writer)); if (this.has_pushHandler) writer.writeMessage(4, this.pushHandler, () => this.pushHandler.serialize(writer)); if (this.lights.length) @@ -11445,7 +11453,7 @@ export namespace state { reader.readMessage(message.driverKey, () => pb_1.Message.addToRepeatedWrapperField(message, 2, TrainControlState.DriverKeySwitch.deserialize(reader), TrainControlState.DriverKeySwitch)); break; case 3: - reader.readMessage(message.dirKey, () => message.dirKey = TrainControlState.DirectionKeySwitch.deserialize(reader)); + reader.readMessage(message.switchKeys, () => pb_1.Message.addToRepeatedWrapperField(message, 3, TrainControlState.SwitchKeyChange.deserialize(reader), TrainControlState.SwitchKeyChange)); break; case 4: reader.readMessage(message.pushHandler, () => message.pushHandler = TrainControlState.PushHandler.deserialize(reader));