test(rfid): intial trials built
This commit is contained in:
51
server/services/rfid/controller/readTags.ts
Normal file
51
server/services/rfid/controller/readTags.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import axios from "axios";
|
||||
import {createLog} from "../../logger/logger.js";
|
||||
|
||||
export const readTags = async (reader: string) => {
|
||||
/**
|
||||
* Start the read for x seconds then auto stop it
|
||||
*/
|
||||
|
||||
let token: string;
|
||||
|
||||
const readers = [{reader: "reader1", readerIP: "10.10.1.222", lastHeartBeat: new Date()}];
|
||||
// get the auth token
|
||||
const ip = readers.find((r) => r.reader === reader)?.readerIP;
|
||||
|
||||
try {
|
||||
const res = await axios.get(`https://${ip}/cloud/localRestLogin`, {
|
||||
headers: {Authorization: `Basic ${btoa("admin:Zebra123!")}`},
|
||||
});
|
||||
token = res.data.message;
|
||||
// start the read
|
||||
try {
|
||||
const res = await axios.put(
|
||||
`https://${ip}/cloud/start`,
|
||||
{},
|
||||
{
|
||||
headers: {Authorization: `Bearer ${token}`},
|
||||
}
|
||||
);
|
||||
|
||||
// stop after 5 seconds
|
||||
|
||||
try {
|
||||
const res = await axios.put(
|
||||
`https://${ip}/cloud/stop`,
|
||||
{},
|
||||
{
|
||||
headers: {Authorization: `Bearer ${token}`},
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
createLog("error", "rfid", "rfid", `There was an error Stopping the read ${error}`);
|
||||
}
|
||||
} catch (error) {
|
||||
createLog("error", "rfid", "rfid", `There was an error Starting the read ${error}`);
|
||||
}
|
||||
} catch (error) {
|
||||
createLog("error", "rfid", "rfid", `There was an error Getting the token the read ${error}`);
|
||||
}
|
||||
|
||||
// start the read
|
||||
};
|
||||
3
server/services/rfid/controller/shippedOutTags.ts
Normal file
3
server/services/rfid/controller/shippedOutTags.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
/**
|
||||
* we will monitor shipped out pallets every hour if they get shipped out
|
||||
*/
|
||||
3
server/services/rfid/controller/station1.ts
Normal file
3
server/services/rfid/controller/station1.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
/**
|
||||
* station 1 will just check for 10 tags
|
||||
*/
|
||||
4
server/services/rfid/controller/station2.ts
Normal file
4
server/services/rfid/controller/station2.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* we will have 3 reader points here station2.1 will require 10 tags, 2.2 and 2.3 will require 1
|
||||
*
|
||||
*/
|
||||
4
server/services/rfid/controller/station3.ts
Normal file
4
server/services/rfid/controller/station3.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Phase 1 we link the tag to the line only the line3.x where x is the line number
|
||||
* Phase 2 we will generate a label to be reprinted at staion 4
|
||||
*/
|
||||
4
server/services/rfid/controller/station4.ts
Normal file
4
server/services/rfid/controller/station4.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Phase 1 we will just follow the logic of printing a label when we are told requested to based on this tag.
|
||||
* Phase 2 we will just reprint the tag that was generated at the line
|
||||
*/
|
||||
48
server/services/rfid/controller/tagData.ts
Normal file
48
server/services/rfid/controller/tagData.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
type TagData = {tagHex: string; reader: string; tag: string; timeStamp: Date};
|
||||
export const tagData = async (data: TagData[]) => {
|
||||
/**
|
||||
* We will always update a tag
|
||||
*/
|
||||
|
||||
// dyco wall makes sure we have 10 tags
|
||||
const station1 = data.some((n) => n.reader.includes("reader1"));
|
||||
|
||||
// by the dyco infeed
|
||||
const station2 = data.some((n) => n.reader.includes("station2"));
|
||||
|
||||
// at the end of each line
|
||||
const station3 = data.some((n) => n.reader.includes("line3"));
|
||||
|
||||
// at the wrapper
|
||||
const station4 = data.some((n) => n.reader.includes("wrapper"));
|
||||
|
||||
// station checks
|
||||
if (station1 && data.length != 10) {
|
||||
console.log(`There are only ${data.length}`);
|
||||
}
|
||||
|
||||
if (station2) {
|
||||
console.log(`There are only ${data.length}`);
|
||||
}
|
||||
|
||||
if (station3) {
|
||||
// make sure we only have one tag or dont update
|
||||
if (data.length != 1) {
|
||||
console.log(`There are ${data.length} tags, and ${data[0].reader} only allows 1 tag to create a label.`);
|
||||
//throw new Error("There are more than 1 tag at this station and it is not allowed");
|
||||
} else {
|
||||
console.log("Generate the tag and link it to the tag.");
|
||||
}
|
||||
}
|
||||
|
||||
if (station4) {
|
||||
if (data.length != 1) {
|
||||
console.log(
|
||||
`There are ${data.length} tags and this ${data[0].reader} only allows 1 tag to create a label.`
|
||||
);
|
||||
//throw new Error("There are more than 1 tag at this station and it is not allowed");
|
||||
} else {
|
||||
console.log("reprint the label linked to the tag.");
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user