com.amx.duet.tools.comm
Interface IDeviceListener


public interface IDeviceListener


Method Summary
 void deQueue()
          Remove a message from the queue and send it to the physical device.
 void enQueue(byte[] msg, int priority)
          Queue outgoing commands to the device and manage timeline.
 void handleErrorEvent(int error)
          Handle the device error event.
 void handleIncomingData(int bytesReceived, byte[] data)
          Handle all incoming data in a single place.
 void handleOfflineEvent()
          Handle the device offline event.
 void handleOnlineEvent()
          Handle the device online event.
 void heartbeatEvent()
          Put heartbeat messages on the queue here.
 void parseResponse(ByteBuffer response)
          Parse a single response passed in from handleIncomingData().
 void pollEvent()
          Query device for status here.
 void setCommPort()
          Sets up the Serial port communications.
 

Method Detail

setCommPort

public void setCommPort()
Sets up the Serial port communications.

Example usage:

	public void setCommPort()
	{
		String sBaud = getProperty(DeviceUtil.BAUD_RATE);
		utilities.setBaud(sBaud + COMM_PORT_STRING);
		utilities.setHardwareHandshake(false);
		utilities.setSoftwareHandshake(false);
	}
 


enQueue

public void enQueue(byte[] msg,
                    int priority)
Queue outgoing commands to the device and manage timeline.

Example usage:

	public void enQueue(byte msg[])
	{
		synchronized (queue)
		{
			// Restart the dequeue timeline if it was paused
			utilities.restartQueueTimeline();
			queue.doEnq(msg);
		}
	}
 

Parameters:
msg - message to be sent to the device.
priority - the priority of the message being sent.

deQueue

public void deQueue()
Remove a message from the queue and send it to the physical device.

Example usage:

	public void deQueue()
	{
		try
		{
			if (utilities.isQueueLocked() || queue.getQueSize() == 0)
				return;
	
			// stop sending messages and queue them up until we're done
			if (isDeviceOnLine())
				utilities.lockQueue(true);

			// Remove the command from the queue
			sbLastMsg.append((byte[])queue.doDeq());
			if (sbLastMsg != null && sbLastMsg.length() > 0)
			{
				// TODO: User defined code goes here...
				
				// Send the command to the device
				log(DEBUG, "Comm ----------> device: BUFFER '" + sbLastMsg.toHex() + "'");
				utilities.sendString(sbLastMsg.toByteArray());

				// times out the heart beat message if a response is not received
				utilities.startResponseTimer();
			}

			// Pause the dequeue timeline if there are no more items
			if (queue.getQueSize() == 0)
				utilities.pauseQueueTimeline();
		}
		catch (Exception e)
		{
			if (this.getDebugState() == DEBUG)
				e.printStackTrace();
			log(ERROR, "Exception in deQueue: " + e.toString());
		}
	}
 


pollEvent

public void pollEvent()
Query device for status here. This is a reocurring event at the specified poll time interval.

Example usage:

	public void pollEvent()
	{
		// TODO: User defined code goes here...
		enQueue("query_vol");
	}
 


heartbeatEvent

public void heartbeatEvent()
Put heartbeat messages on the queue here.

Example usage:

	public void heartbeatEvent()
	{
		byte cmd[] = {0x03,0x41};
		sendCommand(cmd);
	}
 


handleIncomingData

public void handleIncomingData(int bytesReceived,
                               byte[] data)
Handle all incoming data in a single place.

Example usage:

	public void handleIncomingData(int bytesReceived, byte[] data)
	{
		// this would not be good...
		if (data == null || data.length <= 0 || bytesReceived <= 0)
			return;
		
		sbRxMsg.append(data);
		log(DEBUG, "Comm <---------- device: INCOMING DATA '" + FormatUtil.toAsciiHexString(data) + "'");
		log(DEBUG, "Comm <---------- device: BUFFER '" + sbRxMsg.toHex() + "'");
		
		// check for start and end bytes
		int start = sbRxMsg.indexof(STX);
		int end = sbRxMsg.indexof(ETX);
		while (start > -1 && end > -1)
		{
			// TODO: User defined code goes here...
			
			// Parse a single response
			parseResponse(sbRxMsg.substring(start, end));

			// Delete processed response
			sbRxMsg.delete(start, end+1);
					
			// check for another msg in the buffer
			start = sbRxMsg.indexof(STX);
			end = sbRxMsg.indexof(ETX);
		}
	}
 

Parameters:
data - response received from the device.

handleOnlineEvent

public void handleOnlineEvent()
Handle the device online event.

Example usage:

	public void handleOnlineEvent()
	{
		utilities.handleOnlineEvent();
	}
 


handleOfflineEvent

public void handleOfflineEvent()
Handle the device offline event.

Example usage:

	public void handleOfflineEvent()
	{
		utilities.handleOfflineEvent();
	}
 


handleErrorEvent

public void handleErrorEvent(int error)
Handle the device error event.

Example usage:

	public void handleErrorEvent(int error)
	{
		utilities.handleErrorEvent(error);
	}
 

Parameters:
error - int representing the status value.

parseResponse

public void parseResponse(ByteBuffer response)
Parse a single response passed in from handleIncomingData().

Parameters:
response - ByteBuffer object, which can be used for both byte arrays and Strings.


Copyright © 2008 AMX LLC. All Rights Reserved.