|
本帖最后由 laoxiaomage 于 2014-7-2 14:32 编辑
请教楼主,就SampleApp这里例子里 YOURNAME_NETCONF_CLUSTERID 怎么写?我猜就是端点接收的 ELINKCS_NETCONF_CLUSTERID?我是这么写的:
const cId_t SampleApp_ClusterList[SAMPLEAPP_MAX_CLUSTERS] =
{
SAMPLEAPP_PERIODIC_CLUSTERID,
SAMPLEAPP_FLASH_CLUSTERID,
ELINKCS_NETCONF_CLUSTERID//macq add 我添加的
};
#define SAMPLEAPP_MAX_CLUSTERS 3 // 2 //macq modify 加多了一个
#define SAMPLEAPP_PERIODIC_CLUSTERID 1
#define SAMPLEAPP_FLASH_CLUSTERID 2
#define ELINKCS_NETCONF_CLUSTERID 3 //macq add 我添加的
修改PAN_ID调用的函数,广播:
static afStatus_t UpdateAllNetwork(uint16 panId)//, uint8 channelId 只修改PAN_ID
{
afAddrType_t dstAddr;
uint8 dataLength = 2;//3; //PAN ID+CHANNEL,只修改PAN_ID
uint8 *msg = osal_mem_alloc(dataLength);
dstAddr.addrMode = (afAddrMode_t)afAddrBroadcast;
dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL;
dstAddr.endPoint = AF_BROADCAST_ENDPOINT;
msg[0] = LO_UINT16(panId);
msg[1] = HI_UINT16(panId);
//msg[2] = channelId; //只修改PAN_ID
return AF_DataRequest(&dstAddr,
&SampleApp_epDesc,
ELINKCS_NETCONF_CLUSTERID,//YOURNAME_NETCONF_CLUSTERID, //macq modify 我修改的
dataLength,
msg,
&SampleApp_TransID,
0,
AF_DEFAULT_RADIUS);
}
协调器接收串口消息,修改PAN_ID,接收到串口消息修改自己的PAN_ID并且立即广播:
void MT_UtilSetPanID(uint8 *pBuf)
{
uint16 temp16;
uint8 retValue = ZFailure;
uint8 cmdId;
/* parse header */
cmdId = pBuf[MT_RPC_POS_CMD1];
pBuf += MT_RPC_FRAME_HDR_SZ;
temp16 = BUILD_UINT16(pBuf[0], pBuf[1]);
pBuf += sizeof(uint16);
//macq add for comport modify PANID
_NIB.nwkPanId = temp16;
NLME_UpdateNV(0x01);
//add end
retValue = osal_nv_write(ZCD_NV_PANID, 0, osal_nv_item_len( ZCD_NV_PANID ), &temp16);
/* Build and send back the response */
MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue);
// SystemResetSoft();//macq add for via comport modify PANID
if(UpdateAllNetwork(_NIB.nwkPanId) == afStatus_SUCCESS)//, _NIB.nwkLogicalChannel //广播
{
SystemResetSoft();
}
}
端点接收消息:
void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )//
{
uint16 flashTime;
switch ( pkt->clusterId )
{
case SAMPLEAPP_PERIODIC_CLUSTERID:
break;
case SAMPLEAPP_FLASH_CLUSTERID:
flashTime = BUILD_UINT16(pkt->cmd.Data[1], pkt->cmd.Data[2] );
HalLedBlink( HAL_LED_4, 4, 50, (flashTime / 4) );
break;
//配置网络信息
case ELINKCS_NETCONF_CLUSTERID://macq add
_NIB.nwkPanId=BUILD_UINT16(pkt->cmd.Data[0], pkt->cmd.Data[1] );
// _NIB.nwkLogicalChannel=pkt->cmd.Data[2];
NLME_UpdateNV(0x01);
HalLedBlink( HAL_LED_4, 6, 50, (flashTime / 4) );
SystemResetSoft();//macq add
// osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SYS_RESET_SOFT, 5000);//创建一个任务,5S后重启
break;
}
}
问题是,不用开端点,串口发送数据的时候
if(UpdateAllNetwork(_NIB.nwkPanId) == afStatus_SUCCESS)//, _NIB.nwkLogicalChannel
{
SystemResetSoft();
}
就已经执行了,当然,广播不成功,问题在哪里?请教各位大牛
也可以回我qq邮箱:331332430@qq.com,或者加我qq好友,多谢!
|
|