⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsn_coordinator.c

📁 ZIGBEE1015无线传感器统会自动删除debug和release目录
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
 *
 * MODULE:			   WSN - Coordinator
 *
 * COMPONENT:          $RCSfile: WSN_Coordinator.c,v $
 *
 * VERSION:            $Name:  $
 *
 * REVISION:           $Revision: 1.7 $
 *
 * DATED:              $Date: 2007/07/12 11:03:03 $
 *
 * STATUS:             $State: Exp $
 *
 * AUTHOR:             IDM
 *
 * DESCRIPTION:
 *
 * Implements a Wireless Sensor Network Coordinator Node using Jennic Zigbee
 * stack. Receives data from compatible nodes via the radio and retransmits to
 * to host using UART.
 *
 * Update history
 * $Log: WSN_Coordinator.c,v $
 * Revision 1.7  2007/07/12 11:03:03  ndani
 * Add simple descriptor after network has started
 *
 * Revision 1.6  2007/07/12 10:03:34  ndani
 *
 *
 * LAST MODIFIED BY:   $Author: ndani $
 *                     $Modtime: $
 *
 ****************************************************************************
 *
 * This software is owned by Jennic and/or its supplier and is protected
 * under applicable copyright laws. All rights are reserved. We grant You,
 * and any third parties, a license to use this software solely and
 * exclusively on Jennic products. You, and any third parties must reproduce
 * the copyright and warranty notice and any other legend of ownership on each
 * copy or partial copy of the software.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS". JENNIC MAKES NO WARRANTIES, WHETHER
 * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
 * ACCURACY OR LACK OF NEGLIGENCE. JENNIC SHALL NOT, IN ANY CIRCUMSTANCES,
 * BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, SPECIAL,
 * INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER.
 *
 * Copyright Jennic Ltd 2005, 2006, 2007. All rights reserved
 *
 ****************************************************************************/

/****************************************************************************/
/***        Include files                                                 ***/
/****************************************************************************/
#include <jendefs.h>
#include <LedControl.h>
#include <AppHardwareApi.h>
#include <Utilities.h>
#include <JZ_Api.h>
#include <gdb.h>
#include "..\..\..\Chip\Common\Include\Printf.h"


#include "WSN_Profile.h"

/****************************************************************************/
/***        Macro Definitions                                             ***/
/****************************************************************************/
/* Timing values */
#define APP_TICK_PERIOD_ms			 500

/****************************************************************************/
/***        Type Definitions                                              ***/
/****************************************************************************/

/****************************************************************************/
/***        Local Function Prototypes                                     ***/
/****************************************************************************/
PRIVATE void vInit(void);
PRIVATE void vToggleLed(void *pvMsg, uint8 u8Dummy);
PRIVATE void vTxSerialDataFrame(uint16 u16NodeId,
                                uint16 u16Humidity,
                                uint16 u16Temperature,
                                uint16 u16BattVoltage);

/****************************************************************************/
/***        Exported Variables                                            ***/
/****************************************************************************/

/****************************************************************************/
/***        Local Variables                                               ***/
/****************************************************************************/
PRIVATE bool_t bNwkStarted = FALSE;
PRIVATE bool_t bAppTimerStarted = FALSE;

/****************************************************************************
 *
 * NAME: AppColdStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Initialises system and runs
 * main loop.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void AppColdStart(void)
{
	/* Debug hooks: include these regardless of whether debugging or not */
	HAL_GDB_INIT();
    HAL_BREAKPOINT();

	/* Set network information */
	JZS_sConfig.u32Channel = WSN_CHANNEL;
	JZS_sConfig.u16PanId   = WSN_PAN_ID;

    /* General initialisation */
    vInit();

    /* No return from the above function call */
}

/****************************************************************************
 *
 * NAME: AppWarmStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Simply jumps to AppColdStart
 * as, in this instance, application will never warm start.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void AppWarmStart(void)
{
    AppColdStart();
}

/****************************************************************************/
/***        Local Functions                                               ***/
/****************************************************************************/
/****************************************************************************
 *
 * NAME: vInit
 *
 * DESCRIPTION:
 * Initialises Zigbee stack and hardware. Final action is to start BOS, from
 * which there is no return. Subsequent application actions occur in the
 * functions defined above.
 *
 * RETURNS:
 * No return from this function
 *
 ****************************************************************************/
PRIVATE void vInit(void)
{

    /* Initialise Zigbee stack */
    JZS_u32InitSystem(TRUE);

    /* Set DIO for LEDs */
    vLedInitFfd();

    vLedControl(0,0);
    vLedControl(1,0);
    vLedControl(2,0);
    vLedControl(3,0);

    /* Intialise serial comms unless debug mode*/
    #ifndef GDB
        vUART_printInit();

    #endif

    /* Start BOS */
    (void)bBosRun(TRUE);

    /* No return from the above function call */
}

/****************************************************************************
 *
 * NAME: vTxSerialDataFrame
 *
 * DESCRIPTION:
 * Transmits node data (address and sensor readings) to host via serial port.
 *
 * PARAMETERS: Name           RW  Usage
 *             u16NodeId      R   Short address of node that generated the data
 *             u16Humidity    R   Reading from humidity sensor (%)
 *             u16Temperature R   Reading from temperature sensor (degrees C)
 *             u16BattVoltage R   ADC reading of supply voltage (mv)
 *
 ****************************************************************************/
PRIVATE void vTxSerialDataFrame(uint16 u16NodeId,
                                uint16 u16Humidity,
                                uint16 u16Temperature,
                                uint16 u16BattVoltage)
{
    #ifndef GDB
        vPrintf("\n\r\n\rAddress = %x", u16NodeId);
        vPrintf("\n\rHumidity = %d", u16Humidity);
        vPrintf("\n\rTemperature = %d", u16Temperature);
        vPrintf("\n\rVoltage = %d", u16BattVoltage);
	#endif
}

/****************************************************************************
 *
 * NAME: vToggleLed
 *
 * DESCRIPTION:
 * Gets called by a BOS timer. Toggles LED1 to indicate we are alive.
 *
 ****************************************************************************/
PRIVATE void vToggleLed(void *pvMsg, uint8 u8Dummy)
{
    uint8 u8Msg;
    uint8 u8TimerId;
    static bool_t bToggle;

	if (bToggle)
	{
        vLedControl(0,0);
	}
    else
	{
        vLedControl(0,1);
	}
    bToggle = !bToggle;

    (void)bBosCreateTimer(vToggleLed, &u8Msg, 0, (APP_TICK_PERIOD_ms / 10), &u8TimerId);
}

/****************************************************************************/
/***               Functions called by the stack                          ***/
/****************************************************************************/

/****************************************************************************
 *
 * NAME: JZA_vAppEventHandler
 *
 * DESCRIPTION:
 * Called regularly by the task scheduler. This function reads the hardware
 * event queue and processes the events therein. It is important that this
 * function exits after a relatively short time so that the other tasks are
 * not adversely affected.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -