2018-07-01 13:37:23 +02:00
|
|
|
const crc = require("./crc.js");
|
2018-07-01 15:27:15 +02:00
|
|
|
const message = process.argv[3];
|
|
|
|
const flag = process.argv[2];
|
|
|
|
|
2018-07-01 13:37:23 +02:00
|
|
|
switch (flag) {
|
|
|
|
case '-e':
|
2018-07-01 15:14:54 +02:00
|
|
|
console.log(crc.encode(message).encoded);
|
2018-07-01 13:37:23 +02:00
|
|
|
break;
|
|
|
|
case '-d':
|
2018-07-01 15:14:54 +02:00
|
|
|
let fcs = JSON.parse(process.argv[4].replace(/'/g, '"'));
|
|
|
|
console.log(crc.decode(message, fcs));
|
|
|
|
break;
|
|
|
|
case '-t':
|
2018-07-01 15:17:50 +02:00
|
|
|
let res = crc.encode(message);
|
|
|
|
console.log(res.encoded);
|
|
|
|
console.log(crc.decode(message, res.FCS))
|
2018-07-01 13:37:23 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw "incorect flag"
|
|
|
|
}
|