From 4a950283b3d8e0d0f5d329aeef71a9ce36e2f8b9 Mon Sep 17 00:00:00 2001 From: Sam Rang Date: Mon, 18 Apr 2016 22:01:41 -0500 Subject: [PATCH] implementation of UhkConfiguration --- .../config-items/UhkConfiguration.ts | 80 +++++++++++++------ config-serializer/test-serializer.ts | 6 +- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/config-serializer/config-items/UhkConfiguration.ts b/config-serializer/config-items/UhkConfiguration.ts index 192eab4a..805f93eb 100644 --- a/config-serializer/config-items/UhkConfiguration.ts +++ b/config-serializer/config-items/UhkConfiguration.ts @@ -1,53 +1,81 @@ class UhkConfiguration extends Serializable { + signature: string; + // @assertUInt8 - id: number; + dataModelVersion: number; - name: string; + // @assertUInt32 + prologue: number; - abbreviation: string; + // @assertUInt8 + hardwareId: number; - isDefault: boolean; + // @assertUInt8 + brandId: number; - layers: Serializable; + moduleConfigurations: Serializable; + + keyMaps: Serializable; + + macros: Serializable; + + // @assertUInt32 + epilogue: number; _fromJsObject(jsObject: any): UhkConfiguration { - this.id = jsObject.id; - this.isDefault = jsObject.isDefault; - this.abbreviation = jsObject.abbreviation; - this.name = jsObject.name; - this.layers = new Layers().fromJsObject(jsObject.layers); + this.signature = jsObject.signature; + this.dataModelVersion = jsObject.dataModelVersion; + this.prologue = jsObject.prologue; + this.hardwareId = jsObject.hardwareId; + this.brandId = jsObject.brandId; + this.moduleConfigurations = new ModuleConfigurations().fromJsObject(jsObject.moduleConfigurations); + this.keyMaps = new KeyMaps().fromJsObject(jsObject.keyMaps); + this.macros = new Macros().fromJsObject(jsObject.macros); + this.epilogue = jsObject.epilogue; return this; } _fromBinary(buffer: UhkBuffer): UhkConfiguration { - this.id = buffer.readUInt8(); - this.isDefault = buffer.readBoolean(); - this.abbreviation = buffer.readString(); - this.name = buffer.readString(); - this.layers = new Layers().fromBinary(buffer); + this.signature = buffer.readString(); + this.dataModelVersion = buffer.readUInt8(); + this.prologue = buffer.readUInt32(); + this.hardwareId = buffer.readUInt8(); + this.brandId = buffer.readUInt8(); + this.moduleConfigurations = new ModuleConfigurations().fromBinary(buffer); + this.keyMaps = new KeyMaps().fromBinary(buffer); + this.macros = new Macros().fromBinary(buffer); + this.epilogue = buffer.readUInt32(); return this; } _toJsObject(): any { return { - id: this.id, - isDefault: this.isDefault, - abbreviation: this.abbreviation, - name: this.name, - layers: this.layers.toJsObject() + signature: this.signature, + dataModelVersion: this.dataModelVersion, + prologue: this.prologue, + hardwareId: this.hardwareId, + brandId: this.brandId, + moduleConfigurations: this.moduleConfigurations.toJsObject(), + keyMaps: this.keyMaps.toJsObject(), + macros: this.macros.toJsObject(), + epilogue: this.epilogue }; } _toBinary(buffer: UhkBuffer): void { - buffer.writeUInt8(this.id); - buffer.writeBoolean(this.isDefault); - buffer.writeString(this.abbreviation); - buffer.writeString(this.name); - this.layers.toBinary(buffer); + buffer.writeString(this.signature); + buffer.writeUInt8(this.dataModelVersion); + buffer.writeUInt32(this.prologue); + buffer.writeUInt8(this.hardwareId); + buffer.writeUInt8(this.brandId); + this.moduleConfigurations.toBinary(buffer); + this.keyMaps.toBinary(buffer); + this.macros.toBinary(buffer); + buffer.writeUInt32(this.epilogue); } toString(): string { - return ``; + return ``; } } diff --git a/config-serializer/test-serializer.ts b/config-serializer/test-serializer.ts index a02acef0..b1a5aa23 100644 --- a/config-serializer/test-serializer.ts +++ b/config-serializer/test-serializer.ts @@ -10,8 +10,8 @@ let fs = require('fs'); let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json')); -let config1Js = uhkConfig.moduleConfigurations; -let config1Ts: Serializable = new ModuleConfigurations().fromJsObject(config1Js); +let config1Js = uhkConfig; +let config1Ts: Serializable = new UhkConfiguration().fromJsObject(config1Js); let config1Buffer = new UhkBuffer(); config1Ts.toBinary(config1Buffer); let config1BufferContent = config1Buffer.getBufferContent(); @@ -19,7 +19,7 @@ fs.writeFileSync('uhk-config.bin', config1BufferContent); config1Buffer.offset = 0; console.log(); -let config2Ts = new ModuleConfigurations().fromBinary(config1Buffer); +let config2Ts = new UhkConfiguration().fromBinary(config1Buffer); console.log('\n'); let config2Js = config2Ts.toJsObject(); let config2Buffer = new UhkBuffer();