private void frame() { FrameType type = frame.getFrameType(); if (type == null) { // ReceivedUnwantedFrame if (LOG.isDebugEnabled()) LOG.debug(thisStation + " idle:Unknown frame type"); } else if (frame.broadcast() && type.oneOf(FrameType.token, FrameType.bacnetDataExpectingReply, FrameType.testRequest)) { // ReceivedUnwantedFrame if (LOG.isDebugEnabled()) LOG.debug(thisStation + " Frame type should not be broadcast: " + type); } else if (frame.forStation(thisStation) && type == FrameType.token) { // ReceivedToken // debug("idle:ReceivedToken from " + frame.getSourceAddress()); if (LOG.isDebugEnabled()) LOG.debug(thisStation + " idle:ReceivedToken"); frameCount = 0; soleMaster = false; state = MasterNodeState.useToken; // // long now = timeSource.currentTimeMillis(); // if (lastTokenPossession > 0) // debug("Since last token possession: " + (now - lastTokenPossession) + " // ms"); // else // debug("Received first token possession"); // lastTokenPossession = now; } else if (frame.forStation(thisStation) && type == FrameType.pollForMaster) { // ReceivedPFM // debug("idle:ReceivedPFM from " + frame.getSourceAddress()); if (LOG.isDebugEnabled()) LOG.debug(thisStation + " idle:ReceivedPFM"); sendFrame(FrameType.replyToPollForMaster, frame.getSourceAddress()); } else if (frame.forStationOrBroadcast(thisStation) && type.oneOf(FrameType.bacnetDataNotExpectingReply, FrameType.testResponse)) { // ReceivedDataNoReply // debug("idle:ReceivedDataNoReply"); if (LOG.isDebugEnabled()) LOG.debug(thisStation + " idle:ReceivedDataNoReply"); receivedDataNoReply(frame); } else if (frame.forStation(thisStation) && type.oneOf(FrameType.bacnetDataExpectingReply, FrameType.testRequest)) { // ReceivedDataNeedingReply // debug("idle:ReceivedDataNeedingReply"); if (LOG.isDebugEnabled()) LOG.debug(thisStation + " idle:ReceivedDataNeedingReply"); receivedDataNeedingReply(frame); state = MasterNodeState.answerDataRequest; replyDeadline = lastNonSilence + Constants.REPLY_DELAY; } }
private void waitForReply() { if (silence() > Constants.REPLY_TIMEOUT) { // ReplyTimeout - assume that the request has failed // debug("waitForReply:ReplyTimeout"); if (LOG.isDebugEnabled()) LOG.debug(thisStation + " waitForReply:ReplyTimeout"); frameCount = maxInfoFrames; state = MasterNodeState.doneWithToken; } else if (receivedInvalidFrame != null) { // InvalidFrame // debug("waitForReply:InvalidFrame: '" + receivedInvalidFrame + "', frame=" + // frame); if (LOG.isDebugEnabled()) LOG.debug("Received invalid frame: " + receivedInvalidFrame); receivedInvalidFrame = null; state = MasterNodeState.doneWithToken; activity = true; } else if (receivedValidFrame) { activity = true; FrameType type = frame.getFrameType(); if (frame.forStation(thisStation)) { if (type.oneOf(FrameType.testResponse, FrameType.bacnetDataNotExpectingReply)) { // ReceivedReply // debug("waitForReply:ReceivedReply from " + frame.getSourceAddress()); if (LOG.isDebugEnabled()) LOG.debug(thisStation + " waitForReply:ReceivedReply"); receivedDataNoReply(frame); } else if (type.oneOf(FrameType.replyPostponed)) { // ReceivedPostpone // debug("waitForReply:ReceivedPostpone from " + frame.getSourceAddress()); if (LOG.isDebugEnabled()) LOG.debug(thisStation + " waitForReply:ReceivedPostpone"); ; // the reply to the message has been postponed until a later time. } state = MasterNodeState.doneWithToken; } else if (!type.oneOf(FrameType.testResponse, FrameType.bacnetDataNotExpectingReply)) { // ReceivedUnexpectedFrame // debug("waitForReply:ReceivedUnexpectedFrame: " + frame); if (LOG.isDebugEnabled()) LOG.debug(thisStation + " waitForReply:ReceivedUnexpectedFrame"); // This may indicate the presence of multiple tokens. state = MasterNodeState.idle; } receivedValidFrame = false; } }
public void queueFrame(FrameType type, byte destination, byte[] data) { if (!type.oneOf( FrameType.bacnetDataExpectingReply, FrameType.bacnetDataNotExpectingReply, FrameType.testRequest)) throw new RuntimeException("Cannot send frame of type: " + type); Frame frame = new Frame(type, destination, thisStation, data); synchronized (framesToSend) { framesToSend.add(frame); } }