/****************************************************************************** * @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; } }
/****************************************************************************** * @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 zb_HandleOsalEvent * * @brief The zb_HandleOsalEvent function is called by the operating * system when a task event is set * * @param event - Bitmask containing the events that have been set * * @return none */ void zb_HandleOsalEvent( uint16 event ) { if( event & SYS_EVENT_MSG ) { } if( event & ZB_ENTRY_EVENT ) { // blind LED 1 to indicate joining a network HalLedBlink ( HAL_LED_1, 0, 50, 500 ); // Start the device zb_StartRequest(); MCU_IO_DIR_OUTPUT(LED_PORT, LED_PIN); MCU_IO_SET_LOW(LED_PORT, LED_PIN); } if ( event & MY_START_EVT ) { zb_StartRequest(); } if ( event & MY_REPORT_EVT ) { if ( appState == APP_REPORT ) { osal_start_timerEx( sapi_TaskID, MY_REPORT_EVT, myReportPeriod ); } } if ( event & MY_FIND_COLLECTOR_EVT ) { // blind LED 2 to indicate discovery and binding HalLedBlink ( HAL_LED_2, 0, 50, 500 ); appState = APP_BIND; // Find and bind to a collector device zb_BindDevice( TRUE, ROUTER_REPORT_CMD_ID, (uint8 *)NULL ); } }