📄 设备1beeapp.c
字号:
}
else
{ /* if (IsEqual2BytesInt( ... */
/* Free the indication message. */
AF_FreeDataIndicationMsg(pMsg);
}
} /* while (MSG_Pending( ... */
} /* RxZigBeeData() */
/****************************************************************************/
/* Send data received from the UART back out via the UART (loop back). */
/* Note that UART buffers don't need or want sequence numbers. */
/* Return TRUE if successful. */
static bool_t SendUartDataToUart(unsigned char byte)
{
return TRUE;
} /* SendUartDataToUart() */
/****************************************************************************/
/* Send data received from the UART out OTA. */
/* Return TRUE if successful. */
static bool_t SendUartDataToZigBee(unsigned char byte)
{
} /* SendUartDataToZigBee() */
/****************************************************************************/
/* Send data received OTA out through the UART. */
/* Note that the entire buffer received OTA is sent to the UART, all at */
/* once, with no blocking or deblocking. This is simpler: one ZigBee */
/* buffer == one UART buffer. */
/* Return TRUE if successful. */
static bool_t SendZigBeeDataToUart(apsdeToAfMessage_t *pMsg) {
}
/****************************************************************************/
/* Given a binary integer, set all of the LEDs to on or off accordingly. */
/* Does not handle toggling or flashing. Sets the actual LED state, not the */
/* shadow copy. */
static void SetAllLeds(index_t value) {
ASL_SetLed(LED1, ((value & 0x01) ? gLedOn_c : gLedOff_c));
ASL_SetLed(LED2, ((value & 0x02) ? gLedOn_c : gLedOff_c));
ASL_SetLed(LED3, ((value & 0x04) ? gLedOn_c : gLedOff_c));
ASL_SetLed(LED4, ((value & 0x08) ? gLedOn_c : gLedOff_c));
} /* SetAllLeds() */
/****************************************************************************/
/* Change the shadow copy of the LED state. If an integer is being */
/* displayed, it takes priority, so this change will not be written to the */
/* LEDs yet. */
/* Otherwise, display the change on the LED. */
static void SetOneLed(LED_t ledNumber, LedState_t state) {
index_t i;
for (i = 0; i < NumberOfElements(maLedShadowStateTable); ++i) {
if (maLedShadowStateTable[i].number == ledNumber) {
maLedShadowStateTable[i].state = state;
if (!mIsIntegerDisplayedOnLEDs) {
ASL_SetLed(ledNumber, state);
}
}
}
} /* SetOneLed() */
/****************************************************************************/
/* Send the contents of the UART transmit buffer out via the UART. */
static void TxUartData(void)
{
Copy2Bytes(nwkaddress, NlmeGetRequest(gNwkShortAddress_c));
// test1=nwkaddress[0];
// test2=nwkaddress[1];
zbTxDataBuffer.status = mBufStatusInProgress_c;
zbTxDataBuffer.data.structured.payload[0]=0xaa;
zbTxDataBuffer.data.structured.payload[1]=0xac;
zbTxDataBuffer.data.structured.payload[2]=nwkaddress[0];
zbTxDataBuffer.data.structured.payload[3]=nwkaddress[1];
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;
LED3TOGGLE;
TxZigBeeData();
return;
} /* TxUartData() */
/****************************************************************************/
/* Let the other side know that a datagram has been received. */
static void TxZigBeeAck(void)
{
} /* TxZigBeeAck() */
/****************************************************************************/
/* Send the contents of the ZigBee transmit buffer OTA to the remote node. */
void TxZigBeeData(void) {
afAddrInfo_t afAddrInfo;
if (!mTxZigBeeThrottleFlag) {
TS_SendEvent(gAppTaskID, mAppRetryZigBeeDataTx_c);
return;
}
/* Don't need to be interrupted just to come back here again. */
TMR_StopTimer(mTxZigBeeDataRetryTimerID);
if (zbTxDataBuffer.status != mBufStatusReadyToSend_c) {
return;
}
FLib_MemSet(&afAddrInfo, 0, sizeof(afAddrInfo));
afAddrInfo.aClusterId[0] = (mDataClusterId_c & 0xFF);
afAddrInfo.aClusterId[1] = (mDataClusterId_c >> 8);
afAddrInfo.srcEndPoint = appEndPoint;
afAddrInfo.dstAddrMode = gZbAddrMode16Bit_c;
if((zbTxDataBuffer.data.structured.payload[1]==0xfb)||(zbTxDataBuffer.data.structured.payload[1]==0xac))
Copy2Bytes(afAddrInfo.dstAddr.aNwkAddr, aDestAddress);
if(zbTxDataBuffer.data.structured.payload[1]==0xab) {
if(rxnwk==1)
Copy2Bytes(afAddrInfo.dstAddr.aNwkAddr, bindaddress);
else
{
zbTxDataBuffer.status = mBufStatusFree_c;
//Led2Toggle();
//Led4Toggle();
zbTxDataBuffer.len = 0;
return;
}
}
afAddrInfo.dstEndPoint = gZbBroadcastEndPoint_c;
/* Turn on security and leave it on. Harmless In a non-secure network. */
afAddrInfo.txOptions = 0;
afAddrInfo.radiusCounter = afDefaultRadius_c;
/* The Wireless UART application on the remote node will ack or nak this */
/* datagram (regardless of the reliability mode setting), so a confirm id */
/* is not needed here. */
AF_DataRequest(&afAddrInfo,
zbTxDataBuffer.len,
zbTxDataBuffer.data.raw,
NULL) ;
zbTxDataBuffer.status = mBufStatusFree_c;
Led2Toggle();
//Led4Toggle();
zbTxDataBuffer.len = 0;
mTxZigBeeThrottleFlag = FALSE;
TMR_StartSingleShotTimer(mTxZigBeeThrottleTimerID,
mTxZigBeeThrottleDuration_c,
TxZigBeeThrottleTimerCallBack);
} /* TxZigBeeData() */
/****************************************************************************/
/****************************************************************************/
static void TxZigBeeThrottleTimerCallBack(tmrTimerID_t timerID) {
(void) timerID;
mTxZigBeeThrottleFlag = TRUE;
} /* TzZigBeeThrottleTimerCallBack() */
static void wdgTimerCallBack(tmrTimerID_t timerID)
{
// (void) timerID;
// SIMRS=0xff;
}
static void TxZigBeequeryTimerCallBack(tmrTimerID_t timerID)
{
(void) timerID;
TS_SendEvent(gAppTaskID, mAppRetryUartDataTx_c);
return ;
}
/****************************************************************************/
/* When a datagram is sent OTA in reliable mode, a timer is started. */
/* When an ack or nak is received for that datagram, the timer is stopped. */
/* If the timer expires, the remote node apparently has not received the */
/* datagram, so set an event for ourselves to send it again. */
static void TxZigBeeDataRetryTimerCallBack(tmrTimerID_t timerID) {
(void) timerID;
zbTxDataBuffer.status = mBufStatusReadyToSend_c;
TS_SendEvent(gAppTaskID, mAppRetryZigBeeDataTx_c);
} /* TxZigBeeDataRetryTimerCallBack() */
/****************************************************************************/
/* A byte is available from the serial port. */
static void UartRxCallBack(void) {
TS_SendEvent(gAppTaskID, mAppRxFromUart_c);
} /* UartRxCallBack() */
/****************************************************************************/
/* The last byte received from the UART was long enough ago that it is now */
/* time to send any outstanding data, even if the buffer(s) are not full. */
static void UartRxTimeout(tmrTimerID_t timerID)
{
(void) timerID;
} /* UartRxTimeout() */
/****************************************************************************/
/* The UART has finished transmitting a buffer out through the serial port. */
/* pBuf is the start of the data that the UART driver sent, not the address */
/* of the buffer_t that contains it. */
static void UartTxCallBack(unsigned char const *pBuf) {
(void) pBuf;
uartTxDataBuffer.status = mBufStatusFree_c;
uartTxDataBuffer.len = 0;
} /* UartTxCallBack() */
uint8_t convertnoopti(uint8_t lqivalue)
{
uint8_t range;
lqi=(uint8_t)((190-((uint16_t)(lqi<<3))/13)>>1);
if(lqi<=52) range=1;
if((lqi>52)&&(lqi<70)) range=lqi/5-9;
if((lqi>=70)&&(lqi<82)) range=(lqi<<1)/3-42;
if((lqi>=82)&&(lqi<90)) range=(lqi<<1)-133;
if(lqi>=90) range=lqi*10-860;
return range;
}
// TpmReadCNTRegister(newtimenoopti);
uint8_t convertopti(uint8_t lqivalue)
{
uint8_t range;
lqi=(uint8_t)(190-((uint16_t)(lqi<<3))/13)>>1;
if(lqi<=52) range=1;
if((lqi>52)&& (lqi<70)) range=lqi/5-((46857/5)>>10);
if((lqi>=70)&&(lqi<82)) range=(lqi<<1)/3-42;
if((lqi>=82)&&(lqi<90)) range=(lqi<<1)-133;
if(lqi>=90) range=lqi*10-860;
return range;
}
uint16_t gettimenoopti(void)
{
uint16_t temptime;
uint16_t timeintip;
// Copy2Bytes(timenoopti,oldtimenoopti);
// Copy2Bytes(newtime,newtimenoopti);
if(newtimenoopti>=oldtimenoopti) temptime=newtimenoopti-oldtimenoopti;
if(newtimenoopti< oldtimenoopti) temptime=62500-oldtimenoopti+newtimenoopti;
timeintip= temptime<<4;
return timeintip;
}
uint16_t gettimeopti(void)
{
uint16_t temptime1;
uint16_t timeintip1;
// Copy2Bytes(timenoopti,oldtimenoopti);
// Copy2Bytes(newtime,newtimenoopti);
if(newtimeopti>=newtimenoopti) temptime1=newtimeopti-newtimenoopti;
if(newtimeopti< newtimenoopti) temptime1=62500-newtimenoopti+newtimeopti;
timeintip1= temptime1<<4;
return timeintip1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -