feat(ocp): printer cycling backend and frontend done :)

This commit is contained in:
2025-04-07 07:02:31 -05:00
parent 75f94eae14
commit dc5ee5b97a
14 changed files with 302 additions and 35 deletions

View File

@@ -68,9 +68,9 @@ export const printerStatus = async (p: any) => {
"debug",
"ocp",
"ocp",
`${p.name}: timeBetween: ${timeBetween}, delay ${
p.printDelay || 90
}, ${currentTime}... ${lastTime}`
`${p.name}: timeBetween: ${timeBetween}, delay ${parseInt(
p.printDelay
)}, ${currentTime}... ${lastTime}`
);
if (tmp[2] === "0" && tmp[4] !== "000") {
@@ -80,7 +80,7 @@ export const printerStatus = async (p: any) => {
"ocp",
"ocp",
`Unpaused and printing labels, time remaing ${differenceInSeconds(
p.printDelay || 90,
parseInt(p.printDelay),
timeBetween
)}`
);
@@ -96,7 +96,7 @@ export const printerStatus = async (p: any) => {
`${
p.name
} paused to soon, unpausing, remaining time: ${differenceInSeconds(
p.printDelay || 90,
parseInt(p.printDelay),
timeBetween
)}`
);
@@ -105,20 +105,20 @@ export const printerStatus = async (p: any) => {
printerUpdate(p, 2);
unPausePrinter(p);
} else if ((tmp[2] === "0" && timeBetween < p.printDelay) || 90) {
} else if (tmp[2] === "0" && timeBetween < parseInt(p.printDelay)) {
// was unpaused to soon so repause it
createLog(
"debug",
"ocp",
"ocp",
`${p.name} Unpaused before the time allowed, time left ${
differenceInSeconds(p.printDelay || 90, timeBetween) //seconds
differenceInSeconds(parseInt(p.printDelay), timeBetween) //seconds
}`
);
printerUpdate(p, 3);
pausePrinter(p);
} else if ((tmp[2] === "0" && timeBetween > p.printDelay) || 90) {
} else if (tmp[2] === "0" && timeBetween > parseInt(p.printDelay)) {
// its been long enough we can print a label
createLog(
"debug",
@@ -188,3 +188,68 @@ export const printerStatus = async (p: any) => {
});
});
};
export const autoLabelingStats = async (p: any) => {
/**
* Checks autolabeling printers just to see what they are doing.
*/
createLog("debug", "ocp", "ocp", `Printer cycling`);
const printer = new net.Socket();
return new Promise((resolve) => {
// connect to the printer, and check its status
printer.connect(p.port, p.ipAddress, async () => {
// write the message to the printer below gives us a feedback of the printer
printer.write("~HS");
});
// read the data from the printer
printer.on("data", async (data) => {
const res = data.toString();
// turn the data into an array to make it more easy to deal with
const tmp = res.split(",");
if (tmp[4] !== "000") {
// unpaused and printing labels - reset timer
createLog("debug", "ocp", "ocp", `Printing Labels`);
// update last time printed in the array
printerUpdate(p, 1);
}
if (tmp[4] === "000") {
// unpaused and printing labels - reset timer
createLog("debug", "ocp", "ocp", `Printing Labels`);
// update last time printed in the array
printerUpdate(p, 5);
}
});
printer.on("error", async (error) => {
// just going to say theres an error with the printer
if (!errorCheck) {
createLog(
"error",
"ocp",
"ocp",
`${p.name} encountered an error: ${error}`
);
}
await printerUpdate(p, 7);
errorCheck = true;
// send log data
// fake line
printer.end();
resolve({
success: false,
message: "There was an error with the printer.",
});
});
});
};