/**************************************************************************************************
Filename: topologyMesh.c
Revised: $Date: 2009-03-18 15:56:27 -0700 (Wed, 18 Mar 2009) $
Revision: $Revision: 19453 $
Description: Sample Application (no Profile).
Copyright 2007 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED �AS IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/
/*********************************************************************
This application isn't intended to do anything useful, it is
intended to be a simple example of an application's structure.
This application sends it's messages either as broadcast or
broadcast filtered group messages. The other (more normal)
message addressing is unicast. Most of the other sample
applications are written to support the unicast message model.
Key control:
SW1: Sends a flash command to all devices in Group 1.
SW2: Adds/Removes (toggles) this device in and out
of Group 1. This will enable and disable the
reception of the flash command.
*********************************************************************/
/*********************************************************************
* INCLUDES
*/
#include <stdio.h>
#include "OSAL.h"
#include "ZGlobals.h"
#include "AF.h"
#include "aps_groups.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "protocol.h"
#include "mac_radio_defs.h"
#include "topologyMesh.h"
#include "topologyMeshHW.h"
#include "OnBoard.h"
#include "sensor.h"
/* HAL */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_defs.h"
#include "sht.c"
/*********************************************************************
* MACROS
*/
/*********************************************************************
* CONSTANTS
*/
#if !defined( SERIAL_PORT )
#define SERIAL_PORT 0
#endif
#if !defined( SERIAL_BAUD )
#define SERIAL_BAUD HAL_UART_BR_9600
//#define SERIAL_BAUD HAL_UART_BR_115200
#endif
// When the Rx buf space is less than this threshold, invoke the Rx callback.
#if !defined( SERIAL_THRESH )
#define SERIAL_THRESH 64
#endif
#if !defined( SERIAL_RX_SZ )
#define SERIAL_RX_SZ 128
#endif
#if !defined( SERIAL_TX_SZ )
#define SERIAL_TX_SZ 128
#endif
// Millisecs of idle time after a byte is received before invoking Rx callback.
#if !defined( SERIAL_IDLE )
#define SERIAL_IDLE 6
#endif
// Loopback Rx bytes to Tx for throughput testing.
#if !defined( SERIAL_LOOPBACK )
#define SERIAL_LOOPBACK FALSE
#endif
// This is the max byte count per OTA message.
#if !defined( SERIAL_TX_MAX )
#define SERIAL_TX_MAX 80
#endif
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
// This list should be filled with Application specific Cluster IDs.
const cId_t topologyMesh_ClusterList[TOPOLOGYMESH_MAX_CLUSTERS] =
{
TOPOLOGYMESH_PERIODIC_CLUSTERID,
TOPOLOGYMESH_FLASH_CLUSTERID
};
const SimpleDescriptionFormat_t topologyMesh_SimpleDesc =
{
TOPOLOGYMESH_ENDPOINT, // int Endpoint;
TOPOLOGYMESH_PROFID, // uint16 AppProfId[2];
TOPOLOGYMESH_DEVICEID, // uint16 AppDeviceId[2];
TOPOLOGYMESH_DEVICE_VERSION, // int AppDevVer:4;
TOPOLOGYMESH_FLAGS, // int AppFlags:4;
TOPOLOGYMESH_MAX_CLUSTERS, // uint8 AppNumInClusters;
(cId_t *)topologyMesh_ClusterList, // uint8 *pAppInClusterList;
TOPOLOGYMESH_MAX_CLUSTERS, // uint8 AppNumInClusters;
(cId_t *)topologyMesh_ClusterList // uint8 *pAppInClusterList;
};
// This is the Endpoint/Interface description. It is defined here, but
// filled-in in topologyMesh_Init(). Another way to go would be to fill
// in the structure here and make it a "const" (in code space). The
// way it's defined in this sample app it is define in RAM.
endPointDesc_t topologyMesh_epDesc;
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
uint8 topologyMesh_TaskID; // Task ID for internal task/event processing
// This variable will be received when
// topologyMesh_Init() is called.
devStates_t topologyMesh_NwkState;
uint8 topologyMesh_TransID; // This is the unique message ID (counter)
afAddrType_t topologyMesh_Periodic_DstAddr;
afAddrType_t topologyMesh_Flash_DstAddr;
aps_Group_t topologyMesh_Group;
uint8 topologyMeshPeriodicCounter = 0;
uint8 topologyMeshFlashCounter = 0;
uint8 Serial_TxSeq;
uint8 Serial_TxBuf[SERIAL_TX_MAX+1];
uint8 Serial_TxLen;
/*****************************
store reverse control packet command
******************************/
uint8 inCommingData[RECONTROL_COMMAND_DATA_LEN];
uint16 sensorTimeout = 5000;
uint8 txPower = 0xD5;
/********************************
the buff store the packet which carries
the sensor data come from node
*/
uint8 sensorBuff[SENDATA_TOGATEWAY_WITHOUTDATA+SENSOR_DATA_MAX_LEN];
/*********************************************************************
* LOCAL FUNCTIONS
*/
void topologyMesh_HandleKeys( uint8 shift, uint8 keys );
void topologyMesh_MessageMSGCB( afIncomingMSGPacket_t *pckt );
void topologyMesh_SendPeriodicMessage( void );
void topologyMesh_SendFlashMessage( uint16 flashTime );
void SerialCallBack(uint8 port, uint8 event);
void SerialRxProcess( void );
void ReControlPacketProcess(uint8 *data, uint8 len);
void ReControlCommandProcess(uint8 * data, uint8 dataLen);
void ReConLedCmdPro(uint8 command);
void ReConTxPowerCmdPro(uint8 command);
void ReConTimerCmdPro(uint8 command);
/**************************************