READERNAME LogFormatter.java

From RifidiWiki

Jump to: navigation, search

This class handles how the reader should display outgoing and incoming messages in the console logger in the IDE. If the reader does not need to display this information in any special way, it does not have to implement this class and instead can use either the GenericByteLogFormatter or the GenericStringLogFormatter. If it does need to implement this class, it should implement the LogFormatter interface.

formatMessage

This method needs to decode an incoming command into a command to be handled in the command formatter. It should put the command into a commandObject and put the commandObject in the first slot in an arraylist and return the arraylist.

public String formatMessage(byte[] rawMessage);

Arguments

  1. arg - The incoming or outgoing message that needs to be turned into a log message

Return Value

A string that will be printed in the console

Reference Implementation

This is the log formatter for the llrp reader. It displays both the bytes and the xml representation of the messages.

	public String formatMessage(byte[] rawMessage) {
		
		ByteArrayInputStream is = new ByteArrayInputStream(rawMessage);
		String bytes = ByteAndHexConvertingUtility.toHexString(rawMessage);
		try {
			Message m = Message.receive(is);
			return "\nBYTES: \n" + bytes + "\nXML: \n" + m.toXMLString();
		} catch (Exception e) {
			logger.error("Cannot serialize the message");
			return "\nBytes: " + bytes;
		} 
	}

Other Notes

Also note GenericByteLogFormatter and GenericStringLogFormatter are used for two different purposes. GenericByteLogFormatter is used when the reader takes in bytes as commands and out puts them into the debug window of the IDE--like the LLRP or the Symbol. GenericStringLogFormatter is used when the reader takes in strings as commands and out puts them into the debug window of the IDE--like the Alien or the Thing Magic.

Personal tools