📄 gtsmanagementexamplem.nc
字号:
/*
*
* @author IPP HURRAY http://www.hurray.isep.ipp.pt/art-wise
* @author Andre Cunha
*
*/
module GTSManagementExampleM
{
provides {
interface StdControl;
}
uses {
interface Timer;
interface Leds;
interface MLME_START;
interface MLME_ASSOCIATE;
interface MLME_DISASSOCIATE;
interface MLME_SCAN;
interface MLME_RESET;
interface MLME_SYNC;
interface MLME_SYNC_LOSS;
interface MLME_BEACON_NOTIFY;
interface MLME_COMM_STATUS;
interface MLME_SET;
interface MLME_GET;
interface MLME_GTS;
//MCPS
interface MCPS_DATA;
interface MCPS_PURGE;
interface StdControl as Mac_control;
//Period of the GTS traffic generation
interface Timer as Application_GTS_Traffic_Period_Timer;
interface Time;
}
}
implementation
{
uint8_t beacon_present=0;
uint8_t on_sync=0;
uint8_t gts_allocated=0;
uint8_t gts_superframe_count=0;
PANDescriptor pan_des;
uint32_t my_short_address=0x00000000;
uint32_t my_pan_id=0x00000001;
command result_t StdControl.init() {
return SUCCESS;
}
command result_t StdControl.start() {
printfUART("i_am_pan: %i\n", TYPE_DEVICE);
if (TYPE_DEVICE == COORDINATOR)
{
call Timer.start(TIMER_ONE_SHOT,5000);
}
else
{
call Timer.start(TIMER_ONE_SHOT,5000);
}
return SUCCESS;
}
command result_t StdControl.stop() {
call Mac_control.stop();
return SUCCESS;
}
//fired when the mote starts
event result_t Timer.fired()
{
uint8_t v_temp[2];
if (TYPE_DEVICE == COORDINATOR)
{
my_short_address = 0x0000;
v_temp[0] = (uint8_t)(my_short_address >> 8);
v_temp[1] = (uint8_t)(my_short_address );
call MLME_SET.request(MACSHORTADDRESS,v_temp);
call MLME_START.request(PANID, LOGICAL_CHANNEL, BEACON_ORDER, SUPERFRAME_ORDER,1,0,0,0,0);
call Application_GTS_Traffic_Period_Timer.start(TIMER_REPEAT,200);
call Timer.stop();
}
else
{
my_short_address = TOS_LOCAL_ADDRESS;
v_temp[0] = (uint8_t)(my_short_address >> 8);
v_temp[1] = (uint8_t)(my_short_address );
call MLME_SET.request(MACSHORTADDRESS,v_temp);
call Leds.greenOn();
gts_superframe_count=0;
printfUART("GTS req: %i\n", TYPE_DEVICE);
//allocate a transmission GTS - enables a GTS time slot allocation for the device transmission to the PAN Coordinator
call MLME_GTS.request(set_gts_characteristics(1, GTS_TX_ONLY,1),0x00);
//allocate a transmission GTS - enables a GTS time slot allocation for the PAN coordinator transmission to the device
//call MLME_GTS.request(set_gts_characteristics(1, GTS_RX_ONLY,1),0x00);
//enable the transmission of the device to the PAN coordinator in the allocated transmit GTS
call Application_GTS_Traffic_Period_Timer.start(TIMER_REPEAT,500);
}
return SUCCESS;
}
/*****************************************************************************************************/
/*****************************************************************************************************/
/**************************************MLME EVENTS****************************************************/
/*****************************************************************************************************/
/*****************************************************************************************************/
/*****************************************************************************************************/
/**************************************MLME-GTS*******************************************************/
/*****************************************************************************************************/
event result_t MLME_GTS.confirm(uint8_t GTSCharacteristics, uint8_t status)
{
switch(status)
{
case MAC_SUCCESS: gts_allocated=1;
call Leds.greenOn();
break;
case MAC_DENIED: gts_allocated=0;
break;
case MAC_NO_SHORT_ADDRESS: gts_allocated=0;
break;
case MAC_CHANNEL_ACCESS_FAILURE: gts_allocated=0;
break;
case MAC_NO_ACK: gts_allocated=0;break;
case MAC_NO_DATA: gts_allocated=0;break;
default: break;
}
return SUCCESS;
}
event result_t MLME_GTS.indication(uint16_t DevAddress, uint8_t GTSCharacteristics, bool SecurityUse, uint8_t ACLEntry)
{
return SUCCESS;
}
/*****************************************************************************************************/
/**************************************MLME-START*****************************************************/
/*****************************************************************************************************/
event result_t MLME_START.confirm(uint8_t status)
{
return SUCCESS;
}
/*****************************************************************************************************/
/**************************************MLME-ASSOCIATE*************************************************/
/*****************************************************************************************************/
event result_t MLME_ASSOCIATE.indication(uint32_t DeviceAddress[], uint8_t CapabilityInformation, bool SecurityUse, uint8_t ACLEntry)
{
return SUCCESS;
}
event result_t MLME_ASSOCIATE.confirm(uint16_t AssocShortAddress, uint8_t status)
{
return SUCCESS;
}
/*****************************************************************************************************/
/**************************************MLME-DISASSOCIATE**********************************************/
/*****************************************************************************************************/
event result_t MLME_DISASSOCIATE.indication(uint32_t DeviceAddress[], uint8_t DisassociateReason, bool SecurityUse, uint8_t ACLEntry)
{
return SUCCESS;
}
event result_t MLME_DISASSOCIATE.confirm(uint8_t status)
{
return SUCCESS;
}
/*****************************************************************************************************/
/**************************************MLME-BEACON NOTIFY*********************************************/
/*****************************************************************************************************/
event result_t MLME_BEACON_NOTIFY.indication(uint8_t BSN,PANDescriptor pan_descriptor, uint8_t PenAddrSpec, uint8_t AddrList, uint8_t sduLength, uint8_t sdu[])
{
gts_superframe_count++;
if (gts_superframe_count==30)
{
call Leds.greenOff();
call MLME_GTS.request(set_gts_characteristics(1, GTS_TX_ONLY,0),0x00);
}
return SUCCESS;
}
/*****************************************************************************************************/
/*********************** MLME-SYNC_LOSS **************************************/
/*****************************************************************************************************/
event result_t MLME_SYNC_LOSS.indication(uint8_t LossReason)
{
//printfUART("SyncLoss\n", "");
//call Timer.start(TIMER_REPEAT,1000);
return SUCCESS;
}
/*****************************************************************************************************/
/************************* MLME-RESET ********************************************/
/*****************************************************************************************************/
event result_t MLME_RESET.confirm(uint8_t status)
{
return SUCCESS;
}
/*****************************************************************************************************/
/************************* MLME-SCAN *******************************************/
/*****************************************************************************************************/
event result_t MLME_SCAN.confirm(uint8_t status,uint8_t ScanType, uint32_t UnscannedChannels, uint8_t ResultListSize, uint8_t EnergyDetectList[], SCAN_PANDescriptor PANDescriptorList[])
{
printfUART("MLME_SCAN.confirm\n", "");
return SUCCESS;
}
/*****************************************************************************************************/
/************************** MLME-COMM_STATUS **************************************/
/*****************************************************************************************************/
event result_t MLME_COMM_STATUS.indication(uint16_t PANId,uint8_t SrcAddrMode, uint32_t SrcAddr[], uint8_t DstAddrMode, uint32_t DstAddr[], uint8_t status)
{
return SUCCESS;
}
/*****************************************************************************************************/
/************************* MLME-GET ******************************************/
/*****************************************************************************************************/
event result_t MLME_GET.confirm(uint8_t status,uint8_t PIBAttribute, uint8_t PIBAttributeValue[])
{
return SUCCESS;
}
/*****************************************************************************************************/
/********************** MLME-SET ******************************************/
/*****************************************************************************************************/
event result_t MLME_SET.confirm(uint8_t status,uint8_t PIBAttribute)
{
return SUCCESS;
}
/*****************************************************************************************************/
/*****************************************************************************************************/
/**************** MCPS EVENTS *************************************/
/*****************************************************************************************************/
/*****************************************************************************************************/
/*****************************************************************************************************/
/********************* MCPS-DATA ***************************************/
/*****************************************************************************************************/
event result_t MCPS_DATA.confirm(uint8_t msduHandle, uint8_t status)
{
return SUCCESS;
}
event result_t MCPS_DATA.indication(uint16_t SrcAddrMode, uint16_t SrcPANId, uint32_t SrcAddr[2], uint16_t DstAddrMode, uint16_t DestPANId, uint32_t DstAddr[2], uint16_t msduLength,uint8_t msdu[100],uint16_t mpduLinkQuality, uint16_t SecurityUse, uint16_t ACLEntry)
{
return SUCCESS;
}
/*****************************************************************************************************/
/************************* MCPS-PURGE *************************************/
/*****************************************************************************************************/
event result_t MCPS_PURGE.confirm(uint8_t msduHandle, uint8_t status)
{
return SUCCESS;
}
/*****************************************************************************************************/
/*********************** OTHER FUNCTIONS **************************************/
/*****************************************************************************************************/
event result_t Application_GTS_Traffic_Period_Timer.fired()
{
uint32_t SrcAddr[2];
uint32_t DstAddr[2];
uint8_t msdu_payload[4];
if (TYPE_DEVICE == COORDINATOR)
{
SrcAddr[0]=0x00000000;
SrcAddr[1]=TOS_LOCAL_ADDRESS;
DstAddr[0]=0x00000000;
DstAddr[1]=0x00000002;
call MCPS_DATA.request(SHORT_ADDRESS, PANID, SrcAddr, SHORT_ADDRESS, PANID, DstAddr, 4, msdu_payload,1,set_txoptions(1,1,0,0));
}
else
{
SrcAddr[0]=0x00000000;
SrcAddr[1]=TOS_LOCAL_ADDRESS;
DstAddr[0]=0x00000000;
DstAddr[1]=0x00000000;
call MCPS_DATA.request(SHORT_ADDRESS, PANID, SrcAddr, SHORT_ADDRESS, PANID, DstAddr, 4, msdu_payload,1,set_txoptions(1,1,0,0));
}
return SUCCESS;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -