Engine Terms

From RifidiWiki

Revision as of 00:34, 7 November 2007 by Kyle (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Formatter

The formatter handles any reader specific parsing that needs to be done to a raw message coming into (using the decode method) or going out of the reader (using the encode method). For example, in the Symbol Formatter, the third byte is the command type, and is used to look up the handler method to use:

public ArrayList<Object> decode(byte[] arg) {
    if (arg == null || arg.length < 4) {
        return null;
    }
    ArrayList<Object> retVal = new ArrayList<Object>();
    retVal.add(ByteAndHexConvertingUtility.toHexString(arg[3]));
    retVal.add(arg);
    
    return retVal;
	}

On the way out, a 0x01 needs to be prepended to a response, and the CRC needs to be calculated.

public ArrayList<Object> encode(ArrayList<Object> arg) {

	ArrayList<Object> retVal = new ArrayList<Object>();

	for (Object o : arg) {
		byte[] command = (byte[]) o;

		/*
		 * Create outgoing array list that is 3 slots bigger than incoming
		 * one: one for start of frame and two for crc bytes
		 */
		byte[] outgoingCommand = new byte[command.length + 3];
		for (int i = 0; i < command.length; i++) {
			outgoingCommand[i + 1] = command[i];
		}

		/* Add Start of Frame Byte */
		outgoingCommand[0] = 0x01;

		// Calculate CRC
		int crc = CRC16.calculateCRC(command, 0xBEEF,CRC16.XR400_CRC_TABLE, true);
		byte[] crcBytes = ByteAndHexConvertingUtility.intToByteArray(crc, 2);

		// put crc in outgoingCommand, LSB first
		outgoingCommand[outgoingCommand.length - 2] = crcBytes[1];
		outgoingCommand[outgoingCommand.length - 1] = crcBytes[0];
			
		logger.debug(ByteAndHexConvertingUtility.toHexString(outgoingCommand));
			
			
		retVal.add(outgoingCommand);

	}

	return retVal;
}

Handler Method

A method within a reader's project that handles a specific command for a reader. For example if a Rifidi Symbol reader receives a Set System Parameter Command, the following method handles the logic for that command:
	
public CommandObject setSystemParameter(CommandObject arg, AbstractReaderSharedResources asr) {
    byte[] setSystemParam = { 0x04, 0x06, 0x27, 0x00 };
    arg.getReturnValue().add(setSystemParam);
    return arg;
}
Personal tools