?? network.c
字號(hào):
/****************************************************************************//*! *\MODULE Jenie Template * *\COMPONENT $RCSfile: Network.c,v $ * *\VERSION $Name: HEAD $ * *\REVISION $Revision: 1.5 $ * *\DATED $Date: 2008/03/26 15:29:42 $ * *\STATUS $State: Exp $ * *\AUTHOR Martin Looker * *\DESCRIPTION Network common tasks handling. * * This file provides code that is common to most Jenie applications for all * node types. The first set of * functions are equivalent to the standard Jenie callback functions and should * be called by those functions from the node type specific files, (Coordinator.c, * Router.c, EndDevice.c). * * \section Basic_Use Basic Use * * The typical sequence in is as follows: * * -# Call vNetwork_ConfigureNetwork() to set up the initial network settings from * vJenie_CbConfigureNetwork(). * -# Start or join the network by calling vNetwork_Init() from vJenie_CbInit(). * -# When the network is running bNetwork_Up() will return TRUE. *//*\CHANGE HISTORY * * $Log: Network.c,v $ * Revision 1.5 2008/03/26 15:29:42 mlook * Removed use of services, devices now send directly to coordinator. * * Revision 1.4 2007/11/21 16:11:28 mlook * JPI updates - completed * * Revision 1.3 2007/11/21 08:44:48 mlook * First stage of JPI update * * Revision 1.2 2007/11/20 16:21:42 mlook * Updated to recent Jenie template. * * * *\LAST MODIFIED BY $Author: mlook $ * **************************************************************************** * * 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 ***//****************************************************************************//* Jennic include files */#include <jendefs.h>#include <jenie.h>#include <JPI.h>#include <AppHardwareApi.h>#include <LedControl.h>#include <Printf.h>/* Standard library include files */#include <string.h>/* Debugging include files */#include <gdb.h>/* Local include files */#include "Network.h"#include "Sensor.h"/****************************************************************************//*** Macro Definitions ***//****************************************************************************//****************************************************************************//*** Type Definitions ***//****************************************************************************//****************************************************************************//*** Local Function Prototypes ***//****************************************************************************/#if NETWORK_DEBUGPRIVATE bool_t bNetwork_IsString (uint16, uint8 *);#endif/****************************************************************************//*** Exported Variables ***//****************************************************************************//****************************************************************************//*** Local Variables ***//****************************************************************************/PRIVATE teJenieDeviceType eDeviceType; /**< Device type */PRIVATE bool_t bNetworkUp; /**< Network is up */PRIVATE bool_t bUartUp; /**< Uart is open *//****************************************************************************//*** Local Constants ***//****************************************************************************//* Debugging strings */#if NETWORK_DEBUGPRIVATE const char aszDeviceType[][20] = { "COORDINATOR", "ROUTER", "END_DEVICE"};PRIVATE const char aszEventType[][20] = { "REG_SVC_RSP", "SVC_REQ_RSP", "POLL_CMPLT", "PACKET_SENT", "PACKET_FAILED", "NETWORK_UP", "CHILD_JOINED", "DATA", "DATA_TO_SERVICE", "DATA_ACK", "DATA_TO_SERVICE_ACK", "STACK_RESET", "CHILD_LEAVE", "CHILD_REJECTED"};PRIVATE const char aszStatusCode[][20] = { "SUCCESS", "DEFERRED", "ERR_UNKNOWN", "ERR_INVLD_PARAM", "ERR_STACK_RSRC", "ERR_STACK_BUSY"};#endif/****************************************************************************//*** Public network functions ***//****************************************************************************//**************************************************************************** * * NAME vNetwork_ConfigureNetwork *//*! *\DESCRIPTION Configures the network before the stack is initialised. * * This function performs network configuration before the stack is initialised. * * This function should be called from vJenie_CbConfigureNetwork() as it performs * the network configuration tasks common to all Jenie device types. * * This function is only called during a cold start. *//* RETURNS * None * ****************************************************************************/PUBLIC void vNetwork_ConfigureNetwork ( teJenieDeviceType eConfigDeviceType, /**< Type of device to run as */ uint8 u8ConfigMaxChildren, /**< Maximum child devices allowed */ bool_t bInitFfd) /**< Initialise full function devices flag */{ /* Debug hooks: include these regardless of whether debugging or not */ HAL_GDB_INIT(); HAL_BREAKPOINT(); /* Initialise and turn on LEDs */ if (bInitFfd) { vLedInitFfd(); vLedControl(2,FALSE); vLedControl(3,FALSE); } else { vLedInitRfd(); } vLedControl(0,TRUE); vLedControl(1,FALSE); /* Set network identification parameters */ gJenie_NetworkApplicationID = NETWORK_APPLICATION_ID; gJenie_PanID = NETWORK_PAN_ID; gJenie_Channel = NETWORK_CHANNEL; #if NETWORK_CHANNEL gJenie_ScanChannels = (1 << NETWORK_CHANNEL); #else gJenie_ScanChannels = NETWORK_SCAN_CHANNELS; #endif /* Note initialisation settings */ eDeviceType = eConfigDeviceType; /* Limit maximum children to the absolute maximum allowed (10) */ if (u8ConfigMaxChildren > 10) u8ConfigMaxChildren = 10; /* Don't allow any children for an end device */ if (eDeviceType == E_JENIE_END_DEVICE) u8ConfigMaxChildren = 0; /* Set up maximum children */ gJenie_MaxChildren = u8ConfigMaxChildren; /* Network is not up yet */ bNetworkUp = FALSE; bUartUp = FALSE;}/**************************************************************************** * * NAME vNetwork_Init *//*! *\DESCRIPTION Initialise the network and start the stack. * * Allows initialisation to take place and then starts the stack. * * This function should be called from vJenie_CbInit() as it performs * the network initialisation tasks common to all Jenie device types. * * This function called during both a cold and warm start. *//* RETURNS * None * ****************************************************************************/PUBLIC void vNetwork_Init ( bool_t bWarmStart, /**< Specifies if a warm start is taking place */ bool_t bInitUart) /**< Specifies if the UART should be opened for printf support */{ bool_t bUart; teJenieStatusCode eStatus; /* Note passed in uart setting */ bUart = bInitUart; /* Using GDB ? */ #ifdef GDB /* Override passed in UART setting to turn it off - reserved for GDB */ bUart = FALSE; #else /* Want to run network debugging ? */ #if NETWORK_DEBUG /* Override passed in UART setting to turn it on - needed for debugging */ bUart = TRUE; #endif #endif /* Uart not yet up */ bUartUp = FALSE; /* Want to open UART ? */ if (bUart) { /* Open UART */ vUART_printInit(); /* Note it is open */ bUartUp = TRUE; } /* Initialise sensor */ vSensor_Init(); /* Enable wake timer 1 with interrupt */ vJPI_WakeTimerEnable(E_JPI_WAKE_TIMER_1, TRUE); /* Run the timer for 100ms */ vJPI_WakeTimerStart(E_JPI_WAKE_TIMER_1, 3200); /* Update LED */ vLedControl(1,bNetworkUp); /* Start the stack running for our device type */ eStatus = eJenie_Start(eDeviceType); #if NETWORK_DEBUG if (bUartUp) { if (! bWarmStart) { vPrintf("\n------------------------------\n"); vPrintf("Version(%d)\n", NETWORK_VERSION); vPrintf("ApplicationId(%x)\n", gJenie_NetworkApplicationID); vPrintf("PanId(%x)\n", gJenie_PanID); vPrintf("Channel(%d)\n", gJenie_Channel); vPrintf("MaxChildren(%d)\n", gJenie_MaxChildren); vPrintf("DeviceType(%s)\n", aszDeviceType[eDeviceType]); } vPrintf("vNetwork_Init(%d, %d)\n", bWarmStart, bInitUart); vPrintf("eJenie_Start(%s) = %s\n", aszDeviceType[eDeviceType], aszStatusCode[eStatus]); } #endif}/**************************************************************************** * * NAME: vNetwork_Main *//*! *\DESCRIPTION Main application task, called repeatedly by the stack. * * This function should be called from vJenie_CbMain() as it performs * the network tasks common to all Jenie device types. * * This function should be non-blocking. *//* RETURNS * None * ****************************************************************************/PUBLIC void vNetwork_Main (void){}/**************************************************************************** * * NAME vNetwork_StackMgmtEvent *//*! *\DESCRIPTION Called when stack management event has occurred. * * This function should be called from vJenie_CbStackMgmtEvent() as it performs * the network management tasks common to all Jenie device types. *//* RETURNS * None * ****************************************************************************/PUBLIC void vNetwork_StackMgmtEvent ( teEventType eEventType, /**< Type of stack management event received */ void *pvEventPrim) /**< Pointer to event primitive */{ teJenieStatusCode eStatus; /* Which event has occurred ? */ switch (eEventType) { /* Network up ? */ case E_JENIE_NETWORK_UP: { /* Network debugging */ #if NETWORK_DEBUG if (bUartUp) { /* Get pointer to correct primitive structure */ tsNwkStartUp *psNwkStartUp = (tsNwkStartUp *) pvEventPrim; /* Output to UART */ vPrintf("vNetwork_StackMgmtEvent(NETWORK_UP, %x:%x, %x:%x, %d, %x, %d)\n", (uint32)(psNwkStartUp->u64ParentAddress >> 32), (uint32)(psNwkStartUp->u64ParentAddress & 0xFFFFFFFF), (uint32)(psNwkStartUp->u64LocalAddress >> 32), (uint32)(psNwkStartUp->u64LocalAddress & 0xFFFFFFFF), psNwkStartUp->u16Depth, psNwkStartUp->u16PanID, psNwkStartUp->u8Channel); } #endif /* Note network is now up */ bNetworkUp = TRUE; /* Update LED */ vLedControl(1,bNetworkUp); /* End device ? */ if (eDeviceType == E_JENIE_END_DEVICE) { /* Don't allow devices to join to us */ eStatus = eJenie_SetPermitJoin(FALSE);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -