CC2530 Note 1:( ProcessEvent, MSGpkt, MessageMSGCB)

来源:互联网 发布:earpods知乎 编辑:程序博客网 时间:2024/05/21 21:49

搞了半天CC2530  GenericApp 的总结:


最概况的话是

事件(Events) 触发 用户函数XXXApp_ProcessEvent() 
判断event 类型
1. System event: 接收MSGpkt 

  判断 MSGpkt-> hdr.event: case : XXXApp_MessageMSGCB或者xxx_SendTheMessage() 

2. 自定义Event: 自定义函数func()

具体追溯:

1. 系统运行函数:

void osal_run_system( void ){  uint8 idx = 0;  ....  do {    if (tasksEvents[idx])  // 检测触发事件    {      break;    }  } while (++idx < tasksCnt);           if (idx < tasksCnt)  {    uint16 events;    halIntState_t intState;    HAL_ENTER_CRITICAL_SECTION(intState);    //关闭中断    events = tasksEvents[idx];    tasksEvents[idx] = 0;  // Clear the Events for this task.    HAL_EXIT_CRITICAL_SECTION(intState);    activeTaskID = idx;    events = (tasksArr[idx])( idx, events );     // 执行用户应用, 用户的idx在taskArry[ ]对应的是XXXApp_Process_Event(idx,events)    activeTaskID = TASK_NO_TASK;    HAL_ENTER_CRITICAL_SECTION(intState);    tasksEvents[idx] |= events;  // Add back unprocessed events to the current task.    HAL_EXIT_CRITICAL_SECTION(intState);  }  //..........}


备注:
OSAL_XXXApp.c 中
将XXXApp_ProcessEvent 加入taskArry[ ]:

taskArr[idx] = XXXApp_Process_Event(idx, events): 

初始化 tasksArr [ ]: 

osalInitTasks():XXXApp_Init(idx)

2. 触发Process_Event(idx,events):

执行过程:
XXXApp_Process_Event(idx, events): 
if (events & SYS_EVENT_MSG)
MSGpkt = osal_msg_receive(idx);      消息列表里收消息
switch MSGpkt->hdr.event: 

消息是否为命令(Cluster)种类 (最常用的!)
case AF_INCOMING_MSG_CMD:
XXXApp_MessageMSGCB(MSGpkt);
MessageMSGCB里面格式:  [switch ( pkt->clusterId )  case GENERICAPP_CLUSTERID: 自定义XXX()]

消息是否为设备状态改变(终端加入网络时会用到!)

case ZDO_STATE_CHANGE: 
XXXApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
 if ( XXXApp_NwkState ==DEV_ZB_COORD/DEV_ROUTER/DEV_END_DEVICE )
              XXXApp_SendTheMessage();



还没研究清楚==:case ZDO_CB_MSG: XXXApp_ProcessZDOMsgs(MSGpkt);
消息是按键case KEY_CHANGE: XXXApp_HandleKeys( MSGpkt)->state, MSGpkt)->keys );


//自己定义MSG_EVT和函数:
if (events & XXXApp_SEND_MSG_EVT)XXXApp_SendTheMessage()
(什么时候会用到还没搞明白。。。待更新)


一些小细节:

1. Coordinator's short address is fixed to 0x0000
比如要发送给 coordinator:先设置my_DstAddr.addr.shortAddr = 0x0000, 然后AF_DataRequest(&my_DstAddr, ....)

2. 在 SimpleDescriptionFormat_t 中AppNumIn(Out)Clusters的含义

举例:(《Zigbee无线传感器网络设计与实现》pp43~57)


Coordinator:只接收一种命令,不发送命令时

const SimpleDescriptionFormat_t GenericApp_SimpleDesc ={  GENERICAPP_ENDPOINT,              //  int Endpoint;  GENERICAPP_PROFID,                //  uint16 AppProfId[2];  GENERICAPP_DEVICEID,              //  uint16 AppDeviceId[2];  GENERICAPP_DEVICE_VERSION,        //  int   AppDevVer:4;  GENERICAPP_FLAGS,                 //  int   AppFlags:4;  GENERICAPP_MAX_CLUSTERS,          //  byte  AppNumInClusters;  (cId_t *)GenericApp_ClusterList,  //  byte *pAppInClusterList;  0,                                //  byte  AppNumOutClusters;  (cId_t *)NULL                     //  byte *pAppOutClusterList;    };


Enddeivce:只发送一种命令,不接收命令时
const SimpleDescriptionFormat_t GenericApp_SimpleDesc ={  GENERICAPP_ENDPOINT,              //  int Endpoint;  GENERICAPP_PROFID,                //  uint16 AppProfId[2];  GENERICAPP_DEVICEID,              //  uint16 AppDeviceId[2];  GENERICAPP_DEVICE_VERSION,        //  int   AppDevVer:4;  GENERICAPP_FLAGS,                 //  int   AppFlags:4;  0,               //  byte  AppNumInClusters;  (cId_t *)NULL,     //  byte *pAppInClusterList;  GENERICAPP_MAX_CLUSTERS,           //  byte  AppNumOutClusters;  (cId_t *)GenericApp_ClusterList    //  byte *pAppOutClusterList;};


0 0
原创粉丝点击