/****************************************************************************** * @fn zb_ReceiveDataIndication * * @brief The zb_ReceiveDataIndication callback function is called * asynchronously by the ZigBee stack to notify the application * when data is received from a peer device. * * @param source - The short address of the peer device that sent the data * command - The commandId associated with the data * len - The number of bytes in the pData parameter * pData - The data sent by the peer device * * @return none */ void zb_ReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData ) { if (pData[len-1] == DOOR_UNLOCKED || pData[len-1] == DOOR_LOCKED) { if (pData[len-1] == DOOR_LOCKED) { MCU_IO_SET_HIGH(LED_PORT, LED_PIN); } else { MCU_IO_SET_LOW(LED_PORT, LED_PIN); } } }
/****************************************************************************** * @fn sendReport * * @brief Send sensor report * * @param none * * @return none */ static void sendReport(void) { uint8 pData[SENSOR_REPORT_LENGTH]; static uint8 reportNr = 0; uint8 txOptions; // Read and report temperature value pData[SENSOR_TEMP_OFFSET] = readTemp(); // Read and report voltage value pData[SENSOR_VOLTAGE_OFFSET] = readVoltage(); pData[SENSOR_PARENT_OFFSET] = HI_UINT16(parentShortAddr); pData[SENSOR_PARENT_OFFSET + 1] = LO_UINT16(parentShortAddr); pData[BUTTON_PARENT_OFFSET+1] = MCU_IO_GET(0,1); // HalUARTWrite(HAL_UART_PORT_0,pData,SENSOR_REPORT_LENGTH); // HalUARTWrite(HAL_UART_PORT_1,pData,SENSOR_REPORT_LENGTH); int test = MCU_IO_GET(0,1); if( MCU_IO_GET(0,1) > 0){ MCU_IO_SET_LOW(0, 0); } else { MCU_IO_SET_HIGH(0, 0); } MCU_IO_SET_LOW(0, 1); // 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. //printf("%i %i",pData[SENSOR_TEMP_OFFSET],oldValue); if(timeDone >= 60000){ timeDone += 1; } if(pData[SENSOR_TEMP_OFFSET] != oldValue && timeDone >= 60000){ oldValue = pData[SENSOR_TEMP_OFFSET]; zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 ); timeDone = 0; } else { timeDone += myReportPeriod; } }