Skip to content
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 28 commits into from
Oct 1, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
de63a9b
Added Working CCTalk Parser
frank-dspeed Sep 22, 2017
7e6f6e8
Added Working CCTalk Parser
frank-dspeed Sep 22, 2017
50c7ec9
Apply ESLint Rule SET
frank-dspeed Sep 22, 2017
e498b84
Improved Const Position and Name for Reading
frank-dspeed Sep 22, 2017
c590021
chore(packages): upgrade eslint and sinon (#1343)
reconbot Sep 22, 2017
401bd30
Remove not needed debug
frank-dspeed Sep 23, 2017
b41b161
add basic test
frank-dspeed Sep 23, 2017
21b5ba3
Added Working CCTalk Parser
frank-dspeed Sep 22, 2017
d99dcdd
Added Working CCTalk Parser
frank-dspeed Sep 22, 2017
0659493
Apply ESLint Rule SET
frank-dspeed Sep 22, 2017
00e25bb
Improved Const Position and Name for Reading
frank-dspeed Sep 22, 2017
604198d
Remove not needed debug
frank-dspeed Sep 23, 2017
897d530
add basic test
frank-dspeed Sep 23, 2017
6ce2e77
Merge branch 'add_cctalk_parsers' of https://github.com/direktspeed/n…
frank-dspeed Sep 24, 2017
d421232
Deprecating buffer.set Hope God will allow that
frank-dspeed Sep 24, 2017
2b00ea9
New Version array based
frank-dspeed Sep 24, 2017
fcdd6d6
New Version array based faster
frank-dspeed Sep 24, 2017
cf972f4
Disable tests
frank-dspeed Sep 24, 2017
b0f9311
Fix Flatten Array
frank-dspeed Sep 24, 2017
9fa9817
Fixed: parser and Tests also updated to use array
frank-dspeed Sep 25, 2017
cd5d899
Fixed: parser and Tests also updated to use array
frank-dspeed Sep 25, 2017
e43809c
Fixed: parser and Tests also updated to use array
frank-dspeed Sep 25, 2017
72f078a
Fixed: parser and Tests also updated to use array
frank-dspeed Sep 25, 2017
a48513c
Fixed: parser and Tests also updated to use array
frank-dspeed Sep 25, 2017
926f893
Fixed: node < 6
frank-dspeed Sep 25, 2017
d0fb367
Finish: written basic documentation
frank-dspeed Sep 25, 2017
d5bfcfa
Fix: written basic documentation
frank-dspeed Sep 25, 2017
7382fe4
compiled docs for cctalk parser
frank-dspeed Sep 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/parsers/cctalk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
const Buffer = require('safe-buffer').Buffer;
const Transform = require('stream').Transform;

const MAX_PACKET_LENGTH = 255 + 5;
const debug = require('debug');

module.exports = class ccTalkParser extends Transform {
constructor() {
super();
this.buffer = Buffer.alloc(MAX_PACKET_LENGTH); // maxium ccTalkMessage length
this.cursor = 0;
}
_transform(buffer, _, cb) {
debug('parser set')(this.buffer, this.cursor);
debug('parser set')(this.buffer.toString('hex'), buffer.buffer, this.cursor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd either push this into a conditional debug.enabled or use a custom formatter so toString doesn't get called when not debugging.


this.buffer.set(buffer, this.cursor);
this.cursor += buffer.length;
// full frame accumulated
const length = this.buffer[1] + 5;
debug('parse befor loop')(buffer, this.cursor);

while (this.cursor > 1 && this.cursor >= length) {
// console.log("length", length);

// copy command from the buffer
const frame = new Uint8Array(length);
frame.set(this.buffer.slice(0, length));

// copy remaining buffer to the begin of the buffer to prepare for next command
this.buffer.set(this.buffer.slice(length, this.cursor));
this.cursor -= length;
debug('parse push', frame, this.buffer, this.cursor);
this.push(frame);
}
cb();
}
};
1 change: 1 addition & 0 deletions lib/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ parser.on('data', console.log);

Copy link
Member

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 ☝️

module.exports = {
ByteLength: require('./byte-length'),
CCTalk: require('./cctalk'),
Delimiter: require('./delimiter'),
Readline: require('./readline'),
Ready: require('./ready'),
Expand Down