?? macs.c
字號:
#include "mac.h"
extern MAC_STATE_TYPE mac_current_state;
extern MAC_PIB mac_pib_data;
extern uint8_t current_pending_num;
extern SHORT_ADDR default_short_addr;
void mlmeScanConfirm(MLME_SCAN_CONFIRM scan_result_info)
{
//根據scan_result_info來修改對應的mac層和PHY層的pib信息
//本來有個復雜的選擇算法,這里簡單處理第一個
//printf("\n-------it is in scan confirm---------\n");
if((scan_result_info.status==SUCCESS)&&(scan_result_info.scanType==ORPHAN_SCAN))
{
//printf("\n----SUCCESSFULL ORPHAN SCAN----\n");
mac_current_state=MAC_STATE_IDLE;
return;
}
if((scan_result_info.status==SUCCESS)&&(scan_result_info.scanType==ACTIVE_PASSIVE_SCAN))
{//printf("\n-------it is in scan confirm---------\n");
mac_current_state=MAC_STATE_ACTIVE_PASSIVE_SCAN_FINISHED;
//printf("\n-----the macbeacon is %02x\n",scan_result_info.pPANDescriptorList[0].superframeSpec.SF.bytes.LSB);
mac_pib_data.macBeaconOrder=((scan_result_info.pPANDescriptorList[0].superframeSpec.SF.bytes.LSB)&0x0f);
mac_pib_data.macSuperframeOrder=((scan_result_info.pPANDescriptorList[0].superframeSpec.SF.bytes.LSB)>>4);
mac_pib_data.macPANId.Val=scan_result_info.pPANDescriptorList[0].coordinator.panID.Val;
if(scan_result_info.pPANDescriptorList[0].coordinator.addrMode==0x02)
{
mac_pib_data.macCoordShortAddress.Val=scan_result_info.pPANDescriptorList[0].coordinator.shortAddr.Val;
}
else if(scan_result_info.pPANDescriptorList[0].coordinator.addrMode==0x03)
{
mac_pib_data.macCoordExtendedAddress.longaddr=scan_result_info.pPANDescriptorList[0].coordinator.longAddr.longaddr;
}
ppib.phyCurrentChanel=scan_result_info.pPANDescriptorList[0].logicalChannel;
//PLME_SET_request(phyCurrentChanel_id, ppib.phyCurrentChanel);
//OS_post(synrequest_task);
}
else
{
if(!IS_COORDINATOR)
{
mac_current_state=MAC_STATE_UNSTARTED;
//printf("\n--PASSIVE SCAN FAILURE-----\n");
}
else
{
mac_current_state=MAC_STATE_ACTIVE_PASSIVE_SCAN_FINISHED;
//printf("\n---doesn't exist any 802.15.4 network ----\n");
//printf("---I will be the coordinator----");
}
//OS_post(scan_task);
}
}
void mlmeStartConfirm(void)
{
//通知高層發送完畢。
//可以通過post高層任務來完成高層的函數任務
//空函數,高層實現
}
void mlmeAssociateConfirm(SHORT_ADDR AssocShortAddress, BYTE status)
{
//printf("\n------success associate------ %d\n",status);
//printf("\nthe allocated short address is %04x\n",AssocShortAddress.Val);
if(status==NO_ACK)
{
printf("\n----the association request frame is no acked-----\n");
//mac_current_state=MAC
}
//兩種情況為NO_DATA
if(status==NO_DATA)
printf("\n---didn't received the association response frame---\n");
if(status==SUCCESS)
{
mac_current_state=MAC_STATE_ASSOC_FINISHED;
//mac_current_state=MAC_STATE_IDLE;
//mac_current_state_saved=MAC_STATE_IDLE;
phy_channel_state=PHY_IDLE;
PLME_SET_TRX_STATE_request(RX_ON);
mac_pib_data.macShortAddress=AssocShortAddress;
cc2420_setshortaddress((uint16_t)mac_pib_data.macShortAddress.Val);
cc2420_setpanid((uint16_t)mac_pib_data.macPANId.Val);
}
else
{
//主要工作由網絡層決定
mac_current_state=MAC_STATE_ACTIVE_PASSIVE_SCAN_FINISHED;
}
}
//**************************//
void mlmeAssociateIndication(MLME_ASSOCIATE_INDICATION mlme_associate_indication_info)
{
//協調者在收到associate request幀后通知高層
//可以post高層任務
BYTE status;
SHORT_ADDR shortaddr_alloc;
//主要任務是調用mlmeassociateresponse原語
//------------------------------------------------------
//---------------待添加------------------------------
//--------網絡層是否決定關聯-------------------
//--------修改status,分配shortaddr--------------------
//printf("\n------success received an association request frame--------\n");
//for(uint8_t i=0;i<8;i++)
// printf("\nthe addr is v[%d]=%d\n",i,mlme_associate_indication_info.Deviceaddr.v[i]);
//shortaddr_alloc.Val=RFD_SHORT_ADDRESS;
shortaddr_alloc=short_address_allocate_req(mlme_associate_indication_info.Deviceaddr);
printf("\n---allocated short addr is %04x---\n",shortaddr_alloc.Val);
status=0x00;
mlmeAssociateResponse(mlme_associate_indication_info.Deviceaddr, shortaddr_alloc,status, FALSE);
}
//**************************//
void mlmeAssociateResponse(LONG_ADDR deviceAddress, SHORT_ADDR assocShortAddress, BYTE status, bool securityEnable)
{
//協調者的高層在收到associate indication原語后響應MAC層的原語
//MAC層調用發送任務發送associate response幀
FRAME_CONTROL framectl_field;
NODE_INFO dst;
NODE_INFO src;
//下面不用做.
dst.addrMode=0x03;
src.addrMode=0x03;
dst.panID=mac_pib_data.macPANId;
src.panID=mac_pib_data.macPANId;
src.longAddr=mac_pib_data.macExtAddress;
dst.longAddr=deviceAddress;
framectl_field.v[0]=0x23;
framectl_field.v[1]=0xcc;
//
if((IS_FFD!=0x00)&&(mac_current_state==MAC_STATE_IDLE)&&(current_pending_num<MAX_PENDING_LIST_SIZE))
{
add_pending_queue(0, framectl_field, dst,src,0, NULL, status, TRUE, deviceAddress,assocShortAddress);
}
else if(current_pending_num>=MAX_PENDING_LIST_SIZE)
{
//printf("\npending full\n");
//向上層報告
//mlme_comm_status()
}
//--------------------------------------------------
//In order to test the disassociation frame from the coordinator
//LONG_ADDR RFD_LONG_ADDR;
//test the coordinator want the RFD leave the network
//mlmeDisassociateRequest(deviceAddress,0x01, FALSE);
//---------------------------------------------------
}
void mlmeDisassociateIndication(LONG_ADDR deviceAddress, BYTE disassociateReason, bool securityUse, BYTE aclEntry)
{
//協調者或終端設備在收到對方發過來的disassociation notification幀后
//通知高層。post高層任務
//空函數,高層實現
//------------------------------------------------------
//---------------待添加------------------------------
//--------網絡層刪除對應的associate記錄--------
//-------------------------------------------------------
if(!IS_COORDINATOR)
{
//printf("\n--the RFD received the disassociation indiation----\n");
mac_current_state=MAC_STATE_IDLE;
}
else
{
printf("\n----the coordinator received the disassociation indication----\n");
}
}
void mlmeDisassociateConfirm(MAC_ENUM status)
{
//在MAC層發送完成(無論成功與失敗),將調用該原語通知高層
//恢復系統的MAC層的狀態變量
//可以post一個高層任務
//空函數,高層實現
if(status==SUCCESS)
{
if(!IS_COORDINATOR)
{
printf("\n---success disassociated from the network-----\n");
}
else
{
printf("\n---success disassociated the object RFD from the network------\n");
}
}
}
//*************************//
void mlmeOrphanIndication(LONG_ADDR orphanAddress, bool securityUse, BYTE aclEntry)
{
//協調者或簇頭節點在收到一個設備發送過來的orphan nitification幀時候通知高層的原語
//完成高層任務,該任務主要是調用orphan response原語。
SHORT_ADDR shortaddress;
//查找對應orphanAddress的shortaddress.
//-------------------------------------------
//-------------------待添加--------------
//--------------網絡層的代碼----------
//shortaddress.Val=0xfc8b;
//shortaddress.Val=RFD_SHORT_ADDRESS;
printf("\nsuccess received a orphan notification frame\n");
shortaddress=short_address_allocate_req(orphanAddress);
mlmeOrphanResponse(orphanAddress, shortaddress, TRUE, FALSE);
}
//*************************//
void mlmeCommStatusIndication(WORD panId, BYTE srcAddrMode, ADDRESS *pSrcAddr, BYTE dstAddrMode, ADDRESS *pDstAddr, BYTE status)
{
//通知高層顯示response幀的傳輸情況
//空函數
}
void mlmeRxEnableRequest(bool deferPermit, uint32_t rxOnTime, uint32_t rxOnDuration)
{
//空函數
}
void mlmeRxEnableConfirm(MAC_ENUM status)
{
//空函數
}
void mlmeSyncLossIndication(MAC_ENUM lossReason)
{
//三種原因導致MAC層發送該原語通知高層。
//可通過post一個高層任務。高層對丟失同步可能要重新做出處理。
//空函數,高層實現
NODE_INFO dst;
//printf("\n--- a PAN ID conlict ----\n");
if(IS_COORDINATOR)
{
//可能需要重新設置一下mac層網絡參數
coordinator_realignment_frame_send(0, dst, default_short_addr);
mac_current_state=MAC_STATE_IDLE;
}
else
{
if(lossReason==BEACON_LOSS)
//網絡重啟動
mac_current_state=MAC_STATE_UNSTARTED;
//或者
//mac_current_state=MAC_STATE_ENERGY_SCAN_FINISHED;
}
}
void mcpsDataConfirm(MAC_ENUM status, BYTE msduHandle)
{
//作為MAC層對mcpsdatarequest的一個響應,通知高層
//空函數,高層實現
printf("\n----sensor data is sent successfull-----\n");
mac_current_state=MAC_STATE_START_TO_SLEEP;
}
void mcpsDataIndication(MCPS_DATA_INDICATION mcps_data_indication_info)
{
//MAC接收到一個數據幀后,通知高層,可post一個高層任務
//空函數,高層實現
printf("\n-----success received the sensor data-------\n");
if(IS_COORDINATOR)
sensor_data_tx_to_pc(mcps_data_indication_info);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -