Skip to content

Instantly share code, notes, and snippets.

@devongermano
Last active March 23, 2021 17:06
Show Gist options
  • Save devongermano/7b529ca60c6292cc5bdd4e0a158db2b9 to your computer and use it in GitHub Desktop.
Save devongermano/7b529ca60c6292cc5bdd4e0a158db2b9 to your computer and use it in GitHub Desktop.
Zebra ~HQES Error Parser, Typescript
parseError(error: string): string {
const radix = 16; // Hex
const nibbleOneMap: Map<number, string> = new Map();
nibbleOneMap.set(0, 'No error present');
nibbleOneMap.set(8, 'Cutter fault');
nibbleOneMap.set(4, 'Head open');
nibbleOneMap.set(2, 'Ribbon out');
nibbleOneMap.set(1, 'Media out');
const nibbleTwoMap: Map<number, string> = new Map();
nibbleTwoMap.set(0, 'No error present');
nibbleTwoMap.set(8, 'Printhead detection error');
nibbleTwoMap.set(4, 'Bad printhead element');
nibbleTwoMap.set(2, 'Motor over temperature');
nibbleTwoMap.set(1, 'Printhead over temperature');
const nibbleThreeMap: Map<number, string> = new Map();
nibbleThreeMap.set(0, 'No error present');
nibbleThreeMap.set(2, 'Printhead thermistor open');
nibbleThreeMap.set(1, 'Invalid firmware configuration');
const nibbleFourMap: Map<number, string> = new Map();
nibbleFourMap.set(0, 'No error present');
nibbleFourMap.set(8, 'Clear paper path failed');
nibbleFourMap.set(4, 'Paper feed error');
nibbleFourMap.set(2, 'Presenter not running');
nibbleFourMap.set(1, 'Paper jam during retract');
const nibbleFiveMap: Map<number, string> = new Map();
nibbleFiveMap.set(0, 'No error present');
nibbleFiveMap.set(8, 'Black mark not found');
nibbleFiveMap.set(4, 'Black mark calibrate error');
nibbleFiveMap.set(2, 'Retract function timed out');
nibbleFiveMap.set(1, 'Paused');
const errorMap: Map<number, Map<number, string>> = new Map();
// Key is the index of the nibble in the error, map is obviously the map
// above that can parse the error at that nibble's index
errorMap.set(16, nibbleOneMap);
errorMap.set(15, nibbleTwoMap);
errorMap.set(14, nibbleThreeMap);
errorMap.set(13, nibbleFourMap);
errorMap.set(12, nibbleFiveMap);
const parsedErrors: Array<string> = [];
errorMap.forEach((mapValue: Map<number, string>, nibbleIndex: number) => {
// Grab the error nibble that we need based on the errorMaps key, which corresponds to nibbles' index
const nibbleChar = error.charAt(nibbleIndex);
const nibble = parseInt(nibbleChar, radix);
if (nibble !== 0 && mapValue.get(nibble)) {
parsedErrors.push(mapValue.get(nibble));
return;
}
// Represents the sum the of the present error flags
let errorsSum: number = null;
mapValue.forEach((errorValue: string, errorKey: number) => {
// Looks like we have multiple errors, lets try to break it down into its parts
if (errorKey === 0 || errorsSum === 0) return;
// Looks like this is the first go around, set the errorsSum to be the value of our nibble
if (!errorsSum) {
errorsSum = nibble;
}
const errorsSubtract = (errorsSum - errorKey);
// Did it work? Is it not negative? Great!, let's add it to the list of errors and get outta here!
if (errorsSubtract > -1) {
errorsSum = errorsSubtract;
parsedErrors.push(errorValue);
}
});
});
return parsedErrors.join(', ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment