33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
export default async data => {
|
|
data = data.toString();
|
|
const crudeRfids = data.split('\n');
|
|
|
|
const rfidsParsed = new Set();
|
|
const rfidsParsedExtended = [];
|
|
|
|
for (let crudeRfid of crudeRfids) {
|
|
if (crudeRfid && /{.*:{.*:.*}}/.test(crudeRfid)) {
|
|
const jsonResult = JSON.parse(crudeRfid);
|
|
let epcHex = jsonResult?.tagInventoryEvent?.epcHex;
|
|
|
|
if (!epcHex) return;
|
|
if (epcHex.search('AABB') == -1) continue;
|
|
|
|
epcHex = epcHex.replace('AABB', '');
|
|
epcHex = epcHex.substring(0, 1) == 0 ? epcHex.substring(1) : epcHex;
|
|
const rfidParsed = {
|
|
code: parseInt(epcHex),
|
|
created: jsonResult.timestamp,
|
|
peakRssi: jsonResult.tagInventoryEvent.peakRssiCdbm,
|
|
count: 1,
|
|
antenna: jsonResult.tagInventoryEvent.antennaPort
|
|
};
|
|
|
|
rfidsParsed.add(rfidParsed.code);
|
|
rfidsParsed.push(rfidParsed);
|
|
}
|
|
}
|
|
|
|
return {codes: rfidsParsed, extended: rfidsParsedExtended};
|
|
};
|