|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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 |
public void setCommPort()
Example usage:
public void setCommPort() { String sBaud = getProperty(DeviceUtil.BAUD_RATE); utilities.setBaud(sBaud + COMM_PORT_STRING); utilities.setHardwareHandshake(false); utilities.setSoftwareHandshake(false); }
public void enQueue(byte[] msg, int priority)
Example usage:
public void enQueue(byte msg[]) { synchronized (queue) { // Restart the dequeue timeline if it was paused utilities.restartQueueTimeline(); queue.doEnq(msg); } }
msg
- message to be sent to the device.priority
- the priority of the message being sent.public void deQueue()
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()); } }
public void pollEvent()
Example usage:
public void pollEvent() { // TODO: User defined code goes here... enQueue("query_vol"); }
public void heartbeatEvent()
Example usage:
public void heartbeatEvent() { byte cmd[] = {0x03,0x41}; sendCommand(cmd); }
public void handleIncomingData(int bytesReceived, byte[] data)
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); } }
data
- response received from the device.public void handleOnlineEvent()
Example usage:
public void handleOnlineEvent() { utilities.handleOnlineEvent(); }
public void handleOfflineEvent()
Example usage:
public void handleOfflineEvent() { utilities.handleOfflineEvent(); }
public void handleErrorEvent(int error)
Example usage:
public void handleErrorEvent(int error) { utilities.handleErrorEvent(error); }
error
- int representing the status value.public void parseResponse(ByteBuffer response)
response
- ByteBuffer object, which can be used for both byte
arrays and Strings.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |