feat(scanner): more work on the scanner and can now scan to prod no lst right now
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 2m41s

This commit is contained in:
2026-04-25 18:13:07 -05:00
parent 83a542d1b7
commit 77b4533dea
17 changed files with 615 additions and 43 deletions

View File

@@ -0,0 +1,40 @@
import {
type EmitterSubscription,
NativeEventEmitter,
NativeModules,
} from "react-native";
const { ZebraScanner } = NativeModules;
const scannerEmitter = new NativeEventEmitter(ZebraScanner);
export type ZebraScanResult = {
data: string;
labelType?: string;
source?: string;
timestamp: number;
};
export const zebraScanner = {
startListening() {
ZebraScanner.startListening();
},
stopListening() {
ZebraScanner.stopListening();
},
triggerScan() {
ZebraScanner.triggerScan();
},
ensureProfile() {
ZebraScanner.ensureProfile();
},
addScanListener(
callback: (scan: ZebraScanResult) => void,
): EmitterSubscription {
return scannerEmitter.addListener("barcodeScanned", callback);
},
};

View File

@@ -0,0 +1,72 @@
import TcpSocket from "react-native-tcp-socket";
const STX = "\x02";
const ETX = "\x03";
type TcpResponse = {
success: boolean;
message: string;
data: string[];
};
/**
* Sends a Zebra-style TCP message:
* <STX>98@{scanned}<ETX>
*/
export async function sendTcpMessage(
scanned: string,
host: string,
port: number,
timeoutMs = 5000,
): Promise<TcpResponse> {
return new Promise((resolve) => {
const responses: string[] = [];
const client = TcpSocket.createConnection({ host, port }, () => {
const payload = `${STX}98@${scanned}${ETX}`;
console.log("Sending TCP (raw):", payload);
console.log("Sending TCP (visible):", `<stx>98@${scanned}<etx>`);
client.write(payload);
});
const timeout = setTimeout(() => {
client.destroy();
resolve({
success: false,
message: "TCP timeout",
data: responses,
});
}, timeoutMs);
client.on("data", (data) => {
const text = data.toString();
console.log("TCP received:", text);
responses.push(text);
});
client.on("error", (err) => {
clearTimeout(timeout);
client.destroy();
resolve({
success: false,
message: err.message,
data: responses,
});
});
client.on("close", () => {
clearTimeout(timeout);
resolve({
success: true,
message: "TCP complete",
data: responses,
});
});
});
}