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 18 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
33 changes: 33 additions & 0 deletions lib/parsers/cctalk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
const Transform = require('stream').Transform;

module.exports = class CCTalkParser extends Transform {
constructor() {
super();
this.array = [];
}
_transform(buffer, _, cb) {
// TODO: Better Faster es7 no supported by node 4
const array = Array.prototype.slice.call(buffer, 0); // [...buffer];
Copy link
Member

Choose a reason for hiding this comment

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

Array.from(buffer)

but this seems weird that casting from a buffer to an array to a Uint8Array is the right way forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is because buffers don't support the needed methods they are really static we need a event chain so i choosed to go over to array

this.array.push(array);

// full frame accumulated
const FullMsgLength = this.array[1] + 5;
// console.log("FullMsgLength",FullMsgLength);

while (this.array.length > 1 && this.array.length >= FullMsgLength) {
// copy command from the array
const frame = new Uint8Array(FullMsgLength);
frame.set(this.array.slice(0, FullMsgLength));

if (this.array.length > FullMsgLength) { // Preserve Extra Data
this.array = this.array.slice(frame.length, this.array.length);
} else { // flush the array
this.array.length = 0;
}

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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The 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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/arduinoTest/stress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable node/no-missing-require */
/* eslint-disable node/no-missing-require, node/no-extraneous-require */
'use strict';

// `npm run stress` to run these tests
Expand Down
18 changes: 18 additions & 0 deletions test/parser-cctalk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'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('continues looking for bytes in additional writes', () => {
const parser = new CCTalkParser();
const spy = sinon.spy();
// parser.on('data', spy);
// parser.write(Buffer.from([1, 0, 2]));
// parser.write(Buffer.from([254, 217]));
});
// TODO: case crc message got data 2 bits
// TODO: case process remaining buffer
});