本帖最后由 njtechlhr 于 2021-7-19 13:13 編輯
我想用串口調試助手發送指令來讓模塊控制繼電器(發送211為打開繼電器,發送200為關閉繼電器),該模塊上還有一個PM2.5傳感器,每3秒輸出一個5個字節的數據到串口調試助手上,如下圖:但是我點擊發送數據給模塊皆沒有反應,找不到原因,代碼在下面(由于不知道到底是哪一部分代碼出了問題,因此我將協調器和終端的代碼都放上來了),希望有大佬指點迷津:
2.png (142.77 KB, 下載次數: 38)
下載附件
2021-7-18 11:49 上傳
協調器代碼:
#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "GenericApp.h"
#include "DebugTrace.h"
#if !defined( WIN32 )
#include "OnBoard.h"
#endif
/* HAL */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_uart.h"
// This list should be filled with Application specific Cluster IDs.
const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
{
GENERICAPP_CLUSTERID
};
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;
GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters;
(cId_t *)GenericApp_ClusterList // byte *pAppInClusterList;
};
endPointDesc_t GenericApp_epDesc;
byte GenericApp_TaskID; // Task ID for internal task/event processing
// This variable will be received when
// GenericApp_Init() is called.
devStates_t GenericApp_NwkState;
byte GenericApp_TransID; // This is the unique message ID (counter)
afAddrType_t GenericApp_DstAddr;
static uint8 SerialApp_Len;
uint8 SerialApp_Buf[5];
char Duanxin_fasong[1];
char senddata[] = {"T: H: G: PM: "};
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
static void GenericApp_HandleKeys( byte shift, byte keys );
static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
static void rxCB(uint8 port,uint8 event);
#if defined( IAR_ARMCM3_LM )
static void GenericApp_ProcessRtosMessage( void );
#endif
void Delay_MS(unsigned int msec);
void UartSendString(char *Data, int len);
void Delay10us(void);
__interrupt void UART0_ISR(void);
/*********************************************************************
* @fn GenericApp_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 GenericApp_Init( uint8 task_id )
{
GenericApp_TaskID = task_id;
GenericApp_NwkState = DEV_INIT;
GenericApp_TransID = 0;
P0DIR &= ~0x20; //P0.5定義為輸出口
Duanxin_fasong[0] = 0x1A;
PERCFG = 0x00; //外設控制寄存器 USART 0的IO位置:0為P0口位置1
P0SEL = 0x0c; //P0_2,P0_3用作串口(外設功能)
P2DIR &= ~0XC0; //P0優先作為UART0
U0CSR |= 0x80; //設置為UART方式
U0GCR |= 11;
U0BAUD |= 216; //波特率設為9600
UTX0IF = 0; //UART0 TX中斷標志初始置位0
U0CSR |= 0x40; //允許接收
IEN0 |= 0x84; //開總中斷允許接收中斷
//下面六句是我加的,初始化串口的
halUARTCfg_t uartConfig;//定義個串口結構體
uartConfig.configured =TRUE;//串口配置為真
uartConfig.baudRate =HAL_UART_BR_9600;//波特率為9600
uartConfig.flowControl =FALSE;//流控制為假
uartConfig.callBackFunc = rxCB;//定義串口回調函數,什么叫做回調函數,
//說白了,就是當模塊收從串口到外部設備
//的數據時,會調用這個函數進行處理,
HalUARTOpen(HAL_UART_PORT_0,&uartConfig);// 打開串口0
HalUARTWrite(0,"1234",4);//我加的
UartSendString("AT+CIPMUX=1\r\n",13);
DelayMS(1000);
UartSendString("AT+CIPSERVER=1,6666\r\n", 21);
DelayMS(1000);
GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;//設置成廣播
GenericApp_DstAddr.endPoint = GENERICAPP_ENDPOINT;
GenericApp_DstAddr.addr.shortAddr = 0xFFFF;//向所有節點廣播
// Fill out the endpoint description.
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc
= (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;
// Register the endpoint description with the AF
afRegister( &GenericApp_epDesc );
// Register for all key events - This app will handle all key events
RegisterForKeys( GenericApp_TaskID );
// Update the display
#if defined ( LCD_SUPPORTED )
HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 );
#endif
ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp );
ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp );
//添加:
#if defined( IAR_ARMCM3_LM )
// Register this task with RTOS task initiator
RTOS_RegisterApp( task_id, GENERICAPP_RTOS_MSG_EVT );
#endif
}
/*********************************************************************
* @fn GenericApp_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 GenericApp_ProcessEvent( uint8 task_id, uint16 events )
{
afIncomingMSGPacket_t *MSGpkt;
afDataConfirm_t *afDataConfirm;
// Data Confirmation message fields
byte sentEP;
ZStatus_t sentStatus;
byte sentTransID; // This should match the value sent
(void)task_id; // Intentionally unreferenced parameter
if ( events & SYS_EVENT_MSG )
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
while ( MSGpkt )
{
switch ( MSGpkt->hdr.event )
{
case ZDO_CB_MSG:
GenericApp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
break;
case KEY_CHANGE:
GenericApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
case AF_DATA_CONFIRM_CMD:
// This message is received as a confirmation of a data packet sent.
// The status is of ZStatus_t type [defined in ZComDef.h]
// The message fields are defined in AF.h
afDataConfirm = (afDataConfirm_t *)MSGpkt;
sentEP = afDataConfirm->endpoint;
sentStatus = afDataConfirm->hdr.status;
sentTransID = afDataConfirm->transID;
(void)sentEP;
(void)sentTransID;
// Action taken when confirmation is received.
if ( sentStatus != ZSuccess )
{
// The data wasn't delivered -- Do something
}
break;
case AF_INCOMING_MSG_CMD:
GenericApp_MessageMSGCB( MSGpkt );
break;
case ZDO_STATE_CHANGE:
GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
if ( (GenericApp_NwkState == DEV_ZB_COORD)
|| (GenericApp_NwkState == DEV_ROUTER)
|| (GenericApp_NwkState == DEV_END_DEVICE) )
{
}
break;
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
// Next
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
// Discard unknown events
return 0;
}
/*********************************************************************
* Event Generation Functions
*/
/*********************************************************************
* @fn GenericApp_ProcessZDOMsgs()
*
* @brief Process response messages
*
* @param none
*
* @return none
*/
/*
增加串口回調函數 rxCB 用于控制繼電器
*/
static void rxCB(uint8 port, uint8 event)
{
uint8 uartbuf[3];
HalUARTRead(0,uartbuf,3);
AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
GENERICAPP_CLUSTERID,
3,
uartbuf,
&GenericApp_TransID,
AF_DISCV_ROUTE,AF_DEFAULT_RADIUS );
}
static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
{
switch ( inMsg->clusterID )
{
case End_Device_Bind_rsp:
if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess )
{
// Light LED
HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
}
#if defined( BLINK_LEDS )
else
{
// Flash LED to show failure
HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH );
}
#endif
break;
case Match_Desc_rsp:
{
ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );
if ( pRsp )
{
if ( pRsp->status == ZSuccess && pRsp->cnt )
{
GenericApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
GenericApp_DstAddr.addr.shortAddr = pRsp->nwkAddr;
// Take the first endpoint, Can be changed to search through endpoints
GenericApp_DstAddr.endPoint = pRsp->epList[0];
// Light LED
HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
}
osal_mem_free( pRsp );
}
}
break;
}
}
/*********************************************************************
* @fn GenericApp_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:
* HAL_KEY_SW_4
* HAL_KEY_SW_3
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void GenericApp_HandleKeys( uint8 shift, uint8 keys )
{
if ( keys & HAL_KEY_SW_1 )
{
}
if ( keys & HAL_KEY_SW_2 )
{
}
if ( keys & HAL_KEY_SW_3 )
{
}
if ( keys & HAL_KEY_SW_4 )
{
}
}
/*********************************************************************
* LOCAL FUNCTIONS
*/
/*********************************************************************
* @fn GenericApp_MessageMSGCB
*
* @brief Data message processor callback. This function processes
* any incoming data - probably from other devices. So, based
* on cluster ID, perform the intended action.
*
* @param none
*
* @return none
*/
static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
char rcvdata[5];
switch ( pkt->clusterId )
{
case GENERICAPP_CLUSTERID:
if(pkt->cmd.Data[0] == 0x1A & pkt->cmd.Data[1] == 0x60)
{
osal_memcpy(rcvdata, pkt->cmd.Data, 5);
UartSendString(rcvdata,5);
DelayMS(100);
}
break;
}
}
/*********************************************************************
*/
/****************************************************************************
* 名 稱: DelayMS()
* 功 能: 以毫秒為單位延時 16M時約為535,32M時要調整,系統時鐘不修改默認為16M
* 入口參數: msec 延時參數,值越大延時越久
* 出口參數: 無
****************************************************************************/
void Delay10us(void) //10 us延時
{
MicroWait(10);
}
void Delay_MS(unsigned int msec)
{
unsigned char i;
while(msec--)
{
for(i=0;i<100;i++)
Delay10us();
}
}
void UartSendString(char *Data, int len)
{
unsigned int i;
for(i=0; i<len; i++)
{
U0DBUF = *Data++;
while(UTX0IF == 0);
UTX0IF = 0;
}
}
char Serial_Rcv_Lenth=0;
unsigned char RxData[5] = {0}; //存儲發送字符串
unsigned char RxBuf;
#pragma vector = URX0_VECTOR
__interrupt void UART0_ISR(void)
{
URX0IF = 0; // 清中斷標志
RxBuf = U0DBUF;
if(RxBuf==0x2A || Serial_Rcv_Lenth>0)
{
RxData[Serial_Rcv_Lenth] = RxBuf;
Serial_Rcv_Lenth++;
}
if(Serial_Rcv_Lenth==5)
{
AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
GENERICAPP_CLUSTERID,
5,
RxData,
&GenericApp_TransID,
AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
HalLedSet( HAL_LED_1, HAL_LED_MODE_TOGGLE );
Serial_Rcv_Lenth=0;
}
}
終端代碼:
#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "GenericApp.h"
#include "DebugTrace.h"
#if !defined( WIN32 )
#include "OnBoard.h"
#endif
/* HAL */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_uart.h"
#include "hal_adc.h"
#include "DHT11.h"
// This list should be filled with Application specific Cluster IDs.
const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
{
GENERICAPP_CLUSTERID
};
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;
GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters;
(cId_t *)GenericApp_ClusterList // byte *pAppInClusterList;
};
// This is the Endpoint/Interface description. It is defined here, but
// filled-in in GenericApp_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 GenericApp_epDesc;
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
byte GenericApp_TaskID; // Task ID for internal task/event processing
// This variable will be received when
// GenericApp_Init() is called.
devStates_t GenericApp_NwkState;
byte GenericApp_TransID; // This is the unique message ID (counter)
afAddrType_t GenericApp_DstAddr;
byte sensorID = 0x02;
byte str[4];
byte flag = 0;
uint8 SerialApp_Buf[20];
uint8 pm_h,pm_l;
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
static void GenericApp_HandleKeys( byte shift, byte keys );
static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
void GenericApp_Send_pm25_Message( void );//我加的,溫濕度無線發送函數
uint8 myApp_ReadGasLevel( void );//我加的,讀取煙霧數值
static void rxCB(uint8 port, uint8 event);//聲明串口回調函數
//添加:
#if defined( IAR_ARMCM3_LM )
static void GenericApp_ProcessRtosMessage( void );
#endif
/*********************************************************************
* @fn GenericApp_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 GenericApp_Init( uint8 task_id )
{
GenericApp_TaskID = task_id;
GenericApp_NwkState = DEV_INIT;
GenericApp_TransID = 0;
P1DIR |= 0xEC; //<-li P1DIR |= 0xE4;
P1_2 = 1;
P1_5 = 1;
P1_6 = 1;
P1_7 = 1;
P1_2 = 0;
P1_5 = 0;
P1_6 = 0;
P1_7 = 0;
P1_3 = 0; //li繼電器低電平
HalLedSet( HAL_LED_1, HAL_LED_MODE_OFF );
//下面六句是我加的,初始化串口的
halUARTCfg_t uartConfig;//頂一個串口結構體
uartConfig.configured =TRUE;//串口配置為真
uartConfig.baudRate =HAL_UART_BR_9600;//波特率為115200
uartConfig.flowControl =FALSE;//流控制為假
uartConfig.callBackFunc = rxCB;
HalUARTOpen(HAL_UART_PORT_0,&uartConfig);// 打開串口0
// Device hardware initialization can be added here or in main() (Zmain.c).
// If the hardware is application specific - add it here.
// If the hardware is other parts of the device add it in main().
GenericApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;//單播
GenericApp_DstAddr.endPoint = GENERICAPP_ENDPOINT;
GenericApp_DstAddr.addr.shortAddr = 0x0000;//向協調器單播的形式加入網絡
// Fill out the endpoint description.
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc
= (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;
// Register the endpoint description with the AF
afRegister( &GenericApp_epDesc );
// Register for all key events - This app will handle all key events
RegisterForKeys( GenericApp_TaskID );
// Update the display
#if defined ( LCD_SUPPORTED )
HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 );
#endif
ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp );
ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp );
}
/*********************************************************************
* @fn GenericApp_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 GenericApp_ProcessEvent( uint8 task_id, uint16 events )
{
afIncomingMSGPacket_t *MSGpkt;
afDataConfirm_t *afDataConfirm;
// Data Confirmation message fields
byte sentEP;
ZStatus_t sentStatus;
byte sentTransID; // This should match the value sent
(void)task_id; // Intentionally unreferenced parameter
if ( events & SYS_EVENT_MSG )
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
while ( MSGpkt )
{
switch ( MSGpkt->hdr.event )
{
case ZDO_CB_MSG:
GenericApp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
break;
case KEY_CHANGE:
GenericApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
case AF_DATA_CONFIRM_CMD:
// This message is received as a confirmation of a data packet sent.
// The status is of ZStatus_t type [defined in ZComDef.h]
// The message fields are defined in AF.h
afDataConfirm = (afDataConfirm_t *)MSGpkt;
sentEP = afDataConfirm->endpoint;
sentStatus = afDataConfirm->hdr.status;
sentTransID = afDataConfirm->transID;
(void)sentEP;
(void)sentTransID;
// Action taken when confirmation is received.
if ( sentStatus != ZSuccess )
{
// The data wasn't delivered -- Do something
}
break;
case AF_INCOMING_MSG_CMD:
GenericApp_MessageMSGCB( MSGpkt );
break;
case ZDO_STATE_CHANGE:
GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
P1_2 = 0;
if ( (GenericApp_NwkState == DEV_ZB_COORD)
|| (GenericApp_NwkState == DEV_ROUTER)
|| (GenericApp_NwkState == DEV_END_DEVICE) )
{
// Start sending "the" message in a regular interval.
osal_start_timerEx( GenericApp_TaskID,
GENERICAPP_SEND_MSG_EVT,
GENERICAPP_SEND_MSG_TIMEOUT );
}
break;
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
// Next
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
// Send a message out - This event is generated by a timer
// (setup in GenericApp_Init()).
if ( events & GENERICAPP_SEND_MSG_EVT )
{
//你只要在這里填寫上,你想調用的函數,這個函數就會被周期性執行
// Send "the" message
GenericApp_Send_pm25_Message();
// Setup to send message again
osal_start_timerEx( GenericApp_TaskID,
GENERICAPP_SEND_MSG_EVT,
GENERICAPP_SEND_MSG_TIMEOUT );
// return unprocessed events
return (events ^ GENERICAPP_SEND_MSG_EVT);
}
// Discard unknown events
return 0;
}
/*********************************************************************
* Event Generation Functions
*/
/*********************************************************************
* @fn GenericApp_ProcessZDOMsgs()
*
* @brief Process response messages
*
* @param none
*
* @return none
*/
static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
{
switch ( inMsg->clusterID )
{
case End_Device_Bind_rsp:
if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess )
{
// Light LED
HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
}
#if defined( BLINK_LEDS )
else
{
// Flash LED to show failure
HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH );
}
#endif
break;
case Match_Desc_rsp:
{
ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );
if ( pRsp )
{
if ( pRsp->status == ZSuccess && pRsp->cnt )
{
GenericApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
GenericApp_DstAddr.addr.shortAddr = pRsp->nwkAddr;
// Take the first endpoint, Can be changed to search through endpoints
GenericApp_DstAddr.endPoint = pRsp->epList[0];
// Light LED
HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
}
osal_mem_free( pRsp );
}
}
break;
}
}
/*********************************************************************
* @fn GenericApp_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:
* HAL_KEY_SW_4
* HAL_KEY_SW_3
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void GenericApp_HandleKeys( uint8 shift, uint8 keys )
{
if ( keys & HAL_KEY_SW_1 )
{
}
if ( keys & HAL_KEY_SW_2 )
{
}
if ( keys & HAL_KEY_SW_3 )
{
}
if ( keys & HAL_KEY_SW_4 )
{
}
}
/*********************************************************************
* LOCAL FUNCTIONS
*/
/*********************************************************************
* @fn GenericApp_MessageMSGCB
*
* @brief Data message processor callback. This function processes
* any incoming data - probably from other devices. So, based
* on cluster ID, perform the intended action.
*
* @param none
*
* @return none
*/
uint8 buffer[3];
static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
uint8 BUFFER[1]; //對首位地址對接收的數據進行校驗,檢查是否有效
switch ( pkt->clusterId )
{
case GENERICAPP_CLUSTERID:
osal_memcpy(BUFFER,pkt->cmd.Data,1);
if(BUFFER[0]=='2') //校驗準確才開始提取數據,避免重復osal_memcpy覆蓋原數據(方法來自ID:lkc8210)
{
osal_memcpy(buffer,pkt->cmd.Data,3);
}
if(buffer[0]=='2')
{
if((buffer[1]=='1') && (buffer[2]=='1'))
{
P1_3 = 1;
}
if((buffer[1]=='0') && (buffer[2]=='0'))
{
P1_3 = 0;
}
}
break;
}
}
static void GenericApp_Send_pm25_Message(void)
{
byte PM_str[8];
DHT11(); //獲取溫濕度
PM_str[0] = 0x1A;//數據包頭,表示是節點往上傳數據
PM_str[1] = 0x60;//數據是pm25數據
PM_str[2] = 0x02;//模塊ID號
PM_str[3] = pm_h;//LO_UINT16( pm_h );
PM_str[4] = pm_l;//HI_UINT16( pm_l );
AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
GENERICAPP_CLUSTERID,
5,//發送的內容長度
PM_str,//要發送的溫度字符
&GenericApp_TransID,
AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
}
/*******************************************************************
串口囘調函數,一旦受到串口來的數據,會進入此函數進行處理
*******************************************************************/
static void rxCB(uint8 port, uint8 event)
{
if ((event & (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT)))
{
HalUARTRead(0, SerialApp_Buf, 9);
for(uint8 i=0; i<15; i++)
{
if(SerialApp_Buf[0] == 0xff && SerialApp_Buf[1] == 0x18)
{
HalLedSet( HAL_LED_1, HAL_LED_MODE_TOGGLE );
pm_h=SerialApp_Buf[3];
pm_l=SerialApp_Buf[4];
}
}
}
}
拜托了!
|