/********************************************************************* * @fn SampleApp_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 SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; MT_UartInit();//串口初始化 MT_UartRegisterTaskID(task_id);//登记任务号 #ifdef MODE_ED //终端节点下才配置 /**************超声波***************/ #define trig P0_1 #define echo P0_0 P0DIR |= 0x02; //P01输出trig P0DIR &= ~0x01; //P00输入echo trig=0; /*定时器配置*/ HalTimerInit(); HalTimerConfig(HAL_TIMER_0, HAL_TIMER_MODE_CTC, HAL_TIMER_CHANNEL_SINGLE, HAL_TIMER_CH_MODE_OUTPUT_COMPARE, TRUE, timer_callback); /***********步进电机**************/ #define in1 P0_4 #define in2 P0_5 #define in3 P0_6 #define in4 P0_7 P0SEL &=~0xf0; P0DIR |= 0xf0; P0INP &=~0Xf0; //打开上拉 in1=0; in2=0; in3=0; in4=0; /*测试*/ int i=0; for(i=0;i<128;i++) { MotorCW(); } for(i=0;i<128;i++) { MotorCCW(); } HalLedBlink( HAL_LED_2, 2,50, 500); #endif // 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(). #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP; // 网蜂点对点通讯定义 Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;//点播 Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; Point_To_Point_DstAddr.addr.shortAddr = 0x0000; //发给协调器 // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID ); // By default, all devices start out in Group 1 SampleApp_Group.ID = 0x0001; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SmartPark", HAL_LCD_LINE_1 ); #endif }
void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; //uart open(SampleApp_TaskID); // 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(). #if defined ( SOFT_START ) // The "Demo" target is setup to have SOFT_START and HOLD_AUTO_START // SOFT_START is a compile option that allows the device to start // as a coordinator if one isn't found. // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // SOFT_START #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Flash_DstAddr.addr.shortAddr = 0xFFFF; //�s�� //end device /* coordinator to end device must 0xffff end device to coordinator must 0x0000 */ //mpleApp_Flash_DstAddr.addr.shortAddr = 0x0000; //SampleApp_Flash_DstAddr.addr.shortAddr =SAMPLEAPP_FLASH_GROUP; //coordinator // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID ); // By default, all devices start out in Group 1 SampleApp_Group.ID = SAMPLEAPP_FLASH_GROUP; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); #if defined( HAL_UART ) open(SampleApp_TaskID); #endif #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 ); #endif }
void CurrentDetectionT1_Init(uint8 task_id) { IO_Init(); CurrentDetectionT1_TaskID = task_id; CurrentDetectionT1_NwkState = DEV_INIT; CurrentDetectionT1_TransID = 0; MT_UartInit(); MT_UartRegisterTaskID(task_id); // 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(). #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in CurrentDetectionT1Hw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if (readCoordinatorJumper()) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES // Setup for the periodic message's destination address // Broadcast to everyone CurrentDetectionT1_Periodic_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; CurrentDetectionT1_Periodic_DstAddr.endPoint = HEARTBEAT_ENDPOINT; CurrentDetectionT1_Periodic_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. CurrentDetectionT1_epDesc.endPoint = HEARTBEAT_ENDPOINT; CurrentDetectionT1_epDesc.task_id = &CurrentDetectionT1_TaskID; CurrentDetectionT1_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&CurrentDetectionT1_SimpleDesc; CurrentDetectionT1_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister(&CurrentDetectionT1_epDesc); // Register for all key events - This app will handle all key events RegisterForKeys(CurrentDetectionT1_TaskID); nv_read_config(); HalAdcInit(); HalAdcSetReference(HAL_ADC_REF_AVDD); #ifdef DEBUG_TRACE //memset(serialNumber, 0, SN_LEN); //serialNumber[SN_LEN - 1] = 20; #endif memcpy(serialNumber, aExtendedAddress, SN_LEN); //Feed WatchDog WDCTL = 0xa0; WDCTL = 0x50; osal_start_timerEx(CurrentDetectionT1_TaskID, DTCT_HEARTBEAT_MSG_EVT, 10); osal_start_timerEx(CurrentDetectionT1_TaskID, DTCT_LED_WTD_EVT, 10); }
/********************************************************************* * @fn SampleApp_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 SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; //initial uart1 and uart0 initUart1(UART_callback); MT_UartInit();//初始化 // 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(). #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP; // 点对点通讯定义 Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; //点播 Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; Point_To_Point_DstAddr.addr.shortAddr = 0x0000;//发给协调器 // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID ); // By default, all devices start out in Group 1 SampleApp_Group.ID = 0x0001; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); }
/********************************************************************* * @fn ParkingApp_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 ParkingApp_Init( uint8 task_id ) { //开始应用初始化,闪灯 //HalLedSet(HAL_LED_1,HAL_LED_MODE_FLASH); HalLedBlink( HAL_LED_1, 10, 50, 1000 ); ParkingApp_TaskID = task_id; ParkingApp_NwkState = DEV_INIT; ParkingApp_TransID = 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(). #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in ParkingAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone #if (defined DATABROADCAST && DATABROADCAST == TRUE) ParkingApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; //afAddr16Bit; ParkingApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // 0x0000; #else ParkingApp_Periodic_DstAddr.addrMode = (afAddrMode_t)afAddr16Bit; ParkingApp_Periodic_DstAddr.addr.shortAddr = 0x0000; #endif ParkingApp_Periodic_DstAddr.endPoint = PARKINGAPP_ENDPOINT; // Fill out the endpoint description. ParkingApp_epDesc.endPoint = PARKINGAPP_ENDPOINT; ParkingApp_epDesc.task_id = &ParkingApp_TaskID; ParkingApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&ParkingApp_SimpleDesc; ParkingApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &ParkingApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( ParkingApp_TaskID ); osal_pwrmgr_task_state( ParkingApp_TaskID, PWRMGR_CONSERVE ); // Set TXPOWER // MAC_MlmeSetReq( ZMacPhyTransmitPower, &txPower ); // By default, all devices start out in Group 1 ParkingApp_Group.ID = 0x0005; osal_memcpy( ParkingApp_Group.name, "Group 1", 7 ); aps_AddGroup( PARKINGAPP_ENDPOINT, &ParkingApp_Group ); }
/********************************************************************* * @fn SampleApp_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 SampleApp_Init( uint8 task_id ) { macRadioSetTxPower(20); SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; /***********串口初始化****************/ MT_UartInit(); //串口配置初始化 MT_UartRegisterTaskID(task_id);//登记串口任务号 HalUARTWrite(0,"Hello World\r\n",13); // (串口 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(). #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP; // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID ); /*分组信息初始化*/ SampleApp_Group.ID = 0x0001; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 ); #endif }