|
cddxhy 发表于 2012-4-7 20:10
楼上的能不能把你上传的串口数据 贴一个上来,分析一下
嗯,好的。整个过程如下。
关键代码及相关定义如下:
DemoApp.h里面的相关部分
#define TEMP_SRC_INTER 0
#define TEMP_SRC_OUTER 1
#define TEMP_SRC_TMP123 2 //Append by Ryan
#define TEMP_SRC_SHT11 3
#define TEMP_SRC_BMP085 4
#define TEMP_SRC_CH4 5
#define TEMP_SRC TEMP_SRC_SHT11
#if TEMP_SRC == TEMP_SRC_SHT11
#define HUMIDITY
#endif
#if TEMP_SRC == TEMP_SRC_BMP085
#define PRESSURE
#endif
#if TEMP_SRC == TEMP_SRC_CH4
#define CH4
#endif
//16bits userID
#define SENSOR_UID_HI 0x00
//#define SENSOR_UID_LO 0x01//温度
//#define SENSOR_UID_LO 0x02 //人体
#define SENSOR_UID_LO 0x00 //SHT11时
#define SENSOR_REPORT_LENGTH 17// 4
//0-5 for system type 类型低四位定义
#define SENSOR_SYS_INDEX_UID 0 //max 2 bytes
#define SENSOR_SYS_INDEX_IEEE 1 //max 8 bytes
#define SENSOR_SYS_INDEX_PRNT 2 //max 2 bytes
#define SENSOR_SYS_INDEX_RSSI 3 //max 1 byte
//6-15 for user defined type
#define SENSOR_USER_INDEX_TEMP 6 //max 2 bytes
#define SENSOR_USER_INDEX_HUMI 7 //max 1 byte
#define SENSOR_USER_INDEX_VOLT 8 //max 2 bytes
#define SENSOR_USER_INDEX_BMP085 9 //max 1 byte
#define SENSOR_USER_INDEX_CH4 10 //max 1 byte
//#define SENSOR_USER_INDEX_3DZ 11 //max 1 byte
// max bytes = 18= SENSOR_REPORT_LENGTH 类型高四位定义
#define SNRDATA_TYPE_ONOFF 0x00
#define SNRDATA_TYPE_1BUNSIGN 0x10
#define SNRDATA_TYPE_1BSIGN 0x20
#define SNRDATA_TYPE_2BUNSIGN 0x30
#define SNRDATA_TYPE_2BSIGN 0x40
#define SNRDATA_TYPE_2BSIGND 0x50
#define SNRDATA_TYPE_4BSIGN 0x60
#define SNRDATA_TYPE_4BFLOAT 0x70
#define SNRDATA_TYPE_8BIEEE 0x80
传感器发送数据部分:
static void sendReport(void)
{
uint8 pData[SENSOR_REPORT_LENGTH];
static uint8 reportNr=0;
uint8 txOptions;
uint8 index = 0;
//userID
pData[index++] = SNRDATA_TYPE_2BUNSIGN | SENSOR_SYS_INDEX_UID;
pData[index++] = SENSOR_UID_HI;
pData[index++] = SENSOR_UID_LO;
// Read and report temperature value(温度)
pData[index++] = SNRDATA_TYPE_2BSIGND|SENSOR_USER_INDEX_TEMP;
pData[index++] = readTemp();
pData[index++] = iTemp2;
// Read and report voltage value (电压)
pData[index++] = SNRDATA_TYPE_1BSIGN|SENSOR_USER_INDEX_VOLT;
pData[index++] = readVoltage();
// Read and report humidity value (湿度)
#ifdef HUMIDITY
pData[index++] = SNRDATA_TYPE_1BSIGN|SENSOR_USER_INDEX_HUMI;
pData[index++] = iHumidity;
#else
pData[index++] = 0;
#endif
// Read and report air pressure value (气压)
#ifdef PRESSURE
pData[index++] = SNRDATA_TYPE_1BSIGN|SENSOR_USER_INDEX_BMP085;
pData[index++] = readPress();
#else
pData[index++] = 0 ;
#endif
// Read and report ch4 value (甲烷)
#ifdef CH4
pData[index++] = SNRDATA_TYPE_1BSIGN|SENSOR_USER_INDEX_CH4;
pData[index++] = ch4Value ;
#else
pData[index++]= 0;
#endif
// Set ACK request on each ACK_INTERVAL report
// If a report failed, set ACK request on next report
if ( ++reportNr<ACK_REQ_INTERVAL && reportFailureNr==0 )
{
txOptions = AF_TX_OPTIONS_NONE;
}
else
{
txOptions = AF_MSG_ACK_REQUEST;
reportNr = 0;
}
// Destination address 0xFFFE: Destination address is sent to previously
// established binding for the commandId.
zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 );
}
注:里面的相关函数和参数之前用FST测试过,能够正常读出。{:soso_e100:}
协调器接收数据部分
接收数据指示:
void zb_ReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData )
{
uint8 *gtwDataptr;
uint8 gtwDataLen;
//get from sensor, add 5 bytes for MUST data.
gtwDataLen = len+5;
gtwDataptr = osal_mem_alloc(gtwDataLen);
//fill in data
//start
*gtwDataptr = 0xFB;
//data length
*(gtwDataptr+1) = len;
//source addr
*(gtwDataptr+2) = HI_UINT16(source);
*(gtwDataptr+3) = LO_UINT16(source);
//copy data from sensor
osal_memcpy((gtwDataptr+4), pData, len);
//CRC
*(gtwDataptr+len+4) = calcFCS(gtwDataptr,gtwDataLen-1);
// Flash LED 2 once to indicate data reception
HalLedSet ( HAL_LED_2, HAL_LED_MODE_FLASH );
// Update the display
#if defined ( LCD_SUPPORTED )
HalLcdWriteScreen( "Report", "rcvd" );
#endif
// Send gateway report
sendGtwReport(>wData);
}
发送报告:
static void sendGtwReport(gtwData_t *gtwData)
{
uint8 pFrame[ZB_RECV_LENGTH];
// Start of Frame Delimiter
pFrame[FRAME_SOF_OFFSET] = CPT_SOP; // Start of Frame Delimiter
// Length
pFrame[FRAME_LENGTH_OFFSET] = 6+SENSOR_REPORT_LENGTH;
// Command type
pFrame[FRAME_CMD0_OFFSET] = LO_UINT16(ZB_RECEIVE_DATA_INDICATION);
pFrame[FRAME_CMD1_OFFSET] = HI_UINT16(ZB_RECEIVE_DATA_INDICATION);
// Source address
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_SRC_OFFSET] = LO_UINT16(gtwData->source);
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_SRC_OFFSET+ 1] = HI_UINT16(gtwData->source);
// Command ID
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_CMD_OFFSET] = LO_UINT16(SENSOR_REPORT_CMD_ID);
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_CMD_OFFSET+ 1] = HI_UINT16(SENSOR_REPORT_CMD_ID);
// Length
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_LEN_OFFSET] = LO_UINT16(SENSOR_REPORT_LENGTH);
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_LEN_OFFSET+ 1] = HI_UINT16(SENSOR_REPORT_LENGTH);
// Data
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET] = gtwData->temp;
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET+ 1] = gtwData->voltage;
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET+ 2] = LO_UINT16(gtwData->parent);
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET+ 3] = HI_UINT16(gtwData->parent);
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET+ SENSOR_TEMP2_OFFSET] = gtwData->temp_2;
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET+ SENSOR_HUMIDITY_OFFSET] = gtwData->Humidity;
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET+ SENSOR_BMP085PRESSURE_OFFSET] = gtwData->pressure;
pFrame[FRAME_DATA_OFFSET+ ZB_RECV_DATA_OFFSET+ SENSOR_CH4_OFFSET] = gtwData->ch4;
// Frame Check Sequence
pFrame[ZB_RECV_LENGTH - 1] = calcFCS(&pFrame[FRAME_LENGTH_OFFSET], (ZB_RECV_LENGTH - 2) );
// Write report to UART
HalUARTWrite(HAL_UART_PORT_0,pFrame, ZB_RECV_LENGTH);
}
然后在用飞比物联网浏览器时,有以下情况发生:
1、发现节点后(呜,不知道怎么把图片附上去。。。)
|
|