// Запсиь опций файла
const upload = multer({ storage: storage });
app.use(bodyParser.json({ limit: "10mb" }));
app.use(bodyParser.urlencoded({ limit: "10mb", extended: true, parameterLimit: 1000000 }));
app.use(
// Путь подключения
`/up/*`,
// Путь записи файла
//upload.single('file'),
upload.fields([
{name: 'file'}
]),
/**
* crc16Modus
* @class crc16MODBUS
*/
'use strict';
class crc16MODBUS {
constructor() {
this.CRCMaster = {
StringToCheck: "",
CleanedString: "",
CleanString: function(inputType) {
if (inputType == "ASCII") {
this.CleanedString = this.StringToCheck;
} else {
if (this.StringToCheck.match(/^[0-9A-F \t]+$/gi) !== null) {
this.CleanedString = this._hexStringToString(this.StringToCheck.toUpperCase().replace(/[\t ]/g, ''));
} else {
console.log("String doesn't seem to be a valid Hex input.");
return false;
}
}
return true;
},
CRC16Modbus: function() {
var crc = 0xFFFF;
var str = this.CleanedString;
for (var pos = 0; pos < str.length; pos++) {
crc ^= str.charCodeAt(pos);
for (var i = 8; i !== 0; i--) {
if ((crc & 0x0001) !== 0) {
crc >>= 1;
crc ^= 0xA001;
} else
crc >>= 1;
}
}
return crc;
},
_hexStringToString: function(inputstr) {
var hex = inputstr.toString(); //force conversion
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
},
Calculate: function(str, inputType) {
this.StringToCheck = str;
if (this.CleanString(inputType)) {
return this.CRC16Modbus().toString(16).toUpperCase()
}
}
};
}
/**
* Расчет контрольной суммы
* @method transformationCRC16
*/
transformationCRC16( str ) {
return this.CRCMaster.Calculate( str, 'HEX' )
}
}
module.exports = crc16MODBUS
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'OHAI> '
});
rl.prompt();
rl.on('line', (line) => {
switch (line.trim()) {
case 'hello':
console.log('world!');
break;
default:
console.log(`Say what? I might have heard '${line.trim()}'`);
break;
}
rl.prompt();
}).on('close', () => {
console.log('Have a great day!');
process.exit(0);
});
async function processLineByLine() {
var array = await unloadExistOperator(), temp = Array();
const lineReader = require('readline').createInterface({
input: require('fs').createReadStream(tempCatalog+fileDEF)
});
for await (const line of lineReader) {
var list = line.split(';'), operator = list[4].replace(/['"«»]/g, '');
if( array.indexOf( operator ) == -1 && temp.indexOf( operator ) == -1 )
{
temp.push( operator );
console.log(list[4])
}
}
}