Skip to content

Commit

Permalink
feat(parser): Add getImei
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Aug 30, 2016
1 parent 1e97897 commit 0675e75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,21 @@ const getRebootCommand = imei => {
return getCommand(imei, 'F02');
};

const getImei = raw => {
let imei = null;
const data = raw.toString();
if (patterns.mvt380.test(data)) {
imei = patterns.mvt380.exec(data)[3];
}
return imei;
};

module.exports = {
parse: parse,
patterns: patterns,
getMvt380: getMvt380,
isMeitrack: isMeitrack,
parseCommand: parseCommand,
getRebootCommand: getRebootCommand
getRebootCommand: getRebootCommand,
getImei: getImei
};
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,16 @@ describe('meitrack-parser', () => {
const data = meitrack.getRebootCommand(353358017784062);
expect(data).to.match(/^@@([\x41-\x7A])(\d{1,3}),353358017784062,F02\*([0-9A-F]{2})\r\n$/);
});

it('should return null imei', () => {
const raw = new Buffer('askdhaskjdhakjdhaksjdhaksjdh');
const imei = meitrack.getImei(raw);
expect(imei).to.be.null;
});

it('should return MVT380 imei', () => {
const raw = new Buffer('$$e155,867965021508656,AAA,35,-33.361133,-70.514245,160412155005,A,8,27,0,289,1.3,867,318379,2338885,730|1|32D3|A03F,0008,0000|0000|0000|02DA|0106,00000001,*3A\r\n');
const imei = meitrack.getImei(raw);
expect(imei).to.eql('867965021508656');
});
});

0 comments on commit 0675e75

Please sign in to comment.