📄 设备1beeapp.c
字号:
static void TxZigBeeThrottleTimerCallBack(tmrTimerID_t timerID);
static void querystart(void);
static void zbreset(void);
static void TxZigBeequeryTimerCallBack(tmrTimerID_t timerID);
static void wdgTimerCallBack(tmrTimerID_t timerID);
//static void rangeTimerCallBack(tmrTimerID_t timerID);
uint8_t convertnoopti(uint8_t lqivalue);
// TpmReadCNTRegister(newtimenoopti);
uint8_t convertopti(uint8_t lqivalue);
// TpmReadCNTRegister(newtimeopti);
uint16_t gettimenoopti(void);
uint16_t gettimeopti(void);
// extern void StopEndDevice( void );
/******************************************************************************
*******************************************************************************
* Public memory definitions
*******************************************************************************
******************************************************************************/
zbEndPoint_t appEndPoint;
/* This data set contains app layer variables to be preserved across resets */
NvDataItemDescription_t const gaNvAppDataSet[] = {
{&gBeeStackParameters, sizeof(beeStackParameters_t)}, /* BeeStackSpecific */
{&gZclCommonAttr, sizeof(zclCommonAttr_t)}, /* scenes, location, etc... */
{&gAslData, sizeof(ASL_Data_t)}, /* state of ASL */
/* insert any user data for NVM here.... */
{NULL, 0} /* Required end-of-table marker. */
};
/******************************************************************************
*******************************************************************************
* Public functions
*******************************************************************************
******************************************************************************/
/* Initialize the application. */
void BeeAppInit(void) {
index_t i;
/* Register the application endpoint(s), so we receive callbacks. */
for (i = 0; i < gNum_EndPoints_c; ++i) {
(void) AF_RegisterEndPoint(endPointList[i].pEndpointDesc);
}
/* Start with all LEDs off */
ASL_InitUserInterface("Wireless UART");
mTxZigBeeDataRetryTimerID = TMR_AllocateTimer();
mTxZigBeeThrottleTimerID = TMR_AllocateTimer();
mTxZigBeequeryTimerID = TMR_AllocateTimer();
wdgTimerID = TMR_AllocateTimer();
gSendingNwkData.gAddressMode = gZbAddrMode16Bit_c;
// gSendingNwkData.gAddressMode = gZbAddrModeIndirect_c;
/* Only one endpoint is needed for this application. */
appEndPoint = endPointList[0].pEndpointDesc->pSimpleDesc->endPoint;
UartX_SetRxCallBack(UartRxCallBack);
ASL_UpdateDevice(appEndPoint,gStartNetwork_c);
ZDO_Start(gStartWithOutNvm_c);
queryflag=1;
TMR_StartIntervalTimer(wdgTimerID,30,wdgTimerCallBack);
// TMR_StartIntervalTimer(wdgTimerID,1000,rangeTimerCallBack);
TMR_StartIntervalTimer(mTxZigBeequeryTimerID,1000,TxZigBeequeryTimerCallBack);
//for query the device id
Led1Flashing();
} /* BeeAppInit() */
/****************************************************************************/
/* Handles all key events for this device. The UI has two modes:
* config-mode, for setting up the network, joining, forming, etc., and
* run-mode, for controlling the application.
*/
void BeeAppHandleKeys(key_event_t events)
{
/* switch (events) */
} /* BeeAppHandleKeys() */
/****************************************************************************/
/* Application task. Responds to events for the application. */
void BeeAppTask(event_t events)
{
if (events & mAppRetryZigBeeAckTx_c) { TxZigBeeAck(); }
if (events & mAppRetryUartDataTx_c) { TxUartData(); }
if (events & mAppRetryZigBeeDataTx_c) { TxZigBeeData(); }
if (events & gAppEvtDataConfirm_c) { ProcessConfirmData(); }
if (events & gAppEvtDataIndication_c) { RxZigBeeData(); }
if (events & mAppRxFromUart_c) { RxUartData(); }
if (events & gAppEvtAddGroup_c) { ASL_ZclAddGroupHandler(); }
if (events & gAppEvtSyncReq_c) { ASL_Nlme_Sync_req(FALSE); }
} /* BeeAppTask() */
void BeeAppUpdateDevice(zbEndPoint_t ep, uint8_t event)
{
ASL_UpdateDevice(ep, event);
}
void querystart(void)
{
}
/////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////
void zbreset(void)
{
ASL_UpdateDevice(appEndPoint,gStartNetwork_c);
TS_SendEvent(gZdoStateMachineTaskID_c,gStartWithOutNvm_c);
}
/****************************************************************************/
/* The LEDs normally display status information, but sometimes the UI wants
* to display something in response to a keypress, like a baud rate change.
* This display takes precedence over the status indications for a short while.
*
* Note that calling this before the timer has expired from a previous call
* will harmlessly overwrite the previous display.
* The value is assumed to be 0..15. Displaying 0 (all lights off) may
* be confusing to the user. If the maximum value is < 15, it is better
* to pass in an integer in the range 1..15.
*/
static void DisplayLedInteger(index_t value) {
mIsIntegerDisplayedOnLEDs = TRUE;
SetAllLeds(value);
// TMR_StartSingleShotTimer(mBaudRateDisplayTimerID,
// mBaudRateDisplayDuration_c,
// RestoreLedShadowState);
} /* DisplayLedInteger() */
/****************************************************************************/
/* Transmit all buffers that are marked as in progress. */
static void FlushAllBuffers(void) {
if (uartTxDataBuffer.status == mBufStatusInProgress_c) {
uartTxDataBuffer.status = mBufStatusReadyToSend_c;
}
TxUartData();
if (zbTxAckBuffer.status == mBufStatusInProgress_c) {
zbTxAckBuffer.status = mBufStatusReadyToSend_c;
}
TxZigBeeAck();
if (zbTxDataBuffer.status == mBufStatusInProgress_c) {
zbTxDataBuffer.status = mBufStatusReadyToSend_c;
}
TxZigBeeData();
queryflag=1;
} /* FlushAllBuffers() */
/****************************************************************************/
/* Process incoming ZigBee over-the-air data confirms. */
/* The Wireless UART uses application-level ACKs and NAKs, not APS confirms. */
/* Any APS confirm that reaches this routine is not ours. */
static void ProcessConfirmData(void) {
apsdeToAfMessage_t *pMsg;
zbApsdeDataConfirm_t *pConfirm;
while (MSG_Pending(&gAppDataConfirmQueue)) {
pMsg = MSG_DeQueue(&gAppDataConfirmQueue);
pConfirm = &(pMsg->msgData.dataConfirm);
/* Action taken when confirmation is received. */
if (pConfirm->status == gSuccess_c) {
BeeAppUpdateDevice(appEndPoint, gToggleEvent_c);
}
/* Free memory allocated in Call Back function */
MSG_Free(pMsg);
}
} /* ProcessConfirmData() */
/****************************************************************************/
/* Revert the LEDs to displaying their normal (shadow) state. */
static void RestoreLedShadowState(tmrTimerID_t timerID) {
index_t i;
(void) timerID;
for (i = 0; i < NumberOfElements(maLedShadowStateTable); ++i) {
ASL_SetLed(maLedShadowStateTable[i].number, maLedShadowStateTable[i].state);
}
mIsIntegerDisplayedOnLEDs = FALSE;
} /* RestoreLedShadowState() */
/****************************************************************************/
/* Handle bytes arriving from the UART driver. */
static void RxUartData(void)
{
unsigned char byte;
}
/****************************************************************************/
/* Process incoming ZigBee over-the-air messages. */
/* Datagrams arrive here with cluster id == mDataClusterId_c. */
/* ACKs/NAKs from the remote node also arrive here, with cluster id == */
/* mAckClusterId_c. */
static void RxZigBeeData(void) {
ackDatagram_t *pAckDatagram;
datagram_t *pDatagram;
zbApsdeDataIndication_t *pIndication;
apsdeToAfMessage_t *pMsg;
bool_t messageAccepted;
sequenceNumber_t sequenceNumber;
uint8_t temp[8]={0,0,0,0,0,0,0,0} ;
// zbTxDataBuffer.len = 0;
while (MSG_Pending(&gAppDataIndicationQueue)) {
pMsg = MSG_DeQueue(&gAppDataIndicationQueue);
pIndication = &(pMsg->msgData.dataIndication);
if ( (pIndication->aClusterId[0] == (mDataClusterId_c & 0xFF))
&& (pIndication->aClusterId[1] == (mDataClusterId_c >> 8)))
{
FLib_MemCpy(temp,
pIndication->pAsdu + sizeof(sequenceNumber_t),
8);
if((temp[0]==0xaa)&&(temp[7]==0xff)&&(temp[1]==0xbd))
{
zbTxDataBuffer.status = mBufStatusInProgress_c;
nwkaddress[0]=temp[2];
nwkaddress[1]=temp[3];
Copy2Bytes(bindaddress, nwkaddress);
rxnwk=1;
zbTxDataBuffer.status = mBufStatusInProgress_c;
zbTxDataBuffer.data.structured.payload[0]=0xaa;
zbTxDataBuffer.data.structured.payload[1]=0xab;
zbTxDataBuffer.data.structured.payload[2]=0xff;
zbTxDataBuffer.data.structured.payload[3]=0xff;
zbTxDataBuffer.data.structured.payload[4]=0xff;
zbTxDataBuffer.data.structured.payload[5]=0xff;
zbTxDataBuffer.data.structured.payload[6]=0xff;
zbTxDataBuffer.data.structured.payload[7]=0xff;
zbTxDataBuffer.status = mBufStatusReadyToSend_c;
zbTxDataBuffer.data.structured.sequenceNumber = curZbTxSequenceNumber++;
zbTxDataBuffer.len=9;
TxZigBeeData();
LED4TOGGLE;
AF_FreeDataIndicationMsg(pMsg);
return;
}
if((temp[0]==0xaa)&&(temp[1]==0xba)&&(temp[7]==0xff) )
{
zbTxDataBuffer.status = mBufStatusInProgress_c;
lqi=(pIndication->linkQuality) ;
ed=GetEnergyLevel();
// mTmrRead16bitReg.byteAccess[ 0 ] = gTPMxCNTH_c;
// mTmrRead16bitReg.byteAccess[ 1 ] = gTPMxCNTL_c;
tmrReadCNTRegister(oldtimenoopti);
rangenoopti=convertnoopti(lqi);
tmrReadCNTRegister(newtimenoopti);
rangeopti=convertopti(lqi);
tmrReadCNTRegister(newtimeopti);
timenoopti=gettimenoopti();
timeopti=gettimeopti();
Copy2Bytes(time,timenoopti);
zbTxDataBuffer.data.structured.payload[0]=0xaa;
zbTxDataBuffer.data.structured.payload[1]=0xfb;
zbTxDataBuffer.data.structured.payload[2]=(pIndication->linkQuality) ;
zbTxDataBuffer.data.structured.payload[3]=lqi;
zbTxDataBuffer.data.structured.payload[4]=rangeopti;
zbTxDataBuffer.data.structured.payload[5]=time[0];
zbTxDataBuffer.data.structured.payload[6]=time[1];
zbTxDataBuffer.data.structured.payload[7]=0xff;
zbTxDataBuffer.status = mBufStatusReadyToSend_c;
zbTxDataBuffer.data.structured.sequenceNumber = curZbTxSequenceNumber++;
zbTxDataBuffer.len=9;
// Led3Toggle();
TxZigBeeData();
AF_FreeDataIndicationMsg(pMsg);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -