Program: 75316
Project: 75316
Buggy source:
public void fire() throws IllegalActionException {
  super.fire();
  int oldnum=_numBusyTimers;
  int kind=whoTimeout2();
  double currentTime=getDirector().getCurrentTime();
  if (oldnum > 0 && _numBusyTimers == 0) {
    RecordToken ChannelStatusMsg=new RecordToken(SignalMsgFields,new Token[]{new IntToken(Idle)});
    channelStatus.send(0,ChannelStatusMsg);
  }
  double power, duration;
  RecordToken msg;
switch (_currentState) {
case Idle:
    if (fromChannel.hasToken(0)) {
      _data=(RecordToken)fromChannel.get(0);
      RecordToken properties=(RecordToken)((WirelessIOPort)fromChannel).getProperties(0);
      power=((DoubleToken)properties.get("String_Node_Str")).doubleValue();
      duration=((DoubleToken)properties.get("String_Node_Str")).doubleValue();
      if (power > _sensitivity && ((_interference == 0.0) || (power / _interference > _SNRThresholdInDB))) {
        setTimer2(RxDone,currentTime + duration,power);
        _numBusyTimers++;
        if (_numBusyTimers == 1) {
          RecordToken ChannelStatusMsg=new RecordToken(SignalMsgFields,new Token[]{new IntToken(Busy)});
          channelStatus.send(0,ChannelStatusMsg);
        }
        Token[] RxStartValues={new IntToken(RxStart),_data.get("String_Node_Str")};
        RecordToken RxStartMsg=new RecordToken(RxStartMsgFields,RxStartValues);
        toMAC.send(0,RxStartMsg);
        _receivedPower=power;
        _currentState=Receive;
      }
 else {
        setTimer2(InterferenceDone,currentTime + duration,power);
        _interference=_interference + power;
      }
    }
 else     if (fromMAC.hasToken(0)) {
      msg=(RecordToken)fromMAC.get(0);
      if (((IntToken)msg.get("String_Node_Str")).intValue() == TxStart)       _startTransmission(msg);
    }
  break;
case Receive:
if (kind == RxDone) {
  Token[] RxDataValues={new IntToken(RxData),_data.get("String_Node_Str")};
  RecordToken RxDataMsg=new RecordToken(RxDataMsgFields,RxDataValues);
  toMAC.send(0,RxDataMsg);
  Token[] RxEndValues={new IntToken(RxEnd),new IntToken(_rxStatus)};
  RecordToken RxEndMsg=new RecordToken(RxStartMsgFields,RxEndValues);
  toMAC.send(0,RxEndMsg);
  _currentState=Idle;
}
 else if (fromChannel.hasToken(0)) {
  _handleInterference();
  if (_receivedPower / _interference <= _SNRThresholdInDB)   _rxStatus=Error;
}
 else if (fromMAC.hasToken(0)) {
  msg=(RecordToken)fromMAC.get(0);
  if (((IntToken)msg.get("String_Node_Str")).intValue() == TxStart) {
    _startTransmission(msg);
    Token[] RxEndValues={new IntToken(RxEnd),new IntToken(Error)};
    RecordToken RxEndMsg=new RecordToken(RxEndMsgFields,RxEndValues);
    toMAC.send(0,RxEndMsg);
  }
}
break;
case Transmit:
if (kind == TxDone) {
RecordToken TxEndMsg=new RecordToken(SignalMsgFields,new Token[]{new IntToken(TxEnd)});
PHYConfirm.send(0,TxEndMsg);
_currentState=Idle;
}
 else if (fromChannel.hasToken(0)) {
_handleInterference();
}
 else if (fromMAC.hasToken(0)) {
msg=(RecordToken)fromMAC.get(0);
if (((IntToken)msg.get("String_Node_Str")).intValue() == TxData) {
Token[] ChMsgValues={new IntToken(_txRate),msg.get("String_Node_Str")};
RecordToken ChMsg=new RecordToken(ChMsgFields,ChMsgValues);
toChannel.send(0,ChMsg);
_setAttribute(_duration,new DoubleToken(_txDuration));
setTimer2(TxDone,currentTime + _txDuration,0.0);
}
}
break;
}
}

Fixed version (ground truth):
public void fire() throws IllegalActionException {
  super.fire();
  int oldnum=_numBusyTimers;
  int kind=whoTimeout2();
  double currentTime=getDirector().getCurrentTime();
  if (oldnum > 0 && _numBusyTimers == 0) {
    RecordToken ChannelStatusMsg=new RecordToken(SignalMsgFields,new Token[]{new IntToken(Idle)});
    channelStatus.send(0,ChannelStatusMsg);
  }
  double power=0, duration=-1;
  RecordToken msg;
switch (_currentState) {
case PHY_Idle:
    if (fromChannel.hasToken(0)) {
      _data=(RecordToken)fromChannel.get(0);
      Iterator connectedPorts=fromChannel.sourcePortList().iterator();
      while (connectedPorts.hasNext()) {
        IOPort port=(IOPort)connectedPorts.next();
        if (port.isInput() && port instanceof WirelessIOPort) {
          RecordToken properties=(RecordToken)((WirelessIOPort)port).getProperties(0);
          power=((DoubleToken)properties.get("String_Node_Str")).doubleValue();
          duration=((DoubleToken)properties.get("String_Node_Str")).doubleValue();
          break;
        }
      }
      if (power > 0) {
        setTimer2(RxDone,currentTime + duration,power);
        _numBusyTimers++;
        if (_numBusyTimers == 1) {
          RecordToken ChannelStatusMsg=new RecordToken(SignalMsgFields,new Token[]{new IntToken(Busy)});
          channelStatus.send(0,ChannelStatusMsg);
        }
        Token[] RxStartValues={new IntToken(RxStart),_data.get("String_Node_Str")};
        RecordToken RxStartMsg=new RecordToken(RxStartMsgFields,RxStartValues);
        toMAC.send(0,RxStartMsg);
        _receivedPower=power;
        _currentState=Receive;
      }
 else {
        setTimer2(InterferenceDone,currentTime + duration,power);
        _interference=_interference + power;
      }
    }
 else     if (fromMAC.hasToken(0)) {
      msg=(RecordToken)fromMAC.get(0);
      if (((IntToken)msg.get("String_Node_Str")).intValue() == TxStart) {
        _startTransmission(msg);
      }
    }
  break;
case Receive:
if (kind == RxDone) {
  Token[] RxDataValues={new IntToken(RxData),_data.get("String_Node_Str")};
  RecordToken RxDataMsg=new RecordToken(RxDataMsgFields,RxDataValues);
  toMAC.send(0,RxDataMsg);
  Token[] RxEndValues={new IntToken(RxEnd),new IntToken(_rxStatus)};
  RecordToken RxEndMsg=new RecordToken(RxEndMsgFields,RxEndValues);
  toMAC.send(0,RxEndMsg);
  _currentState=PHY_Idle;
}
 else if (fromChannel.hasToken(0)) {
  _handleInterference();
  if (_receivedPower / _interference <= _SNRThresholdInDB) {
    _rxStatus=Error;
  }
}
 else if (fromMAC.hasToken(0)) {
  msg=(RecordToken)fromMAC.get(0);
  if (((IntToken)msg.get("String_Node_Str")).intValue() == TxStart) {
    _startTransmission(msg);
    Token[] RxEndValues={new IntToken(RxEnd),new IntToken(Error)};
    RecordToken RxEndMsg=new RecordToken(RxEndMsgFields,RxEndValues);
    toMAC.send(0,RxEndMsg);
  }
}
break;
case Transmit:
if (kind == TxDone) {
RecordToken TxEndMsg=new RecordToken(SignalMsgFields,new Token[]{new IntToken(TxEnd)});
PHYConfirm.send(0,TxEndMsg);
_currentState=PHY_Idle;
}
 else if (fromChannel.hasToken(0)) {
_handleInterference();
}
 else if (fromMAC.hasToken(0)) {
msg=(RecordToken)fromMAC.get(0);
if (((IntToken)msg.get("String_Node_Str")).intValue() == TxData) {
Token[] ChMsgValues={new IntToken(_txRate),msg.get("String_Node_Str")};
RecordToken ChMsg=new RecordToken(ChMsgFields,ChMsgValues);
toChannel.send(0,ChMsg);
setTimer2(TxDone,currentTime + _txDuration,0.0);
}
}
break;
}
}