/******************************************************** process request funtin of the CLUSDISC command *************************************************************/ void AT_AF_Cmd_HA_CIDDISC_req(afIncomingMSGPacket_t *pkt ){ AT_AF_hdr *req = (AT_AF_hdr *)pkt->cmd.Data; AT_AF_Cmd_HA_CIDDISC_rsp_t *rsp; uint8 status=0; uint16 rspLen=0; if(AT_is_CMD_EPs(req->ep)){ SimpleDescriptionFormat_t *pDesc; if(SUCCESS == (status=afFindSimpleDesc(&pDesc, req->ep))){ rspLen = (pDesc->AppNumInClusters+pDesc->AppNumInClusters)*2 +sizeof(AT_AF_Cmd_HA_CIDDISC_rsp_t); rsp = osal_mem_alloc(rspLen); if(rsp) { rsp->status = SUCCESS; rsp->serverNum = pDesc->AppNumInClusters; rsp->clientNum = pDesc->AppNumOutClusters; rsp->hdr.ep = req->ep; rsp->hdr.cmd = AT_AF_Cmd_rsp; osal_memcpy(rsp->list,pDesc->pAppInClusterList,rsp->serverNum*2); osal_memcpy(rsp->list+rsp->serverNum,pDesc->pAppOutClusterList,rsp->clientNum*2); //sent the found data AF_DataRequest( & (pkt->srcAddr), & AT_AF_epDesc, AT_AF_Cmd_HA_CIDDISC_CLUSTERID, rspLen, (uint8*)rsp, &AT_AF_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); osal_mem_free(rsp); return; //important }else{ status = AT_AF_MEM_ERROR; } }else { //status = status; //have been done } }else{ status = AT_AF_NOTFOUND_ERROR; } AT_AF_Cmd_HA_CIDDISC_rsp_t dftRsp; dftRsp.hdr.cmd = AT_AF_Cmd_rsp; dftRsp.hdr.ep = req->ep; dftRsp.status = status; rsp = &dftRsp; AF_DataRequest( & (pkt->srcAddr), & AT_AF_epDesc, AT_AF_Cmd_HA_CIDDISC_CLUSTERID, sizeof(AT_AF_Cmd_HA_CIDDISC_rsp_t), (uint8*)rsp, &AT_AF_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); }
/************************************************************************************************** * @fn MHMSDataReq * * @brief This function is called by MHMSAppEvt() to send a MHMS data report. When it is detected that * a pulse is found (QS flag is set) this function will start to transfer BPM, IBI, and raw Signal * data over the air to the coordinator at 20ms intervals. When there is no BPM detected * this function will stop sending information over the air to the coordinator. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ static void MHMSDataReq(void) { static bool MHMSDataReqFlag; MHMSDataReqFlag = FALSE; afAddrType_t addr; //AF address stucture defined for info on the destination Endpoint object that data will be sent to osal_stop_timerEx(MHMSTaskId, MHMS_EVT_CHECKIN); //Node is collecting data and sending it to coordinator so turn off check in event MHMSEvtCheckin_sync = FALSE; MHMSDat[MHMS_CHECK_IN] = CHECK_IN_INACTIVE; //Flag is off and will notify coordinator that node is not sending check in data addr.addr.shortAddr = MHMSAddr; //loading short address (16-bit) with pulse address addr.addrMode = afAddr16Bit; //Set to directly sent to a node addr.endPoint = MHMS_ENDPOINT; //Sets the endpoint of the final destination (coordinator?) if (afStatus_SUCCESS != AF_DataRequest(&addr, (endPointDesc_t *)&MHMS_epDesc, MHMS_CLUSTER_ID, MHMS_DAT_LEN, MHMSDat, &MHMSTSN, AF_DISCV_ROUTE,AF_DEFAULT_RADIUS)) { //if data transfer is unsuccessful place event immediately back into queue to attempt to send again osal_set_event(MHMSTaskId, MHMS_EVT_REQ); } if((QS == TRUE) && (MHMSDataReqFlag == FALSE)){ osal_start_timerEx(MHMSTaskId, MHMS_EVT_REQ, MHMS_DLY_DATAREQ); //send next Pulse data report in 500ms MHMSDataReqFlag = TRUE; //to prevent restarting of timer if existing already running } }
afStatus_t AF_DataRequestSrcRtg( afAddrType_t *dstAddr, endPointDesc_t *srcEP, uint16 cID, uint16 len, uint8 *buf, uint8 *transID, uint8 options, uint8 radius, uint8 relayCnt, uint16* pRelayList ) { uint8 status; /* Add the source route to the source routing table */ status = RTG_AddSrcRtgEntry_Guaranteed( dstAddr->addr.shortAddr, relayCnt, pRelayList ); if( status == RTG_SUCCESS) { /* Call AF_DataRequest to send the data */ status = AF_DataRequest( dstAddr, srcEP, cID, len, buf, transID, options, radius ); } else if( status == RTG_INVALID_PATH ) { /* The source route relay count is exceeding the network limit */ status = afStatus_INVALID_PARAMETER; } else { /* The guaranteed adding entry fails due to memory failure */ status = afStatus_MEM_FAIL; } return status; }
static void SerialApp_SendData( uint8 *buf, uint8 len ) { afStatus_t stat; // Pre-pend sequence number to the start of the Rx buffer. *buf = ++SerialApp_SeqTx; otaBuf = buf; otaLen = len+1; if (buf[1]==0xff) { reset(); } stat = AF_DataRequest( &SerialApp_DstAddr, (endPointDesc_t *)&SerialApp_epDesc, SERIALAPP_CLUSTERID_CMD, otaLen, otaBuf, &SerialApp_MsgID, 0, AF_DEFAULT_RADIUS ); HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF); FREE_OTABUF(); }
void AT_AF_Cmd_REPPRINT_req(afIncomingMSGPacket_t *pkt ){ const uint8 AT_CMD_EP_ARRAY[] = AT_CMD_EPs; uint8 epNum = afNumEndPoints()-1; byte* epBuf = (byte*) osal_mem_alloc(epNum); if(epBuf==NULL) return; afEndPoints( epBuf, true); AT_sort_arr(epBuf,epNum); //the epStatus store the search result uint8 pbuf_temp[sizeof(AT_CMD_EP_ARRAY)+sizeof(AT_AF_hdr)]; AT_AF_Cmd_REPPRINT_rsp_t* pbuf = (AT_AF_Cmd_REPPRINT_rsp_t*)pbuf_temp; pbuf->hdr.cmd=AT_AF_Cmd_rsp; pbuf->hdr.numItem=AT_CMD_EPs_Num; int i,j; for(i=0,j=0;j<AT_CMD_EPs_Num;j++){ if(epBuf[i]==AT_CMD_EP_ARRAY[j]){ pbuf->status[j] = AT_AF_enable; i++; } else pbuf->status[j] = AT_AF_disable; } osal_mem_free(epBuf); AF_DataRequest( & (pkt->srcAddr), & AT_AF_epDesc, AT_AF_Cmd_REPPRINT_CLUSTERID, sizeof(AT_CMD_EP_ARRAY)+sizeof(AT_AF_hdr), (uint8*)pbuf, &AT_AF_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); }
static void send_command_to_T1(uint8 length, uint8 * buffer) { afAddrType_t * desAddr = NULL; if (length != COMMAND_FULL_LENGTH) { return; } desAddr = findSrcAddr(buffer); if (desAddr == NULL) { return; } AF_DataRequest( desAddr, &SampleApp_HeartBeatEpDesc, SAMPLEAPP_PERIODIC_CLUSTERID, length - SN_LEN, buffer + SN_LEN, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS); return; }
/************************************************************************************************** * @fn MHMSAnnce * * @brief This function is called by MHMSAppEvt() to send an announce command to start or stop * the device that is acting as a health monitor from collecting sensor data. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ static void MHMSAnnce(void) { uint8 msg[3]; afAddrType_t addr; addr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL; addr.addrMode = afAddrBroadcast; addr.endPoint = MHMS_ENDPOINT; if (INVALID_NODE_ADDR != MHMSAddr) { msg[MHMS_CMD_IDX] = MHMS_CMD_BEG; if (ZSuccess != osal_start_timerEx(MHMSTaskId, MHMS_EVT_ANN, MHMS_DLY_ANN)) { (void)osal_set_event(MHMSTaskId, MHMS_EVT_ANN); } } else { msg[MHMS_CMD_IDX] = MHMS_CMD_END; } msg[MHMS_ADR_LSB] = LO_UINT16(MHMSAddr); msg[MHMS_ADR_MSB] = HI_UINT16(MHMSAddr); if (afStatus_SUCCESS != AF_DataRequest(&addr, (endPointDesc_t *)&MHMS_epDesc, MHMS_CLUSTER_ID, 3, msg, &MHMSTSN, AF_TX_OPTIONS_NONE, AF_DEFAULT_RADIUS)) { osal_set_event(MHMSTaskId, MHMS_EVT_ANN); } else { MHMSCnt++; } }
//This function send the status of own park to the coordinator static void ParkWay_SendTheMessage( void ) { uint8 pData[6]; pData[0] = 'E'; pData[1] = 'D'; pData[2] = DEVICE_PW_1; pData[3] = DEVICE_PW_2; pData[4] = '-'; pData[5] = vaga; //Send data to the coordinator ADDRESS(0000) if ( AF_DataRequest( &ParkWay_DstAddr, &ParkWay_epDesc, ParkWay_CLUSTERID, (byte)osal_strlen( pData ) + 1, (byte *)&pData, &ParkWay_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { // Successfully requested to be sent. } else { osal_stop_timerEx( ParkWay_TaskID, ParkWay_SEND_MSG_EVT); osal_start_timerEx( ParkWay_TaskID, POLLING_OF_DEV_EVT, 200); } }
/* @fn handleKeys * @brief Handles all key events for this device. * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * @return none*/ static void handleKeys( uint8 shift, uint8 keys ) { /* POWER_SAVING key press interrupt uses shift key to awaken from deep sleep, * so it is not available.*/ #if !defined( POWER_SAVING ) /* Give the LocationProfile access to 4 keys by sending any Shif-Key * sequence to the profile as a normal Key.*/ if ( shift ) LocationHandleKeys( keys ); else #endif { if(keys & HAL_KEY_SW_1) {} if(keys & HAL_KEY_SW_2) {} if(keys & HAL_KEY_SW_3) {} if(keys & HAL_KEY_SW_4) {} } #if defined ( LOCATION_BLINDNODE ) { static uint8 transId; uint8 actionId = LOCATION_APP_TOGGLE; afAddrType_t dstAddr; dstAddr.addrMode = afAddrBroadcast; dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL; dstAddr.endPoint = LOCATION_APP_ENDPOINT; // Control all lights within 1-hop radio range. AF_DataRequest( &dstAddr, (endPointDesc_t *)&LoacationApp_epDesc, LOCATION_APP_ON_OFF_ID, 1, &actionId, &transId, AF_SKIP_ROUTING, 1); } #endif }
/************************************************************************************************** * @fn TestPayloadTx * * @brief This function is called by the MHMSAppEvt() function. This function is used to test * network loading by sending test payloads that have a packet size and Tx frequency that * are user defined. This is operated on a timer and is initiated by SW1. * input parameters * * * output parameters * * None. * * @return None. ************************************************************************************************** */ static void TestPayloadTx(void){ static uint8 SeqNum = 0; //MHMS Note that there is actually a separate Seq number appended to the over the air msg by the ZNP (ex. msg.nwkSeqNum) static bool flag = FALSE; afAddrType_t addr; //AF address stucture defined for info on the destination Endpoint object that data will be sent to // Turn off collecting data and regular Pulse report generation for Payload testing osal_stop_timerEx(MHMSTaskId, MHMS_EVT_CHECKIN); osal_stop_timerEx(MHMSTaskId, MHMS_EVT_DAT); osal_stop_timerEx(MHMSTaskId, MHMS_EVT_REQ); TestDatTx[11] = SeqNum; TestDatTx[MHMS_CMD_IDX] = MHMS_CMD_DAT_TEST; if( flag == FALSE){ SeqNum++; } flag = FALSE; addr.addr.shortAddr = MHMSAddr; //loading short address (16-bit) with pulse address addr.addrMode = afAddr16Bit; //Set to directly sent to a node addr.endPoint = MHMS_ENDPOINT; //Sets the endpoint of the final destination (coordinator?) HalLcdWriteString("TestPayload TX",HAL_LCD_LINE_5); if (afStatus_SUCCESS != AF_DataRequest(&addr, (endPointDesc_t *)&MHMS_epDesc, MHMS_CLUSTER_ID, MHMS_TEST_PAYLOAD_LEN, TestDatTx, &MHMSTSN, AF_DISCV_ROUTE,AF_DEFAULT_RADIUS)) { //if data transfer is unsuccessful place event immediately back into queue to attempt to send again osal_set_event(MHMSTaskId, TEST_EVT_PAYLOAD_TX); flag = TRUE; } osal_start_timerEx(MHMSTaskId, TEST_EVT_PAYLOAD_TX, TEST_DLY_PAYLOAD_TX); //send check in dummy packet every 10 seconds }
/********************************************************************* * @fn GenericApp_SendTheMessage * * @brief Send "the" message. * * @param none * * @return none */ static void GenericApp_SendTheMessage( void ) { byte temp[4]; DHT11(); temp[0] = wendu_shi; temp[1] = wendu_ge; temp[2] = shidu_shi; temp[3] = shidu_ge; if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc, TEMP_HUMI_INFO_CLUSTERID, 4, temp, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { // Successfully requested to be sent. } else { // Error occurred in request to send. } }
/*************************************************************************** deal with the HA discover request *****************************************************************************/ void AT_AF_Cmd_HA_DISC_req(afIncomingMSGPacket_t *pkt ){ AT_AF_Cmd_HA_DISC_req_t *req = (AT_AF_Cmd_HA_DISC_req_t *)pkt->cmd.Data; AT_AF_Cmd_HA_DISC_rsp_t *rsp; uint8 zcl_epCount =0; uint8 AT_CMD_EP_ARRAY[]=AT_CMD_EPs; uint8 i; uint8 buf_temp[sizeof(AT_AF_Cmd_HA_DISC_rsp_t)+sizeof(AT_CMD_EP_ARRAY)*sizeof(AT_AF_Cmd_HA_DISC_item_t)]; rsp = (AT_AF_Cmd_HA_DISC_rsp_t *) buf_temp; for(i=0;i<sizeof(AT_CMD_EP_ARRAY);i++){ epList_t* epList = AT_af_get_ep(AT_CMD_EP_ARRAY[i]); SimpleDescriptionFormat_t* simDesc=epList->epDesc->simpleDesc; //find the CID bool found=false; uint8 j; for(j=0;j<simDesc->AppNumOutClusters;j++){ if(simDesc->pAppOutClusterList[j]==req->CID) { if(req->option==0){ if(afFindEndPointDesc(AT_CMD_EP_ARRAY[i])) found=true; }else{ found=true; } break; } } if(!found){ for(j=0;j<simDesc->AppNumInClusters;j++){ if(simDesc->pAppInClusterList[j]==req->CID) { if(req->option==0){ if(afFindEndPointDesc(AT_CMD_EP_ARRAY[i])) found=true; }else{ found=true; } break; } } } //if found the CID if(found){ rsp->item[zcl_epCount].ep = AT_CMD_EP_ARRAY[i]; rsp->item[zcl_epCount].status = afFindEndPointDesc(AT_CMD_EP_ARRAY[i]) ? AT_AF_enable : AT_AF_disable; zcl_epCount++; } } if(zcl_epCount!=0){ rsp->hdr.numItem=zcl_epCount; rsp->hdr.cmd=AT_AF_Cmd_rsp; AF_DataRequest( & (pkt->srcAddr), & AT_AF_epDesc, AT_AF_Cmd_HA_DISC_CLUSTERID, sizeof(AT_AF_Cmd_HA_DISC_rsp_t)+zcl_epCount*sizeof(AT_AF_Cmd_HA_DISC_item_t), (uint8*)rsp, &AT_AF_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } }
/************************************************************************************************** * @fn MT_AfDataStore * * @brief Process AF Data Store command to incrementally store the data buffer for very large * outgoing AF message. * * input parameters * * @param pBuf - pointer to the received buffer * * output parameters * * @param rtrn - AF-Status of the operation. * * @return None. ************************************************************************************************** */ void MT_AfDataStore(uint8 *pBuf) { uint16 idx; uint8 len, rtrn = afStatus_FAILED; pBuf += MT_RPC_FRAME_HDR_SZ; idx = BUILD_UINT16(pBuf[0], pBuf[1]); len = pBuf[2]; pBuf += 3; if (pMtAfDataReq == NULL) { rtrn = afStatus_MEM_FAIL; } else if (len == 0) // Indication to send the message. { rtrn = AF_DataRequest(&(pMtAfDataReq->dstAddr), pMtAfDataReq->epDesc, pMtAfDataReq->cId, pMtAfDataReq->dataLen, pMtAfDataReq->data, &(pMtAfDataReq->transId), pMtAfDataReq->txOpts, pMtAfDataReq->radius); (void)osal_mem_free(pMtAfDataReq); pMtAfDataReq = NULL; } else { (void)osal_memcpy(pMtAfDataReq->data+idx, pBuf, len); rtrn = afStatus_SUCCESS; } MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_AF), MT_AF_DATA_STORE, 1, &rtrn); }
bool CurrentDetectionT1_SendHeartBeatMessage(uint8* sendToG1Data) { SET_HEART_BIT_STATUS(sendToG1Data , HEART_BIT_STATUS_REALTIME_MASK, 1); if (nv_number() || nv_mem_number()) { SET_HEART_BIT_STATUS(sendToG1Data, HEART_BIT_STATUS_RECOVER_MASK, 1); } else { SET_HEART_BIT_STATUS(sendToG1Data , HEART_BIT_STATUS_RECOVER_MASK, 0); } ShowHeartBeatInfo(sendToG1Data); ShowRssiInfo(); if (AF_DataRequest( &CurrentDetectionT1_Periodic_DstAddr, &CurrentDetectionT1_epDesc, DTCT_PERIODIC_CLUSTERID, HEART_BIT_MSG_LEN, sendToG1Data, &CurrentDetectionT1_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS) == afStatus_SUCCESS) { HalLedBlink(HAL_LED_2, 2, 20, 50); return true; } return false; }
/*********************************************************** LCD send retry ***********************************************************/ static void LCD_SendRetry(){ // first get the short address uint16 srcAddr = NLME_GetShortAddr(); // new the frame byte frame[7] = {0}; // fill the header frame[0] = 0xFE; // fill the length frame[1] = 0; // fill the command frame[2] = LO_UINT16(LCD_RETRY_CMD); frame[3] = HI_UINT16(LCD_RETRY_CMD); // fill Addr frame[4] = LO_UINT16(srcAddr); frame[5] = HI_UINT16(srcAddr); // fill the fcs frame[6] = LCD_CalcFCS((byte*)&frame[1], 5); // Send the data to Coordinator AF_DataRequest( &LCD_DstAddr, &LCD_epDesc, ZIGBEE_COMMON_CLUSTER, 7, (byte *)frame, &LCD_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); }
/************************************************************** send the ack command to the monitor **************************************************************/ static void LCD_SendACK(byte flag){ // new the frame byte frame[8] = {0}; // fill the header frame[0] = 0xFE; // fill the length frame[1] = 1; // fill the command frame[2] = LO_UINT16(LCD_ACK_CMD); frame[3] = HI_UINT16(LCD_ACK_CMD); // fill Addr frame[4] = LO_UINT16(0); frame[5] = HI_UINT16(0); // fill the flag frame[6] = flag; // fill the fcs frame[7] = LCD_CalcFCS((byte*)&frame[1], 6); // Send the data to Coordinator AF_DataRequest( &LCD_DstAddr, &LCD_epDesc, ZIGBEE_COMMON_CLUSTER, 8, (byte *)frame, &LCD_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); }
void SampleApp_SendPointMessage(void) { HalUARTWrite(0, "PointMsg\n", sizeof("PointMsg\n")-1); uint8 T[5]; Temp_test(); if (temp > 27) LED1 = !LED1; T[0] = temp / 10 + 48; T[1] = temp % 10 + 48; T[2] = ' '; T[3] = 'C'; T[4] = '\0'; HalUARTWrite(0, "temp=", 5); HalUARTWrite(0, T, 2); HalUARTWrite(0, "\n", 1); if ( AF_DataRequest( &SampleApp_Point_DstAddr, &SampleApp_epDesc, SAMPLEAPP_POINT_CLUSTERID, 5, T, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { HalUARTWrite(0, "PointMsg Success\n", sizeof("PointMsg Success\n")-1); } else { // Error occurred in request to send. HalUARTWrite(0, "PointMsg Failed\n", sizeof("PointMsg Failed\n")-1); } }
static void SerialApp_SendData( uint8 *buf, uint8 len ) { afStatus_t stat; // Pre-pend sequence number to the start of the Rx buffer. *buf = ++SerialApp_SeqTx; otaBuf = buf; otaLen = len+1; stat = AF_DataRequest( &SerialApp_DstAddr, (endPointDesc_t *)&SerialApp_epDesc, SERIALAPP_CLUSTERID1, otaLen, otaBuf, &SerialApp_MsgID, 0, AF_DEFAULT_RADIUS ); if ( (stat == afStatus_SUCCESS) || (stat == afStatus_MEM_FAIL) ) { osal_start_timerEx( SerialApp_TaskID, SERIALAPP_MSG_RTRY_EVT, SERIALAPP_MSG_RTRY_TIMEOUT ); rtryCnt = SERIALAPP_MAX_RETRIES; HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF); } else { FREE_OTABUF(); } }
static void MHMSNodeCheckIn(void) { static bool Flag; afAddrType_t addr; //AF address stucture defined for info on the destination Endpoint object that data will be sent to osal_stop_timerEx(MHMSTaskId, MHMS_EVT_REQ); //Stop MHMSDataReq() task since no pulse data is being measured MHMSEvtReq_sync = FALSE; Flag = FALSE; addr.addr.shortAddr = MHMSAddr; //loading short address (16-bit) with pulse address addr.addrMode = afAddr16Bit; //Set to directly sent to a node addr.endPoint = MHMS_ENDPOINT; //Sets the endpoint of the final destination (coordinator?) MHMSDat[MHMS_CHECK_IN] = CHECK_IN_ACTIVE; //Flag is set and will notify coordinator that node is currently sending check in data HalLcdWriteString("BPMsensor Inacti",HAL_LCD_LINE_5); if (afStatus_SUCCESS != AF_DataRequest(&addr, (endPointDesc_t *)&MHMS_epDesc, MHMS_CLUSTER_ID, MHMS_DAT_LEN, MHMSDat, &MHMSTSN, AF_DISCV_ROUTE,AF_DEFAULT_RADIUS)) { //if data transfer is unsuccessful place event immediately back into queue to attempt to send again osal_set_event(MHMSTaskId, MHMS_EVT_CHECKIN); } else { MHMSCnt++; } if((QS == FALSE) && (Flag == FALSE)){ osal_start_timerEx(MHMSTaskId, MHMS_EVT_CHECKIN, MHMS_DLY_CHECKIN); //send check in dummy packet every 10 seconds Flag = TRUE; //to prevent restarting of timer if existing already running } }
/********************************************************************* * @fn SampleApp_SendPeriodicMessage * @brief Send the periodic message. * @param none * @return none */ void SampleApp_SendPeriodicMessage( void ) { uint8 data[10]={178,201,45,56,46,58,77,32,88,19}; if ( AF_DataRequest( &Point_To_Point_DstAddr, &SampleApp_epDesc, SAMPLEAPP_POINT_TO_POINT_CLUSTERID, 10, //一共10个数据 data, //装载要发送的数据 &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) {} }
/********************************************************************* * @fn SampleApp_SendPeriodicMessage * * @brief Send the periodic message. * * @param none * * @return none */ void SampleApp_SendPeriodicMessage( void ) { if ( AF_DataRequest ( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc, SAMPLEAPP_PERIODIC_CLUSTERID, 1, (uint8*)&SampleAppPeriodicCounter, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { /* Success occurred in request to send*/ } else { /* Error occurred in request to send. */ } }
static void AT_AF_Cmd_RSSI_req(afIncomingMSGPacket_t *pkt ){ AT_AF_Cmd_POWER_SAVING_rssi_t buf; buf.hdr.cmd =AT_AT_PSE_RSSI_rsp; buf.rssi = pkt->rssi; buf.lqi = pkt->LinkQuality; buf.correlation =pkt->correlation; AF_DataRequest( & (pkt->srcAddr), & AT_AF_epDesc, AT_AF_POWER_SVING_EXP_CLUSTERID, sizeof(buf), (uint8*)&buf, &AT_AF_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); }
afStatus_t AT_AF_Cmd_send_simple_(uint16 nwkAddr,uint16 CID,uint8 len, uint8 *buff){ afAddrType_t dstAddr; dstAddr.endPoint = AT_AF_ENDPOINT; dstAddr.addr.shortAddr =nwkAddr; dstAddr.addrMode = (afAddrMode_t) Addr16Bit; return AF_DataRequest( &dstAddr, & AT_AF_epDesc, CID, len, buff, &AT_AF_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); }
/***************************************** 广播,由协调器通过按键或启动时, 向全部终端节点发起测试请求 ******************************************/ void SampleApp_SendBroadcastMessage( void ) { uint8 data[]="+REBOT#"; if(AF_DataRequest(&SampleApp_Periodic_DstAddr, &SampleApp_epDesc, SAMPLEAPP_PERIODIC_CLUSTERID, 7, data, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { //SUCCESS! HalLedBlink( HAL_LED_2, 2,50, 500 ); } }
static void My_SendTheShortAddr( void ) { if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc, SHORT_ADDR_INFO_CLUSTERID, 0, NULL, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { // Successfully requested to be sent. } else { // Error occurred in request to send. } }
//void SampleApp_SendPeriodicMessage( void ) //{ // if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc, // SAMPLEAPP_PERIODIC_CLUSTERID, // 1, // (uint8*)&SampleAppPeriodicCounter, // &SampleApp_TransID, // AF_DISCV_ROUTE, // AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) // { // } // else // { // // Error occurred in request to send. // } //} void SampleApp_SendPeriodicMessage( void ) { uint8 data[1]={2};//,'3','4','5','6','7','8','9'}; if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc, SAMPLEAPP_PERIODIC_CLUSTERID, 1, &data[0],//(uint8*)&SampleAppPeriodicCounter, &SampleApp_TransID, AF_DISCV_ROUTE,//设置路由发现 AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { } else { // Error occurred in request to send. } }
/********************************************************************* * @fn App_SendSample * * @brief * * @param buf - pointer for the field * len - length of the field * * @return none */ void App_SendSample(unsigned char *buf, unsigned char len, uint16 option) { uint8 packetLen=0; app_msg_t packet; packet.head = 0xFE; // packet.nodeid = theNodeID; SendSeqno++; if(SendSeqno == 0xFE) { SendSeqno = 1; } packet.seqno = SendSeqno; memcpy(packet.IEEEAddr, NLME_GetExtAddr(), 8);//IEEE address 64 bit myAddr = NLME_GetShortAddr(); packet.myAddr = myAddr; packet.rssi = 0x00; packet.cmd = option; packet.len = len; memcpy(packet.data, buf, len); packetLen = sizeof(app_msg_t)-60 + len; // packet.end = 0xAA; // AF_SKIP_ROUTING - will cause the device to skip // routing and try to send the message directly if ( AF_DataRequest( &ParkingApp_Periodic_DstAddr, &ParkingApp_epDesc, PARKINGAPP_PERIODIC_CLUSTERID, packetLen,//sizeof(app_msg_t),//22, (byte*) &packet,//(byte *)tempbuf, &ParkingApp_TransID, #if (defined DATABROADCAST && DATABROADCAST == TRUE) AF_SKIP_ROUTING, // AF_DISCV_ROUTE ENDDEVICE_BCAST_RADIUS ) == afStatus_SUCCESS ) //AF_DEFAULT_RADIUS #else AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) #endif { // P0_0 = 0; } else { // Error occurred in request to send. } }
/************************************************************* deal with the requst from other devices for REPENABLE, and send a response *************************************************************/ void AT_AF_Cmd_REPENABLE_req(afIncomingMSGPacket_t *pkt ){ AT_AF_Cmd_REPENABLE_rsp_t rsp; AT_AF_Cmd_REPENABLE_req_t *req = (AT_AF_Cmd_REPENABLE_req_t*)pkt->cmd.Data; uint8 enable =req->enable; uint8 ep =req->ep; rsp.hdr.cmd=AT_AF_Cmd_rsp; rsp.item.ep=req->ep; if(enable){ if( AT_af_get_ep(ep)){ if(AT_af_register_ep(ep)==afStatus_SUCCESS){ //enable the end point in ZCL layer AT_ZCL_EP_ENABLE( enable,ep); AT_NV_ZCL_saveEPStatus(AT_NV_ZCL_get_index_(ep),&enable); } rsp.item.status=AT_AF_enable; }else { rsp.item.status = AT_AF_UNKNOWNEP; } } else{ if(AT_af_get_ep(ep)){ if(AT_af_remove_ep(ep)==afStatus_SUCCESS){ //disable the end point in ZCL layer AT_ZCL_EP_ENABLE( enable,ep); //save to NV AT_NV_ZCL_saveEPStatus(AT_NV_ZCL_get_index_(ep),&enable); } rsp.item.status = AT_AF_disable; }else { rsp.item.status = AT_AF_UNKNOWNEP; } } AF_DataRequest( & (pkt->srcAddr), & AT_AF_epDesc, AT_AF_Cmd_REPENABLE_CLUSTERID, sizeof(AT_AF_Cmd_REPENABLE_rsp_t), (uint8*)&rsp, &AT_AF_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); }
/********************************************************************* * @fn TransmitApp_SendTheMessage * * @brief Send "the" message. * * @param none * * @return none */ void TransmitApp_SendTheMessage( void ) { uint16 len; uint8 tmp; // put the sequence number in the message tmp = HI_UINT8( TransmitApp_TransID ); tmp += (tmp <= 9) ? ('0') : ('A' - 0x0A); TransmitApp_Msg[2] = tmp; tmp = LO_UINT8( TransmitApp_TransID ); tmp += (tmp <= 9) ? ('0') : ('A' - 0x0A); TransmitApp_Msg[3] = tmp; len = TransmitApp_MaxDataLength; #if defined ( TRANSMITAPP_RANDOM_LEN ) len = (uint8)(osal_rand() & 0x7F); if( len > TransmitApp_MaxDataLength || len == 0 ) len = TransmitApp_MaxDataLength; #endif do { tmp = AF_DataRequest( &TransmitApp_DstAddr, &TransmitApp_epDesc, TRANSMITAPP_CLUSTERID_TESTMSG, len, TransmitApp_Msg, &TransmitApp_TransID, TRANSMITAPP_TX_OPTIONS, AF_DEFAULT_RADIUS ); if ( timesToSend ) { timesToSend--; } } while ( (timesToSend != 0) && (afStatus_SUCCESS == tmp) ); if ( afStatus_SUCCESS == tmp ) { pktCounter++; } else { // Error, so wait (10 mSec) and try again. osal_start_timerEx( TransmitApp_TaskID, TRANSMITAPP_SEND_ERR_EVT, 10 ); } }
/********************************************************************* * @fn SampleApp_SendPeriodicMessage * * @brief Send the periodic message. * * @param none * * @return none */ void SampleApp_SendPeriodicMessage( void ) { LedState = LedState+1 ; //unsigned char data[15]= "F3332221114444"; SEND_DATA[0] = 0x31; // ROOM1 SESOR KEY CNT[2]=CNT[2]+1; if( CNT[2] == 0x3A) { CNT[2] = 0x30; CNT[1] = CNT[1] + 1 ; } if( CNT[1] == 0x3A) { CNT[1] = 0x30; CNT[0] = CNT[0] + 1 ; } if( CNT[0] == 0x3A) { CNT[0] = 0x30; } SEND_DATA[14]=0x41; SEND_DATA[15]=CNT[0]; SEND_DATA[16]=CNT[1]; SEND_DATA[17]=CNT[2]; if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc, SAMPLEAPP_PERIODIC_CLUSTERID, 27, SEND_DATA, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { if(LedState == 1) HalLedSet(HAL_LED_3, HAL_LED_MODE_ON); else if(LedState == 2) {HalLedSet(HAL_LED_3, HAL_LED_MODE_OFF); LedState=0;} } else { // Error occurred in request to send. } }