This commit is contained in:
parent
d30e157420
commit
036b54ae97
|
@ -6,7 +6,7 @@
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon ./server.js"
|
"start": "nodemon ./server.js | pino-pretty "
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18",
|
"node": ">=18",
|
||||||
|
|
|
@ -7,10 +7,10 @@ console.logger = logger();
|
||||||
|
|
||||||
async function main(arcId) {
|
async function main(arcId) {
|
||||||
const conf = getConfig();
|
const conf = getConfig();
|
||||||
|
|
||||||
for (let arc of await getArcs()) {
|
for (let arc of await getArcs()) {
|
||||||
const config = Object.assign({}, conf, arc);
|
const config = Object.assign({}, conf, arc);
|
||||||
if (arcId && arcId != arc.arcId) continue;
|
if (arcId && arcId != arc.arcId) continue;
|
||||||
|
console.logger.info(`ARC_ID:${config.arcId} is running...`);
|
||||||
stream(config, e => {
|
stream(config, e => {
|
||||||
console.logger.error(e);
|
console.logger.error(e);
|
||||||
setTimeout(main, config.reconnectInterval, config.arcId);
|
setTimeout(main, config.reconnectInterval, config.arcId);
|
||||||
|
|
|
@ -1,29 +1,48 @@
|
||||||
|
import con from '../db/connect.js';
|
||||||
|
|
||||||
export default async data => {
|
export default async data => {
|
||||||
|
const palletFkFinding = 0;
|
||||||
|
const attempt = 0;
|
||||||
|
const sensitivity = null;
|
||||||
|
|
||||||
data = data.toString();
|
data = data.toString();
|
||||||
const crudeRfids = data.split('\n');
|
const crudeRfids = data.split('\n');
|
||||||
|
|
||||||
const rfidsParsed = new Set();
|
const rfidsParsed = new Set();
|
||||||
const rfidsParsedExtended = [];
|
const rfidsParsedExtended = [];
|
||||||
|
const RFID_PREFIX = 'AABB';
|
||||||
for (let crudeRfid of crudeRfids) {
|
for (let crudeRfid of crudeRfids) {
|
||||||
if (crudeRfid && /{.*:{.*:.*}}/.test(crudeRfid)) {
|
if (crudeRfid && /{.*:{.*:.*}}/.test(crudeRfid)) {
|
||||||
const jsonResult = JSON.parse(crudeRfid);
|
const jsonResult = JSON.parse(crudeRfid);
|
||||||
let epcHex = jsonResult?.tagInventoryEvent?.epcHex;
|
let epcHex = jsonResult?.tagInventoryEvent?.epcHex;
|
||||||
|
|
||||||
if (!epcHex) continue;
|
if (!epcHex) continue;
|
||||||
if (epcHex.search('AABB') == -1) continue;
|
if (epcHex.search(RFID_PREFIX) == -1) continue;
|
||||||
|
|
||||||
epcHex = epcHex.replace('AABB', '');
|
epcHex = epcHex.replace(RFID_PREFIX, '');
|
||||||
epcHex = epcHex.substring(0, 1) == 0 ? epcHex.substring(1) : epcHex;
|
epcHex = epcHex.substring(0, 1) == 0 ? epcHex.substring(1) : epcHex;
|
||||||
|
// console.log(jsonResult);
|
||||||
const rfidParsed = {
|
const rfidParsed = {
|
||||||
code: parseInt(epcHex),
|
code: parseInt(epcHex),
|
||||||
created: jsonResult.timestamp,
|
created: jsonResult.timestamp,
|
||||||
peakRssi: jsonResult.tagInventoryEvent.peakRssiCdbm,
|
peakRssi: jsonResult.tagInventoryEvent.peakRssiCdbm,
|
||||||
count: 1,
|
count: 1,
|
||||||
antenna: jsonResult.tagInventoryEvent.antennaPort
|
antenna: jsonResult.tagInventoryEvent.antennaPort,
|
||||||
|
transmitPowerCdbm: jsonResult.tagInventoryEvent.transmitPowerCdbm
|
||||||
};
|
};
|
||||||
|
await con.query(`
|
||||||
const rfidsParsedExtended = [];
|
INSERT INTO vn.rfidTest (palletFk, expeditionFk, peakRssi, antenna, attempt, power, sensitivity)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?, ?);
|
||||||
|
`, [
|
||||||
|
palletFkFinding,
|
||||||
|
rfidParsed.code,
|
||||||
|
rfidParsed.peakRssi,
|
||||||
|
rfidParsed.antenna,
|
||||||
|
attempt,
|
||||||
|
jsonResult.tagInventoryEvent.transmitPowerCdbm,
|
||||||
|
sensitivity
|
||||||
|
]);
|
||||||
|
// console.log(rfidParsed);
|
||||||
rfidsParsedExtended.push(rfidParsed);
|
rfidsParsedExtended.push(rfidParsed);
|
||||||
rfidsParsed.add(rfidParsed.code);
|
rfidsParsed.add(rfidParsed.code);
|
||||||
}
|
}
|
||||||
|
@ -31,3 +50,4 @@ export default async data => {
|
||||||
|
|
||||||
return {codes: rfidsParsed, extended: rfidsParsedExtended};
|
return {codes: rfidsParsed, extended: rfidsParsedExtended};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,10 @@ export default async(conf, cb) => {
|
||||||
function createPallet() {
|
function createPallet() {
|
||||||
clearTimeout(interval);
|
clearTimeout(interval);
|
||||||
|
|
||||||
if (!conf.minimum || rfidbuffer.size > conf.minimum)
|
// if (!conf.minimum || rfidbuffer.size > conf.minimum)
|
||||||
newPallet(rfidbuffer, conf.arcId);
|
// newPallet(rfidbuffer, conf.arcId);
|
||||||
|
// rfidbuffer = new Set();
|
||||||
rfidbuffer = new Set();
|
// rfidbufferExtend = [];
|
||||||
rfidbufferExtend = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function counterIntervalManager() {
|
function counterIntervalManager() {
|
||||||
|
|
|
@ -1,25 +1,107 @@
|
||||||
export default (parsed, conf) => {
|
import con from '../db/connect.js';
|
||||||
|
|
||||||
|
export default async(parsed, conf) => {
|
||||||
|
const palletFkFinding = 0;
|
||||||
|
const attempt = 0;
|
||||||
|
|
||||||
if (conf.env != 'dev') return;
|
if (conf.env != 'dev') return;
|
||||||
// TOTAL
|
// TOTAL
|
||||||
console.log('TOTAL BUFFER: ', parsed.codes.size);
|
// console.log('TOTAL BUFFER: ', parsed.codes.size);
|
||||||
|
// console.log('BUFFER: ', parsed.codes);
|
||||||
|
// console.log('BUFFER_EXTEND: ', parsed);
|
||||||
|
|
||||||
// TOTAL READS BY ANTENNA
|
// TOTAL READS BY ANTENNA
|
||||||
const totalRead = [0, 0, 0, 0];
|
const totalRead = [0, 0, 0, 0];
|
||||||
for (let read of parsed.extended)
|
for (let read of parsed.extended)
|
||||||
totalRead[read.antenna - 1]++;
|
totalRead[read.antenna - 1]++;
|
||||||
console.log('TOTAL READ ANTENNA:', totalRead);
|
console.log('TOTAL READ ANTENNA:', totalRead);
|
||||||
|
|
||||||
// UNIQUE READS BY ANTENNA
|
// UNIQUE READS BY ANTENNA
|
||||||
const uniqueRead = [new Set(), new Set(), new Set(), new Set()];
|
const uniqueRead = [new Set(), new Set(), new Set(), new Set()];
|
||||||
for (let read of parsed.extended)
|
for (let read of parsed.extended)
|
||||||
uniqueRead[read.antenna - 1].add(read.code);
|
uniqueRead[read.antenna - 1].add(read.code);
|
||||||
|
|
||||||
console.log('UNIQUE READ ANTENNA:', uniqueRead[0].size, uniqueRead[1].size, uniqueRead[2].size, uniqueRead[3].size);
|
console.log('UNIQUE READ ANTENNA:', uniqueRead[0].size, uniqueRead[1].size, uniqueRead[2].size, uniqueRead[3].size);
|
||||||
|
|
||||||
// WARNING IF AN ANTENNA READS LESS THAN IT SHOULD
|
// console.log(uniqueRead[0], uniqueRead[1]);
|
||||||
for (const [index, set] of uniqueRead.entries()) {
|
// console.log(uniqueRead[2], uniqueRead[3]);
|
||||||
if (((set.size * 100) / parsed.codes.size) < 25)
|
|
||||||
console.logger.warn(`[ANTENNA]: ${index + 1} ONLY ${set.size}`);
|
// AL QUAD
|
||||||
}
|
let quad1 = [...uniqueRead[0]].filter(value => uniqueRead[1].has(value));
|
||||||
|
let quad2 = [...uniqueRead[2]].filter(value => uniqueRead[3].has(value));
|
||||||
|
const quad = quad1.filter(value => new Set(quad2).has(value));
|
||||||
|
console.log('UNIQUE READ QUAD:', quad.length);
|
||||||
|
await con.query(`
|
||||||
|
INSERT INTO vn.algorithm (palletFk, attempt, expeditionArray, expeditionCount, model, power)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?);
|
||||||
|
`, [
|
||||||
|
palletFkFinding,
|
||||||
|
attempt,
|
||||||
|
quad.join(','),
|
||||||
|
quad.length,
|
||||||
|
'QUAD',
|
||||||
|
quad[0]?.transmitPowerCdbm
|
||||||
|
]);
|
||||||
|
|
||||||
|
// AL TRI
|
||||||
|
let tri1 = [...uniqueRead[1]];
|
||||||
|
let tri2 = [...uniqueRead[2]].filter(value => uniqueRead[3].has(value));
|
||||||
|
const tri = tri1.filter(value => new Set(tri2).has(value));
|
||||||
|
console.log('UNIQUE READ TRI:', tri.length);
|
||||||
|
await con.query(`
|
||||||
|
INSERT INTO vn.algorithm (palletFk, attempt, expeditionArray, expeditionCount, model, power)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?);
|
||||||
|
`, [
|
||||||
|
palletFkFinding,
|
||||||
|
attempt,
|
||||||
|
tri.join(','),
|
||||||
|
tri.length,
|
||||||
|
'TRI',
|
||||||
|
tri[0]?.transmitPowerCdbm
|
||||||
|
]);
|
||||||
|
|
||||||
|
// AL BI
|
||||||
|
const uniqueReadLeft = new Set([...uniqueRead[0], ...uniqueRead[1]]);
|
||||||
|
const uniqueReadRight = new Set([...uniqueRead[2], ...uniqueRead[3]]);
|
||||||
|
const bi = [...uniqueReadLeft].filter(value => uniqueReadRight.has(value));
|
||||||
|
console.log('UNIQUE READ BI:', bi.length);
|
||||||
|
console.log('UNIQUE READ: 1', [...uniqueRead[0]].length);
|
||||||
|
console.log('UNIQUE READ:', new Set([...uniqueRead[0], ...uniqueRead[1], ...uniqueRead[2], ...uniqueRead[3]]).size);
|
||||||
|
console.log('UNIQUE READ:', new Set([...uniqueRead[0], ...uniqueRead[1], ...uniqueRead[2], ...uniqueRead[3]]));
|
||||||
|
await con.query(`
|
||||||
|
INSERT INTO vn.algorithm (palletFk, attempt, expeditionArray, expeditionCount, model, power)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?);
|
||||||
|
|
||||||
|
`, [
|
||||||
|
palletFkFinding,
|
||||||
|
attempt,
|
||||||
|
bi.join(','),
|
||||||
|
bi.length,
|
||||||
|
'BI',
|
||||||
|
bi[0]?.transmitPowerCdbm
|
||||||
|
]);
|
||||||
|
|
||||||
|
// // // AL BEST PEAK
|
||||||
|
// MIRAR SI DOS LA HAN LEIDO ENTONCES BUENA, O TAMBIEN SE PUEDE MIRAR QUE SI EL PEAK ES MEJOR A X COJERLA POR BUENA
|
||||||
|
// const allExpedition = [];
|
||||||
|
// for ()
|
||||||
|
// console.log('UNIQUE READ BI:', bi.length);
|
||||||
|
// await con.query(`
|
||||||
|
// INSERT INTO vn.algorithm (palletFk, attempt, expeditionArray, expeditionCount, model)
|
||||||
|
// VALUES(?, ?, ?, ?, ?, ?);
|
||||||
|
|
||||||
|
// `, [
|
||||||
|
// palletFkFinding,
|
||||||
|
// attempt,
|
||||||
|
// bi,
|
||||||
|
// bi.length,
|
||||||
|
// 'BI'
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// // WARNING IF AN ANTENNA READS LESS THAN IT SHOULD
|
||||||
|
// for (const [index, set] of uniqueRead.entries()) {
|
||||||
|
// if (((set.size * 100) / parsed.codes.size) < 25)
|
||||||
|
// console.logger.warn(`[ANTENNA]: ${index + 1} ONLY ${set.size}`);
|
||||||
|
// }
|
||||||
|
|
||||||
console.log('----------------------------------------------------------------');
|
console.log('----------------------------------------------------------------');
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue