feat(config): Read / write hardware configuration area (#423)
* add write-hca.js * refactor: Move config serializer into the uhk-common package * refactor: Move getTransferBuffers into the uhk-usb package * refactor: delete obsoleted classes * build: add uhk-usb build command * refactor: move eeprom transfer to uhk-usb package * fix: Fix write-hca.js * feat: load hardware config from the device and * style: fix ts lint errors * build: fix rxjs dependency resolve * test: Add jasmine unit test framework to the tet serializer * fix(user-config): A "type": "basic", properties to the "keystroke" action types * feat(usb): set chmod+x on write-hca.js * feat(usb): Create USB logger * style: Fix type * build: Add chalk to dependencies. Chalk will colorize the output
This commit is contained in:
committed by
László Monda
parent
1122784bdb
commit
9294bede50
7
packages/test-serializer/.gitignore
vendored
7
packages/test-serializer/.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
uhk-config.bin
|
||||
uhk-config-serialized.json
|
||||
uhk-config-serialized.bin
|
||||
test-serializer.js
|
||||
user-config.bin
|
||||
user-config-serialized.json
|
||||
user-config-serialized.bin
|
||||
|
||||
8
packages/test-serializer/jasmine.json
Normal file
8
packages/test-serializer/jasmine.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"spec_dir": "spec",
|
||||
"spec_files": [
|
||||
"**/*[sS]pec.ts"
|
||||
],
|
||||
"stopSpecOnExpectationFailure": true,
|
||||
"random": false
|
||||
}
|
||||
1029
packages/test-serializer/package-lock.json
generated
Normal file
1029
packages/test-serializer/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,10 +16,16 @@
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"uhk-web": "^1.0.0"
|
||||
"@types/jasmine": "^2.6.0",
|
||||
"@types/node": "8.0.30",
|
||||
"jasmine": "^2.8.0",
|
||||
"jasmine-core": "^2.8.0",
|
||||
"jasmine-node": "2.0.0",
|
||||
"jasmine-ts": "^0.2.1",
|
||||
"ts-node": "3.3.0",
|
||||
"uhk-common": "1.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"test": "node ./test-serializer.js"
|
||||
"test": "jasmine-ts --config=jasmine.json"
|
||||
}
|
||||
}
|
||||
|
||||
33
packages/test-serializer/spec/test-serializer.spec.ts
Normal file
33
packages/test-serializer/spec/test-serializer.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { UhkBuffer, UserConfiguration } from '../../uhk-common/index';
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const userConfig = JSON.parse(fs.readFileSync('../uhk-web/src/app/services/user-config.json'));
|
||||
|
||||
describe('Test Serializer', () => {
|
||||
it('full config match', () => {
|
||||
const config1Js = userConfig;
|
||||
const config1Ts: UserConfiguration = new UserConfiguration().fromJsonObject(config1Js);
|
||||
const config1Buffer = new UhkBuffer();
|
||||
config1Ts.toBinary(config1Buffer);
|
||||
const config1BufferContent = config1Buffer.getBufferContent();
|
||||
fs.writeFileSync('user-config.bin', config1BufferContent);
|
||||
|
||||
config1Buffer.offset = 0;
|
||||
console.log();
|
||||
const config2Ts = new UserConfiguration().fromBinary(config1Buffer);
|
||||
console.log('\n');
|
||||
const config2Js = config2Ts.toJsonObject();
|
||||
const config2Buffer = new UhkBuffer();
|
||||
config2Ts.toBinary(config2Buffer);
|
||||
fs.writeFileSync('user-config-serialized.json', JSON.stringify(config2Js, undefined, 4));
|
||||
const config2BufferContent = config1Buffer.getBufferContent();
|
||||
fs.writeFileSync('user-config-serialized.bin', config2BufferContent);
|
||||
|
||||
expect(config1Js).toEqual(config2Js);
|
||||
|
||||
const buffersContentsAreEqual: boolean = Buffer.compare(config1BufferContent, config2BufferContent) === 0;
|
||||
expect(buffersContentsAreEqual).toBe(true);
|
||||
|
||||
});
|
||||
});
|
||||
@@ -1,45 +0,0 @@
|
||||
import { UserConfiguration } from '../uhk-web/src/app/config-serializer/config-items/user-configuration';
|
||||
import { UhkBuffer } from '../uhk-web/src/app/config-serializer/uhk-buffer';
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
|
||||
const userConfig = JSON.parse(fs.readFileSync('../uhk-web/src/app/config-serializer/user-config.json'));
|
||||
|
||||
const config1Js = userConfig;
|
||||
const config1Ts: UserConfiguration = new UserConfiguration().fromJsonObject(config1Js);
|
||||
const config1Buffer = new UhkBuffer();
|
||||
config1Ts.toBinary(config1Buffer);
|
||||
const config1BufferContent = config1Buffer.getBufferContent();
|
||||
fs.writeFileSync('user-config.bin', config1BufferContent);
|
||||
|
||||
config1Buffer.offset = 0;
|
||||
console.log();
|
||||
const config2Ts = new UserConfiguration().fromBinary(config1Buffer);
|
||||
console.log('\n');
|
||||
const config2Js = config2Ts.toJsonObject();
|
||||
const config2Buffer = new UhkBuffer();
|
||||
config2Ts.toBinary(config2Buffer);
|
||||
fs.writeFileSync('user-config-serialized.json', JSON.stringify(config2Js, undefined, 4));
|
||||
const config2BufferContent = config1Buffer.getBufferContent();
|
||||
fs.writeFileSync('user-config-serialized.bin', config2BufferContent);
|
||||
|
||||
console.log('\n');
|
||||
let returnValue = 0;
|
||||
try {
|
||||
assert.deepEqual(config1Js, config2Js);
|
||||
console.log('JSON configurations are identical.');
|
||||
} catch (error) {
|
||||
console.log('JSON configurations differ.');
|
||||
returnValue = 1;
|
||||
}
|
||||
|
||||
const buffersContentsAreEqual: boolean = Buffer.compare(config1BufferContent, config2BufferContent) === 0;
|
||||
if (buffersContentsAreEqual) {
|
||||
console.log('Binary configurations are identical.');
|
||||
} else {
|
||||
console.log('Binary configurations differ.');
|
||||
returnValue += 2;
|
||||
}
|
||||
|
||||
process.exit(returnValue);
|
||||
@@ -5,10 +5,7 @@
|
||||
"moduleResolution": "node",
|
||||
"experimentalDecorators": true,
|
||||
"typeRoots": [
|
||||
"../node_modules/@types"
|
||||
],
|
||||
"types": [
|
||||
"node"
|
||||
"./node_modules/@types"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Reference in New Issue
Block a user