📄 simpleroutingexamplem.nc
字号:
/*
*
* @author IPP HURRAY http://www.hurray.isep.ipp.pt/art-wise
* @author Andre Cunha
*
*/
module SimpleRoutingExampleM
{
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;
interface MLME_POLL;
//MCPS
interface MCPS_DATA;
interface MCPS_PURGE;
interface StdControl as Mac_control;
interface Time;
interface Timer as Timer_send;
}
}
implementation
{
PANDescriptor pan_des;
uint32_t my_short_address=0x00000000;
uint32_t DestinationMote[2];
uint32_t SourceMoteAddr[2];
//number of routed packet (coordinator)
uint8_t routed_packets = 0x00;
command result_t StdControl.init() {
return SUCCESS;
}
command result_t StdControl.start() {
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()
{
//uint32_t SrcAddr[2];
uint8_t v_temp[2];
if (TYPE_DEVICE != COORDINATOR)
{
//device operation
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);
v_temp[0] = (uint8_t)(PANID >> 8);
v_temp[1] = (uint8_t)(PANID );
call MLME_SET.request(MACPANID,v_temp);
call Timer_send.start(TIMER_REPEAT,5000);
}
else
{
//coordinator operation
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);
}
return SUCCESS;
}
event result_t Timer_send.fired()
{
uint8_t msdu_payload[4];
DestinationMote[0]=0x00000000;
DestinationMote[1]=0x00000000;
msdu_payload[0] = 0x00;
msdu_payload[1] = 0x03;
SourceMoteAddr[0]=0x00000000;
SourceMoteAddr[1]=TOS_LOCAL_ADDRESS;
if (TOS_LOCAL_ADDRESS == 0x02)
{
call Leds.greenToggle(); //set_txoptions(ack, gts, indirect_transmission, security)
call MCPS_DATA.request(SHORT_ADDRESS, PANID, SourceMoteAddr, SHORT_ADDRESS, PANID, DestinationMote, 2, msdu_payload,1,set_txoptions(1,0,0,0));
}
return SUCCESS;
}
/*****************************************************************************************************/
/*****************************************************************************************************/
/**************************************MLME EVENTS****************************************************/
/*****************************************************************************************************/
/*****************************************************************************************************/
/*****************************************************************************************************/
/**************************************MLME-GTS*******************************************************/
/*****************************************************************************************************/
event result_t MLME_GTS.confirm(uint8_t GTSCharacteristics, uint8_t status)
{
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[])
{
return SUCCESS;
}
/*****************************************************************************************************/
/*********************** MLME-SYNC_LOSS **************************************/
/*****************************************************************************************************/
event result_t MLME_SYNC_LOSS.indication(uint8_t LossReason)
{
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 SourceAddr[], 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;
}
/*****************************************************************************************************/
/********************** MLME-POLL ******************************************/
/*****************************************************************************************************/
event result_t MLME_POLL.confirm(uint8_t status)
{
return SUCCESS;
}
/*****************************************************************************************************/
/*****************************************************************************************************/
/**************** MCPS EVENTS *************************************/
/*****************************************************************************************************/
/*****************************************************************************************************/
/*****************************************************************************************************/
/********************* MCPS-DATA ***************************************/
/*****************************************************************************************************/
event result_t MCPS_DATA.confirm(uint8_t msduHandle, uint8_t status)
{
//call Leds.redToggle();
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)
{
//routing procedure, the short address of the destination device is the first 2 bytes of the data payload
if (TYPE_DEVICE == COORDINATOR)
{
call Leds.greenToggle();
DestinationMote[0]=0x00000000;
DestinationMote[1]=(uint32_t) msdu[1];
routed_packets++;
msdu[0] = routed_packets;
//set_txoptions(ack, gts, indirect_transmission, security)
call MCPS_DATA.request(SHORT_ADDRESS, PANID, SrcAddr, SHORT_ADDRESS, PANID, DestinationMote, 1, msdu,1,set_txoptions(1,0,0,0));
}
else
{
call Leds.redToggle();
}
return SUCCESS;
}
/*****************************************************************************************************/
/************************* MCPS-PURGE *************************************/
/*****************************************************************************************************/
event result_t MCPS_PURGE.confirm(uint8_t msduHandle, uint8_t status)
{
return SUCCESS;
}
/*****************************************************************************************************/
/*********************** OTHER FUNCTIONS **************************************/
/*****************************************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -