📄 wsn_coordinator.c
字号:
/****************************************************************************
*
* MODULE: WSN - Coordinator
*
* COMPONENT: $RCSfile: WSN_Coordinator.c,v $
*
* VERSION: $Name: $
*
* REVISION: $Revision: 1.4 $
*
* DATED: $Date: 2006/12/11 10:38:48 $
*
* 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.
*
* LAST MODIFIED BY: $Author: imorr $
* $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. All rights reserved
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include <jendefs.h>
#include <LedControl.h>
#include <AppHardwareApi.h>
#include <Utilities.h>
#include <JZ_Api.h>
#include "serial.h"
#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)
{
/* 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);
/* Intialise serial comms */
vSerial_Init();
/* 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)
{
printf("\n\r\n\rAddress = %x", u16NodeId);
printf("\n\rHumidity = %d", u16Humidity);
printf("\n\rTemperature = %d", u16Temperature);
printf("\n\rVoltage = %d", u16BattVoltage);
}
/****************************************************************************
*
* 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.
*
****************************************************************************/
void JZA_vAppEventHandler(void)
{
uint8 u8Msg;
uint8 u8TimerId;
if (!bAppTimerStarted)
{
if (bNwkStarted)
{
bAppTimerStarted = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -