This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
我在Sample那个Progects中,终端程序中加入编译选项POWER_SAVING, 接收器设置FALSE,POLL_RATE设置成0,去掉按键注册以及其他,修改成只有给协调器定时发送数据(单播),用的是事件定时函数 osal_start_timerEx,当定时10s、20s时,终端会定时睡眠唤醒给协调器发送数据,但是,当定时30s(30000)时,终端会在1分钟多才会给协调器发数据,而且1分钟多这个时间不是固定数值,定时1分钟时,2分钟或3分钟多才会发数据,我只做了这4个时间的实验,请问可能是什么原因导致的?是不是我休眠方式设置的不对,?
我用不休眠的终端定时发,定时的30s挺准确的,为什么休眠就不行呢???
Thanks in advance!
jiao
你好,我上传附件了,是终端SampleApp.c,我修改过的,我直接复制到这上面的话,格式就变了,不条理,不好看
里面就是关闭LED,然后设置单播,定时事件发送数据等
我觉得问题可能在void halSleep( uint16 osal_timeout )这个函数中,osal_start_timerEx最终不就是调用这个函数么
这个函数中有一句timeout = HAL_SLEEP_MS_TO_320US(osal_timeout);,这句是HAL_SLEEP_MS_TO_320US(ms)---(((((uint32) (ms)) * 100) + 31) / 32)
假如20s,数值就是20000ms, (20000*100+31)/32 = 62500 ,这个值接近65535 ,也就是说只要换算过来小于这个值就准确,大于就不准确
但不设置低功耗的话,都是准确的,
这个函数后面看了,有部分也看不懂,也不知道错误在哪,不知道时间链表中的时间数据是怎么减的,没有找到这一部分
谢谢
/********************************************************************* * INCLUDES */ #include "OSAL.h" #include "ZGlobals.h" #include "AF.h" #include "aps_groups.h" #include "ZDApp.h" #include "SampleApp.h" #include "SampleAppHw.h" #include "OnBoard.h" /* HAL */ #include "hal_lcd.h" #include "hal_led.h" #include "hal_key.h" #include "MT_UART.h" #include "MT.h" #include "sapi.h" #include <string.h> /*#include "ZComDef.h" #include "MT.h" #include "MT_NWK.h" #include "NLMEDE.h" #include "nwk.h" #include "nwk_globals.h" #include "nwk_util.h" #include "OSAL.h" #include "ZDApp.h"*/ /********************************************************************* * MACROS */ /********************************************************************* * CONSTANTS */ /********************************************************************* * TYPEDEFS */ /********************************************************************* * GLOBAL VARIABLES */ // This list should be filled with Application specific Cluster IDs. const cId_t SampleApp_ClusterList[SAMPLEAPP_MAX_CLUSTERS] = { SAMPLEAPP_PERIODIC_CLUSTERID, //SAMPLEAPP_PERIODIC_CLUSTERID 1 SAMPLEAPP_FLASH_CLUSTERID //SAMPLEAPP_FLASH_CLUSTERID 2 }; const SimpleDescriptionFormat_t SampleApp_SimpleDesc = { SAMPLEAPP_ENDPOINT, // int Endpoint; //SAMPLEAPP_ENDPOINT---20 SAMPLEAPP_PROFID, // uint16 AppProfId[2]; //SAMPLEAPP_PROFID---0x0F08 SAMPLEAPP_DEVICEID, // uint16 AppDeviceId[2]; //SAMPLEAPP_DEVICEID---0x0001 SAMPLEAPP_DEVICE_VERSION, // int AppDevVer:4; //SAMPLEAPP_DEVICE_VERSION---0 SAMPLEAPP_FLAGS, // int AppFlags:4; //SAMPLEAPP_FLAGS---0 SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters; //SAMPLEAPP_MAX_CLUSTERS---2 (cId_t *)SampleApp_ClusterList, // uint8 *pAppInClusterList; SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters; //SAMPLEAPP_MAX_CLUSTERS---2 (cId_t *)SampleApp_ClusterList // uint8 *pAppInClusterList; }; // This is the Endpoint/Interface description. It is defined here, but // filled-in in SampleApp_Init(). Another way to go would be to fill // in the structure here and make it a "const" (in code space). The // way it's defined in this sample app it is define in RAM. endPointDesc_t SampleApp_epDesc; /********************************************************************* * EXTERNAL VARIABLES */ /********************************************************************* * EXTERNAL FUNCTIONS */ /********************************************************************* * LOCAL VARIABLES */ uint8 SampleApp_TaskID; // Task ID for internal task/event processing // This variable will be received when // SampleApp_Init() is called. devStates_t SampleApp_NwkState; uint8 SampleApp_TransID; // This is the unique message ID (counter) afAddrType_t Point_To_Point_DstAddr; //�㲥 uint8 SampleAppPeriodicCounter = 0; uint8 SampleAppFlashCounter = 0; uint16 k; /********************************************************************* * LOCAL FUNCTIONS */ void SampleApp_HandleKeys( uint8 shift, uint8 keys ); void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pckt ); void SampleApp_SendPeriodicMessage( void ); void SampleApp_SendFlashMessage( uint16 flashTime ); void SampleApp_SerialCMD(mtOSALSerialData_t *cmdMsg); void display_hex_com(uint8 nameid); void SampleApp_SendPointToPointMessage( void ); void SampleApp_Key_Message( void ); /********************************************************************* * NETWORK LAYER CALLBACKS */ /********************************************************************* * PUBLIC FUNCTIONS */ /********************************************************************* * @fn SampleApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; HalLedSet(HAL_LED_1,1); //�������ǹر�LED�ģ���������ij�����ˣ�û������ HalLedSet(HAL_LED_2,0); #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; Point_To_Point_DstAddr.addr.shortAddr = 0x0000; // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); } /********************************************************************* * @fn SampleApp_ProcessEvent * * @brief Generic Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return none */ uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; (void)task_id; // Intentionally unreferenced parameter if ( events & SYS_EVENT_MSG ) //SYS_EVENT_MSG---0x8000 // A message is waiting event { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // case AF_INCOMING_MSG_CMD: // SampleApp_MessageMSGCB( MSGpkt ); // break; // Received whenever the device changes state in the network case ZDO_STATE_CHANGE: //ZDO_STATE_CHANGE---0xD1 // ZDO has changed the device's network state SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if ( (SampleApp_NwkState == DEV_ZB_COORD) //Э���� || (SampleApp_NwkState == DEV_ROUTER) //·���� || (SampleApp_NwkState == DEV_END_DEVICE) ) //�ն� { // Start sending the periodic message in a regular interval. osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, //SAMPLEAPP_SEND_PERIODIC_MSG_EVT---0x0001 ,ͬһ�������ж���¼��������¼��ĺ��룬�����ظ� 30000 ); //SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT---5000 // Every 5 seconds } else { // Device is no longer in the network } break; default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); // Next - if one is available MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } // Send a message out - This event is generated by a timer // (setup in SampleApp_Init()). if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT ) { // Send the periodic message HalLedBlink( HAL_LED_1, 4,200, 500 ); SampleApp_SendPointToPointMessage(); // Setup to send message again in normal period (+ a little jitter) osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, (30000 ) ); //+ (osal_rand() & 0x00FF) // return unprocessed events return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT); } // Discard unknown events return 0; } void display_hex_com(uint8 nameid) //display ieee.shortadress.panid.channel { uint8 channel,i,*extaddr,hex_value[19],asc16[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; uint16 panId,shortaddr; hex_value[0]='0'; hex_value[1]='x'; switch(nameid) { case 0: //IEEE HalUARTWrite(0,"My IEEE address is:",19); extaddr = NLME_GetExtAddr(); for(i=2;i<18;i++,i++) { hex_value[i] = asc16[extaddr[(16-i)/2]/16]; hex_value[i+1] = asc16[extaddr[(16-i)/2]%16]; } hex_value[18] = '\n'; HalUARTWrite(0,hex_value,19); break; case 1: //panid HalUARTWrite(0,"My network ID is:",17); panId=_NIB.nwkPanId; //osal_memcpy(&panId, &_NIB.nwkPanId, sizeof(uint16)); hex_value[2] = asc16[(panId/16/16/16)%16]; hex_value[3] = asc16[(panId/16/16)%16]; hex_value[4] = asc16[(panId/16)%16]; hex_value[5] = asc16[panId%16]; hex_value[6] = '\n'; HalUARTWrite(0,hex_value,7); break; case 2: //shortaddress shortaddr = NLME_GetShortAddr(); HalUARTWrite(0,"My shortaddr is:",16); hex_value[2] = asc16[(shortaddr/16/16/16)%16]; hex_value[3] = asc16[(shortaddr/16/16)%16]; hex_value[4] = asc16[(shortaddr/16)%16]; hex_value[5] = asc16[shortaddr%16]; hex_value[6] = '\n'; HalUARTWrite(0,hex_value,7); break; case 3: //information channel //osal_memcpy(&channel, &_NIB.nwkLogicalChannel, sizeof(uint8)); channel = _NIB.nwkLogicalChannel; HalUARTWrite(0,"My info channel is:",19); hex_value[2] = asc16[channel/16]; hex_value[3] = asc16[channel%16]; hex_value[4] = '\n'; HalUARTWrite(0,hex_value,5); break; default : HalUARTWrite(0,"Input error",5); } } void SampleApp_SendPointToPointMessage( void ) { uint8 asc16[10]={'0','1','2','3','4','5','6','7','8','9'}; //�豸���ͱ��� uint8 device[13]="ED_N:01_D:000"; k++;if(1000==k)k=0; device[12]=asc16[k%10]; device[11]=asc16[k/10%10]; device[10]=asc16[k/100%10]; if ( AF_DataRequest( &Point_To_Point_DstAddr, //afAddrType_t *dstAddr, Ŀ�ĵ�ַ�����е�ַģʽ�����ǣ� afAddrNotPresent ��ģʽ��ַ�� afAddrGroup�鲥��ַ�� //afAddrBroadcast�㲥��ַ��afAddr16Bitֱ�Ӵ��䣨��������ַ�� &SampleApp_epDesc, // endPointDesc_t *srcEP, Դ�˵� SAMPLEAPP_POINT_TO_POINT_CLUSTERID, //�Լ������ ��ID��(Cluster ID) 13, //uint16 len, buf��ij��ȣ��������ݵ��ֽ����� device, //uint8 *buf, �����͵����� &SampleApp_TransID, //uint8 *transID, �������к� AF_DISCV_ROUTE, //uint8 options, 0x10:AF_ACK_REQUEST �� 0x20:AF_DISCV_ROUTE �� 0x40:AF_EN_SECURITY ��0x80:AF_SKIP_ROUTING AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) //afStatus_SUCCESS---ZSuccess---SUCCESS---0x00 //uint8 radius )��������30 { } else { // Error occurred in request to send. } } /********************************************************************* *********************************************************************/