-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cctalk parsers #1342
Merged
Merged
Add cctalk parsers #1342
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
de63a9b
Added Working CCTalk Parser
frank-dspeed 7e6f6e8
Added Working CCTalk Parser
frank-dspeed 50c7ec9
Apply ESLint Rule SET
frank-dspeed e498b84
Improved Const Position and Name for Reading
frank-dspeed c590021
chore(packages): upgrade eslint and sinon (#1343)
reconbot 401bd30
Remove not needed debug
frank-dspeed b41b161
add basic test
frank-dspeed 21b5ba3
Added Working CCTalk Parser
frank-dspeed d99dcdd
Added Working CCTalk Parser
frank-dspeed 0659493
Apply ESLint Rule SET
frank-dspeed 00e25bb
Improved Const Position and Name for Reading
frank-dspeed 604198d
Remove not needed debug
frank-dspeed 897d530
add basic test
frank-dspeed 6ce2e77
Merge branch 'add_cctalk_parsers' of https://github.com/direktspeed/n…
frank-dspeed d421232
Deprecating buffer.set Hope God will allow that
frank-dspeed 2b00ea9
New Version array based
frank-dspeed fcdd6d6
New Version array based faster
frank-dspeed cf972f4
Disable tests
frank-dspeed b0f9311
Fix Flatten Array
frank-dspeed 9fa9817
Fixed: parser and Tests also updated to use array
frank-dspeed cd5d899
Fixed: parser and Tests also updated to use array
frank-dspeed e43809c
Fixed: parser and Tests also updated to use array
frank-dspeed 72f078a
Fixed: parser and Tests also updated to use array
frank-dspeed a48513c
Fixed: parser and Tests also updated to use array
frank-dspeed 926f893
Fixed: node < 6
frank-dspeed d0fb367
Finish: written basic documentation
frank-dspeed d5bfcfa
Fix: written basic documentation
frank-dspeed 7382fe4
compiled docs for cctalk parser
frank-dspeed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
const Transform = require('stream').Transform; | ||
const Buffer = require('safe-buffer').Buffer; | ||
|
||
module.exports = class CCTalkParser extends Transform { | ||
constructor() { | ||
super(); | ||
this.array = []; | ||
this.cursor = 0; | ||
} | ||
_transform(buffer, _, cb) { | ||
this.cursor += buffer.length; | ||
// TODO: Better Faster es7 no supported by node 4 | ||
// ES7 allows directly push [...buffer] | ||
// this.array = this.array.concat(Array.from(buffer)); //Slower ?!? | ||
Array.from(buffer) | ||
.map((byte) => this.array.push(byte)); | ||
while (this.cursor > 1 && this.cursor >= this.array[1] + 5) { | ||
// full frame accumulated | ||
// copy command from the array | ||
const FullMsgLength = this.array[1] + 5; | ||
|
||
const frame = Buffer.from(this.array.slice(0, FullMsgLength)); | ||
// Preserve Extra Data | ||
this.array = this.array.slice(frame.length, this.array.length); | ||
this.cursor -= FullMsgLength; | ||
this.push(frame); | ||
} | ||
cb(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ | |
"chai": "^4.0.2", | ||
"chai-subset": "^1.5.0", | ||
"conventional-changelog-cli": "^1.3.2", | ||
"eslint": "^4.5.0", | ||
"eslint": "^4.7.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is so weird, we totally have this in master |
||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.7.0", | ||
"eslint-plugin-node": "^5.1.0", | ||
|
@@ -82,7 +82,7 @@ | |
"mocha": "^3.4.2", | ||
"prebuild": "^6.2.1", | ||
"proxyquire": "^1.7.10", | ||
"sinon": "^3.2.1" | ||
"sinon": "^3.3.0" | ||
}, | ||
"engines": { | ||
"node": ">=4.0.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
/* eslint-disable no-new */ | ||
|
||
const Buffer = require('safe-buffer').Buffer; | ||
const sinon = require('sinon'); | ||
const CCTalkParser = require('../lib/parsers/cctalk'); | ||
|
||
describe('CCTalkParser', () => { | ||
it('emits data for a default length message', () => { | ||
const data = Buffer.from([2, 0, 1, 254, 217]); | ||
const spy = sinon.spy(); | ||
const parser = new CCTalkParser(); | ||
parser.on('data', spy); | ||
parser.write(data); | ||
assert.equal(spy.callCount, 1); | ||
assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 0, 1, 254, 217])); | ||
}); | ||
|
||
it('emits data for a 7 byte length message', () => { | ||
const parser = new CCTalkParser(); | ||
const spy = sinon.spy(); | ||
parser.on('data', spy); | ||
parser.write(Buffer.from([2, 2, 1, 254, 1, 1, 217])); | ||
assert.equal(spy.callCount, 1); | ||
assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 2, 1, 254, 1, 1, 217])); | ||
}); | ||
|
||
it('emits 2 times data first length 7 secund length 5', () => { | ||
const parser = new CCTalkParser(); | ||
const spy = sinon.spy(); | ||
parser.on('data', spy); | ||
parser.write(Buffer.from([2, 2, 1])); | ||
parser.write(Buffer.from([254, 1, 1])); | ||
parser.write(Buffer.from([217, 2])); | ||
parser.write(Buffer.from([0, 1, 254, 217])); | ||
assert.equal(spy.callCount, 2); | ||
assert.deepEqual(spy.getCall(0).args[0], Buffer.from([2, 2, 1, 254, 1, 1, 217])); | ||
assert.deepEqual(spy.getCall(1).args[0], Buffer.from([2, 0, 1, 254, 217])); | ||
}); | ||
}); | ||
// TODO: parser.write(Buffer.from([2, 2, 1, 254, 1, 1, 217, 2, 0, 1, 254, 217, 2, 2, 1, 251, 1, 1, 217, 2, 2, 1, 252, 1, 1, 217, 2, 0, 1, 253, 217])); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some docs up here ☝️