feat(mobile): shadcn like and tailwind added to make things look yummy
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m21s

This commit is contained in:
2026-04-27 21:23:40 -05:00
parent 649ae1ee9f
commit 7d2f048932
32 changed files with 1909 additions and 325 deletions

View File

@@ -1,7 +1,7 @@
import TcpSocket from "react-native-tcp-socket";
const STX = "\x02";
const ETX = "\x03";
// const STX = "\x02";
// const ETX = "\x03";
type TcpResponse = {
success: boolean;
@@ -9,26 +9,154 @@ type TcpResponse = {
data: string[];
};
function parseErpResponse(buffer: Buffer) {
const text = buffer
.toString("utf8")
.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|#[0-9A-Za-z])/g, "")
.replace(/\x02/g, "")
.replace(/\x03/g, "")
.trim();
const noHeader = text.replace(/^\d+@/, "");
console.log(text);
if (!noHeader.includes("Scan:")) {
return {
raw: text,
type: "error",
message: noHeader.trim(),
lines: [noHeader.trim()],
};
}
const [actionPart, scanPart = ""] = noHeader.split("Scan:");
const action = actionPart.trim();
const scanClean = scanPart.trim();
const successMatch = scanClean.match(/^(.*?)\s+V$/);
if (successMatch) {
const prompt = successMatch[1].trim();
return {
raw: text,
type: "success",
action,
prompt,
status: "V",
lines: [action, prompt, "V"],
};
}
// // Handles: "Production lotInvalid barcode"
// const knownErrors = [
// "Invalid barcode",
// "Invalid machine",
// "Not on stock",
// "Article tolerance for consolidation not satisfied",
// ].sort((a, b) => b.length - a.length);
// const foundError = knownErrors.find((err) => scanClean.includes(err));
// if (foundError) {
// const prompt = scanClean.replace(foundError, "").trim();
// return {
// raw: text,
// type: "error",
// action,
// prompt,
// message: foundError,
// lines: [action, prompt, foundError].filter(Boolean),
// };
// }
// return {
// raw: text,
// type: "pending",
// action,
// prompt: scanClean,
// lines: [action, scanClean].filter(Boolean),
// };
const unitMatch = scanClean.match(/^(Unit\s+\d+\/\d+)(.*)$/);
if (unitMatch) {
const prompt = unitMatch[1].trim(); // "Unit 1/4"
const remainder = unitMatch[2].trim(); // everything after
// SUCCESS
if (remainder === "V") {
return {
raw: text,
type: "success",
action,
prompt,
status: "V",
lines: [action, prompt, "V"],
};
}
// Known ERP errors
const knownErrors = [
"Invalid barcode",
"Invalid machine",
"Not on stock",
"Article tolerance for consolidation not satisfied",
];
const foundError = knownErrors.find((err) =>
remainder.toLowerCase().includes(err.toLowerCase()),
);
if (foundError) {
return {
raw: text,
type: "error",
action,
prompt,
message: foundError,
lines: [action, prompt, foundError],
};
}
if (remainder) {
return {
raw: text,
type: "prompt",
action,
prompt,
message: remainder,
lines: [action, prompt, remainder],
};
}
return {
raw: text,
type: "pending",
action,
prompt,
lines: [action, prompt],
};
}
}
/**
* Sends a Zebra-style TCP message:
* <STX>98@{scanned}<ETX>
*/
export async function sendTcpMessage(
scanned: string,
command: string,
host: string,
port: number,
timeoutMs = 5000,
): Promise<TcpResponse> {
return new Promise((resolve) => {
const responses: string[] = [];
const responses: any = [];
const client = TcpSocket.createConnection({ host, port }, () => {
const payload = `${STX}98@${scanned}${ETX}`;
console.log("Sending TCP (visible):", `${command}`);
console.log("Sending TCP (raw):", payload);
console.log("Sending TCP (visible):", `<stx>98@${scanned}<etx>`);
client.write(payload);
client.write(command);
});
const timeout = setTimeout(() => {
@@ -42,10 +170,17 @@ export async function sendTcpMessage(
}, timeoutMs);
client.on("data", (data) => {
const text = data.toString();
console.log("TCP received:", text);
//const text = data.toString();
//console.log("TCP received:", text);
const parsed = parseErpResponse(data);
responses.push(text);
responses.push(parsed);
clearTimeout(timeout);
resolve({
success: true,
message: "TCP Response",
data: responses,
});
});
client.on("error", (err) => {