CC2530 Note 1:( ProcessEvent, MSGpkt, MessageMSGCB)
2014-07-22 15:32
766 查看
搞了半天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:只发送一种命令,不接收命令时
最概况的话是
事件(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; };
相关文章推荐
- Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server.
- note : windows message process
- 小e开发板WiFi微信登录后的回调函数et_message_process、et_event_process
- ProcessErrorMessage(char* ErrorText)
- LR:接口性能测试时提示:Code-29723 Error: Failed to deliver a p2p message from parent to child process, reason
- ProcessMessageFilter的使用
- Bugzilla Error message: couldn't create child process: 720003: index.cgi
- Master Note: Database System Monitor Process (SMON) (Doc ID 1495163.1)
- WAITEVENT: "cursor: pin S" Reference Note (文档 ID 1310764.1)
- TIJ Note - Object creation process
- DSS Source Code Analyse (05) - EventContext::ProcessEvent
- 怎么监视跟踪一个进程(Process)中的MS Unit Test DLL的详细性能(performance)【asp.net C#】
- LR Error: Failed to deliver a p2p message from son to parent process, reason - communication error.
- Application.ProcessMessage作用
- [jQuery Note]jQuery Event Handle-JavaScript Object fundamentals
- WAITEVENT: "log file sync" Reference Note (文档 ID 34592.1)
- ProcessMessageFilter()方法实现对话框的键盘响应
- ios5调试时的信息 “Discarding message for event 0 because of too many unprocessed messages”
- MS Bigdata HDInsight -Process, analyze, and gain new insights from big data using the power of Apache Hadoop
- WCF 4 Step By Step Chapter 4 Note (Transport and Message Security + Authentication in Organization)