📄 irlapcontext.java
字号:
m_discoveryLog.add(discoveryInfo);
if ( null != m_listener ) {
m_listener.discoveryIndication(this, discoveryInfo);
}
}
public void flushQueue(byte yConnection) throws Exception {
if ( m_sendQueue.pendingDataRequests() ) {
for ( int i = 0; i < m_sendQueue.size(); i++ ) {
IrLAPFrame nextFrame = m_sendQueue.get(i);
byte [] ayNextData = nextFrame.getData();
m_log.debug("IrLAPContext", "Data-Request(" + Utilities.bytesToString(ayNextData, 0, ayNextData.length) + ")");
m_framer.sendI(yConnection, m_nVr, nextFrame.getSequenceNumber(), true, ayNextData, 0, ayNextData.length);
}
}
}
public void generateAddress() {
m_nMyAddress = m_random.nextInt();
m_log.debug("IrLAPContext", "\tGenerate-Random-Address => " + m_nMyAddress);
}
public byte generateConnectionAddress() throws Exception {
byte yConnection = (byte) 0x35;
m_log.debug("IrLAPContext", "\tGenerate-Random-ConnectionAdr(" + yConnection + ")");
return yConnection;
}
public byte generateResponseSlot(byte yNumSlots, byte ySlot) throws Exception {
m_yResponseSlot = (byte) (m_random.nextInt() % (yNumSlots - ySlot) + ySlot);
if ( m_yResponseSlot < 0 ) {
m_yResponseSlot *= -1;
}
m_log.debug("IrLAPContext", "\tslot := Generate-Random-Time-Slot(" + yNumSlots + "," + ySlot + ") => " + m_yResponseSlot);
return m_yResponseSlot;
}
public byte getConnection() {
return m_yConnection;
}
public byte getResponseSlot() {
return m_yResponseSlot;
}
public byte getSlotCount() {
return _slotCount;
}
public int getVr() {
return m_nVr;
}
public int getVs() {
return m_nVs;
}
public void incrementVr() throws Exception {
m_log.debug("IrLAPContext", "\tVr := (Vr + 1) % 8");
m_nVr = (m_nVr + 1) % 8;
}
public void initializeConnectionState() throws Exception {
m_log.debug("IrLAPContext", "\tInitialize-Connection-State");
m_bFrameSent = false;
m_bRemoteBusy = false;
m_nRetryCount = 0;
m_nVr = 0;
m_nVs = 0;
m_nWindowSize = DEFAULT_WINDOW_SIZE;
//m_framer.initialize();
}
public boolean isConnectionConfirmed() {
return m_bConnectionConfirmed;
}
public boolean isFrameSent() {
return m_bFrameSent;
}
public boolean isMediaBusy() throws Exception {
m_log.debug("IrLAPContext", "\tmediaBusy = " + m_bMediaBusy);
return m_bMediaBusy;
}
public boolean isRemoteBusy() throws Exception {
m_log.debug("IrLAPContext", "\tremoteBusy = " + m_bRemoteBusy);
return m_bRemoteBusy;
}
/**
* Does nothing right now. We stick to 9600bps, 8 data bits, 1 stop bit,
* no parity. We gotta fix that -- 9600 is painfully slow.
*/
public void negotiateConnectionParameters(byte [] ayParameters) throws Exception {
m_log.debug("IrLAPContext", "\tNegotiate-Connection-Parameters: " + Utilities.bytesToString(ayParameters, 0, ayParameters.length));
m_ayCommParameters = ayParameters;
m_framer.setConnectionParameters(m_ayCommParameters);
}
public void nextState(IrLAPState nextState) throws Exception {
m_log.debug("IrLAPContext", "[transition from " + m_state.getClass().getName() + " to " + nextState.getClass().getName() + "]");
m_state = nextState;
}
public boolean pendingDataRequests() throws Exception {
boolean bPending = m_sendQueue.pendingDataRequests();
m_log.debug("IrLAPContext", bPending ? "\tPending-Data-Requests" : "\tNo-Pending-Data-Requests");
return bPending;
}
public void sendData(byte yConnection, byte [] ayData, int nOffset, int nLength) throws Exception {
m_log.debug("IrLAPContext", "sendData");
m_sendQueue.addFrame(new IrLAPFrame(m_nVs, ayData, nOffset, nLength));
m_nVs = (m_nVs + 1) % 8;
}
public void sendDiscoveryRequest() throws Exception {
m_log.debug("IrLAPContext", "\tSend-Discovery-Request:" + m_nMyAddress);
m_framer.sendXID(m_nMyAddress, 0xFFFFFFFF, true, _slotCount, DISCOVERY_INFO);
}
public void sendDiscoveryResponse(int nDestination) throws Exception {
m_log.debug("IrLAPContext", "\tSend-Discovery-XID-Rsp:" + m_nMyAddress + ",discovery-info");
m_framer.sendXID(m_nMyAddress, nDestination, false, (byte) 0xFF, DISCOVERY_INFO);
}
public void sendNext(byte yConnection) throws Exception {
if ( !m_sendQueue.pendingDataRequests() ) {
throw new Exception("No pending requests");
}
IrLAPFrame nextFrame = m_sendQueue.getNext();
byte [] ayNextData = nextFrame.getData();
m_log.debug("IrLAPContext", "Data-Request(" + Utilities.bytesToString(ayNextData, 0, ayNextData.length) + ")");
m_framer.sendI(yConnection, m_nVr, nextFrame.getSequenceNumber(), true, ayNextData, 0, ayNextData.length);
}
public void sendRR(byte yConnection, boolean bCommand, boolean bFinal) throws Exception {
m_log.debug("IrLAPContext", "\tSend s:rr:" + (bCommand ? "cmd" : "rsp") + ":" + m_nVr + ":" + (bFinal ? "F" : "~F"));
m_framer.sendRR(yConnection, m_nVr, bCommand, bFinal);
}
public void sendSNRM(int nDestination, byte yConnection) throws Exception {
m_log.debug("IrLAPContext", "\tsend u:snrm:cmd:P:" + yConnection + ":" + nDestination);
m_framer.sendSNRM(m_nMyAddress, nDestination, yConnection);
}
public void sendUA(int nDestination, byte yConnection, boolean bSendParameters) throws Exception {
if ( bSendParameters ) {
m_log.debug("IrLAPContext", "\tsend u:ua:cmd:F (+ parameters) (" + Utilities.byteToString(yConnection) + ")");
} else {
m_log.debug("IrLAPContext", "\tsend u:ua:cmd:F (" + Utilities.byteToString(yConnection) + ")");
}
m_framer.sendUA(m_nMyAddress, nDestination, yConnection, bSendParameters);
}
/*
public void setAckRequired(boolean bAckRequired) {
m_log.debug("ackRequired := " + bAckRequired);
m_bAckRequired = bAckRequired;
}
public void setConnectionConfirmed(boolean bConnectionConfirmed) {
m_log.debug("connection-confirm(" + bConnectionConfirmed + ")");
m_bConnectionConfirmed = bConnectionConfirmed;
}
*/
public void setSlotCount(byte slotCount) throws Exception {
m_log.debug("IrLAPContext", "\tslotCount := slotCount + 1");
_slotCount = slotCount;
}
public void setFramer(IrLAPFramer framer) throws Exception {
m_framer = framer;
m_framer.addIrLAPFramerListener(this);
}
public void setFrameSent(boolean bFrameSent) throws Exception {
m_log.debug("IrLAPContext", "\tframeSent := " + bFrameSent);
m_bFrameSent = bFrameSent;
}
public void setMediaBusy(boolean isBusy) throws Exception {
m_log.debug("IrLAPContext", "\tisBusy := " + isBusy);
m_bMediaBusy = isBusy;
}
public void setRemoteBusy(boolean bRemoteBusy) throws Exception {
m_log.debug("IrLAPContext", "\tremoteBusy := " + bRemoteBusy);
m_bRemoteBusy = bRemoteBusy;
}
public void startFTimer() throws Exception {
m_log.debug("IrLAPContext", "\tstart-F-timer");
m_fTimer.setRepeats(false);
m_fTimer.start();
}
public void startQueryTimer() throws Exception {
m_log.debug("IrLAPContext", "\tstart-query-timer");
m_queryTimer.setRepeats(false);
m_queryTimer.start();
}
public void startSlotTimer() throws Exception {
m_log.debug("IrLAPContext", "\tstart-slot-timer");
_slotTimer.stop();
_slotTimer.setRepeats(false);
_slotTimer.start();
}
public void startWatchdogTimer() throws Exception {
m_log.debug("IrLAPContext", "\tstart-WD-timer");
m_watchdogTimer.stop();
m_watchdogTimer.setRepeats(false);
m_watchdogTimer.start();
}
public void stopQueryTimer() throws Exception {
m_log.debug("IrLAPContext", "\tstop-query-timer");
m_queryTimer.stop();
}
public void stopSlotTimer() throws Exception {
m_log.debug("IrLAPContext", "\tstop-slot-timer");
_slotTimer.stop();
}
public void stopWatchdogTimer() throws Exception {
m_log.debug("IrLAPContext", "\tstop-WD-timer");
m_watchdogTimer.stop();
}
/**
* Acknowledge frames through Nr - 1 by removing them from
* the send queue.
*/
public void updateNr(int nNr) throws Exception {
// Damned sign extension.
nNr &= 0x00000007;
m_log.debug("IrLAPContext", "\tUpdate Nr Received (Nr: " + nNr + ")");
m_log.debug("IrLAPContext", "\t\tsend queue size = " + m_sendQueue.size());
int i = 0;
while ( i < m_sendQueue.size() ) {
IrLAPFrame frame = m_sendQueue.get(i);
int sequenceNumber = frame.getSequenceNumber();
m_log.debug("IrLAPContext", "\t\tframe sequence number = " + frame.getSequenceNumber());
if ( (sequenceNumber < nNr) || ((sequenceNumber == 7) && (0 == nNr)) ) {
m_log.debug("IrLAPContext", "\t\tpeer acknowledges receipt of frame " + frame.getSequenceNumber() + ", removing from send buffer");
m_sendQueue.remove(i);
i --;
}
i++;
}
}
public void waitMinimumTurnaroundTime() throws Exception {
//m_log.debug("IrLAPContext", "\tWait-Minimum-Turnaround-Time");
//Thread.sleep(DEFAULT_MIN_TURNAROUND_MSEC);
}
public void zeroRetryCount() throws Exception {
m_log.debug("IrLAPContext", "\tretryCount := 0");
m_nRetryCount = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -