fix(rfid): changed the tag reading to have a little more flexable

This commit is contained in:
2025-12-08 08:36:25 -06:00
parent ba48c5307f
commit 722b23a321

View File

@@ -1,14 +1,14 @@
//http://usday1vms006:4000/api/v1/zebra/wrapper1 //http://usday1vms006:4000/api/v1/zebra/wrapper1
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi"; import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { ConsoleLogWriter } from "drizzle-orm"; import { ConsoleLogWriter } from "drizzle-orm";
import { tagData } from "../controller/tagData.js"; import { apiHit } from "../../../globalUtils/apiHits.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js"; import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { createLog } from "../../logger/logger.js";
import { clearNoReadTimer, noRead } from "../controller/noRead.js"; import { clearNoReadTimer, noRead } from "../controller/noRead.js";
import { badRead, goodRead } from "../controller/readerControl.js"; import { badRead, goodRead } from "../controller/readerControl.js";
import { createLog } from "../../logger/logger.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { stopRead } from "../controller/readTags.js"; import { stopRead } from "../controller/readTags.js";
import { apiHit } from "../../../globalUtils/apiHits.js"; import { tagData } from "../controller/tagData.js";
const app = new OpenAPIHono(); const app = new OpenAPIHono();
@@ -48,9 +48,7 @@ app.openapi(
//console.log(`Tag: ${Buffer.from(body.idHex, "hex").toString("utf-8")}, ${body[key].data.idHex}`); //console.log(`Tag: ${Buffer.from(body.idHex, "hex").toString("utf-8")}, ${body[key].data.idHex}`);
for (let i = 0; i < body.length; i++) { for (let i = 0; i < body.length; i++) {
const tag = Buffer.from(body[i].data.idHex, "hex").toString( const tag = Buffer.from(body[i].data.idHex, "hex").toString("utf-8");
"utf-8"
);
// console.log( // console.log(
// "Raw value:", // "Raw value:",
// body[i].data.peakRssi, // body[i].data.peakRssi,
@@ -59,7 +57,7 @@ app.openapi(
// ); // );
if ( if (
tag.includes("ALPLA") && tag.includes("ALPLA") &&
parseInt(body[i].data.peakRssi) < -30 parseInt(body[i].data.peakRssi) >= -80 // anything strong than this go ahead and read it
) { ) {
tagdata = [ tagdata = [
...tagdata, ...tagdata,
@@ -80,19 +78,16 @@ app.openapi(
// badRead(reader); // badRead(reader);
return c.json( return c.json(
{ success: false, message: `There were no tags scanned.` }, { success: false, message: `There were no tags scanned.` },
200 200,
); );
} else { } else {
tagData(tagdata); tagData(tagdata);
goodRead(reader); goodRead(reader);
clearNoReadTimer(); clearNoReadTimer();
return c.json( return c.json({ success: true, message: `New info from ${reader}` }, 200);
{ success: true, message: `New info from ${reader}` },
200
);
}
} }
},
); );
export default app; export default app;