* 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
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
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);
|
|
|
|
});
|
|
});
|