2016-05-20 7 views
0

OMNeT ++ 4.5を使用してワイヤレスセンサーネットワークのMACプロトコルをシミュレートするコードを作成しています。しかし、CCA(Carrier channel assessment)の実装方法はわかりません。サンプルコードを教えてください。OMNet ++ 4.5でCCAを実装する方法

答えて

0

私はあなたがアンナ・フェルスター

によってMiXiMにおけるWSNのためにB-MACプロトコルの 実装を参照することができ、より詳しくは、INETにBMacLayer.ccファイルを読み込む

case CCA: 
      if (msg->getKind() == BMAC_CCA_TIMEOUT) { 
       // channel is clear 
       // something waiting in eth queue? 
       if (macQueue.size() > 0) { 
        EV_DETAIL << "State CCA, message CCA_TIMEOUT, new state" 
           " SEND_PREAMBLE" << endl; 
        macState = SEND_PREAMBLE; 
        radio->setRadioMode(IRadio::RADIO_MODE_TRANSMITTER); 
        changeDisplayColor(YELLOW); 
        scheduleAt(simTime() + slotDuration, stop_preambles); 
        return; 
       } 
       // if not, go back to sleep and wake up after a full period 
       else { 
        EV_DETAIL << "State CCA, message CCA_TIMEOUT, new state SLEEP" 
           << endl; 
        scheduleAt(simTime() + slotDuration, wakeup); 
        macState = SLEEP; 
        radio->setRadioMode(IRadio::RADIO_MODE_SLEEP); 
        changeDisplayColor(BLACK); 
        return; 
       } 
      } 
      // during CCA, we received a preamble. Go to state WAIT_DATA and 
      // schedule the timeout. 
      if (msg->getKind() == BMAC_PREAMBLE) { 
       nbRxPreambles++; 
       EV_DETAIL << "State CCA, message BMAC_PREAMBLE received, new state" 
          " WAIT_DATA" << endl; 
       macState = WAIT_DATA; 
       cancelEvent(cca_timeout); 
       scheduleAt(simTime() + slotDuration + checkInterval, data_timeout); 
       delete msg; 
       return; 
      } 
      // this case is very, very, very improbable, but let's do it. 
      // if in CCA and the node receives directly the data packet, switch to 
      // state WAIT_DATA and re-send the message 
      if (msg->getKind() == BMAC_DATA) { 
       nbRxDataPackets++; 
       EV_DETAIL << "State CCA, message BMAC_DATA, new state WAIT_DATA" 
          << endl; 
       macState = WAIT_DATA; 
       cancelEvent(cca_timeout); 
       scheduleAt(simTime() + slotDuration + checkInterval, data_timeout); 
       scheduleAt(simTime(), msg); 
       return; 
      } 
      //in case we get an ACK, we simply dicard it, because it means the end 
      //of another communication 
      if (msg->getKind() == BMAC_ACK) { 
       EV_DETAIL << "State CCA, message BMAC_ACK, new state CCA" << endl; 
       delete msg; 
       return; 
      } 
      break; 

をお勧めします

関連する問題