feat(tag reading): more tag reading updates, with more contorl now
station 1 and 2 are still pending but didnt have enough tags at the office trial it
This commit is contained in:
40
server/services/rfid/route/manualTagRead.ts
Normal file
40
server/services/rfid/route/manualTagRead.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
//http://usday1vms006:4000/api/v1/zebra/wrapper1
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
import {readTags} from "../controller/readTags.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const ParamsSchema = z.object({
|
||||
reader: z
|
||||
.string()
|
||||
.min(3)
|
||||
.openapi({
|
||||
param: {
|
||||
name: "reader",
|
||||
in: "path",
|
||||
},
|
||||
example: "1212121",
|
||||
}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["rfid"],
|
||||
summary: "Manual triggers the read function",
|
||||
method: "post",
|
||||
path: "/manualtrigger/{reader}",
|
||||
request: {
|
||||
params: ParamsSchema,
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const {reader} = c.req.valid("param");
|
||||
const manualTrigger = await readTags(reader);
|
||||
|
||||
return c.json({success: true, message: `A Manaul trigger was done on ${reader}`}, 200);
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
@@ -2,12 +2,8 @@
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {readTags} from "../controller/readTags.js";
|
||||
import {createLog} from "../../logger/logger.js";
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
success: z.boolean().openapi({example: true}),
|
||||
message: z.string().optional(),
|
||||
});
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
import {newHeartBeat} from "../controller/readerControl.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
let lastGpiTimestamp = 0;
|
||||
@@ -28,64 +24,37 @@ const ParamsSchema = z.object({
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["rfid"],
|
||||
summary: "Adds a new module",
|
||||
summary: "Post info from the reader",
|
||||
method: "post",
|
||||
path: "/mgtevents/{reader}",
|
||||
request: {
|
||||
params: ParamsSchema,
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {schema: responseSchema},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
401: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
||||
},
|
||||
},
|
||||
description: "Unauthorized",
|
||||
},
|
||||
500: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const {reader} = c.req.valid("param");
|
||||
const body = await c.req.json();
|
||||
|
||||
if (body.type === "heartbeat") {
|
||||
console.log("Heartbeat");
|
||||
const heart = await newHeartBeat(reader);
|
||||
return c.json({success: heart.success, message: heart.message}, 200);
|
||||
}
|
||||
|
||||
if (body.type === "gpi" && body.data.state === "HIGH") {
|
||||
const eventTimestamp = new Date(body.timestamp).getTime(); // Convert ISO timestamp to milliseconds
|
||||
|
||||
if (eventTimestamp - lastGpiTimestamp > 10) {
|
||||
if (eventTimestamp - lastGpiTimestamp > 5 * 1000) {
|
||||
// Check if it's been more than 2ms
|
||||
lastGpiTimestamp = eventTimestamp; // Update last seen timestamp
|
||||
|
||||
createLog("info", "rfid", "rfid", `${reader} is reading a tag.`);
|
||||
readTags(reader);
|
||||
await readTags(reader);
|
||||
} else {
|
||||
console.log("Duplicate GPI event ignored.");
|
||||
createLog("info", "rfid", "rfid", `A new trigger from ${reader} was to soon`);
|
||||
lastGpiTimestamp = eventTimestamp;
|
||||
}
|
||||
|
||||
//console.log(body);
|
||||
}
|
||||
|
||||
return c.json({success: true, message: `New info from ${reader}`}, 200);
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {ConsoleLogWriter} from "drizzle-orm";
|
||||
import {tagData} from "../controller/tagData.js";
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
success: z.boolean().openapi({example: true}),
|
||||
message: z.string().optional(),
|
||||
});
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
import {noRead} from "../controller/noRead.js";
|
||||
import {badRead, goodRead} from "../controller/readerControl.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -27,44 +24,13 @@ const ParamsSchema = z.object({
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["rfid"],
|
||||
summary: "Adds a new module",
|
||||
summary: "Tag info posted from the reader.",
|
||||
method: "post",
|
||||
path: "/taginfo/{reader}",
|
||||
request: {
|
||||
params: ParamsSchema,
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {schema: responseSchema},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
401: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
||||
},
|
||||
},
|
||||
description: "Unauthorized",
|
||||
},
|
||||
500: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const {reader} = c.req.valid("param");
|
||||
@@ -74,17 +40,31 @@ app.openapi(
|
||||
|
||||
for (let i = 0; i < body.length; i++) {
|
||||
const tag = Buffer.from(body[i].data.idHex, "hex").toString("utf-8");
|
||||
if (tag.includes("ALPLA")) {
|
||||
//console.log("Raw value:", body[i].data.peakRssi, "Parsed:", parseInt(body[i].data.peakRssi));
|
||||
if (tag.includes("ALPLA") && parseInt(body[i].data.peakRssi) < -50) {
|
||||
tagdata = [
|
||||
...tagdata,
|
||||
{tagHex: body[i].data.idHex, reader: reader, tag: tag, timeStamp: body[i].timestamp},
|
||||
{
|
||||
tagHex: body[i].data.idHex,
|
||||
reader: reader,
|
||||
tag: tag,
|
||||
timeStamp: body[i].timestamp,
|
||||
antenna: body[i].data.antenna,
|
||||
tagStrength: body[i].data.peakRssi,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
tagData(tagdata);
|
||||
|
||||
return c.json({success: true, message: `New info from ${reader}`}, 200);
|
||||
if (tagdata.length === 0) {
|
||||
noRead(reader);
|
||||
badRead(reader);
|
||||
return c.json({success: false, message: `There were no tags scanned.`}, 200);
|
||||
} else {
|
||||
tagData(tagdata);
|
||||
goodRead(reader);
|
||||
return c.json({success: true, message: `New info from ${reader}`}, 200);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user