📄 prodtestcoord.c
字号:
/****************************************************************************
*
* MODULE: Demo coordinator code
*
* COMPONENT: $RCSfile: ProdTestCoord.c,v $
*
* VERSION: $Name: $
*
* REVISION: $Revision: 1.1 $
*
* DATED: $Date: 2007/06/19 07:15:20 $
*
* STATUS: $State: Exp $
*
* AUTHOR: CJG
*
* DESCRIPTION:
* Coordinator for demonstrator. Acts as time coordinator for up to four
* sensor endpoints and manages LCD panel and keys on central coordinator.
*
* LAST MODIFIED BY: $Author: cjg $
* $Modtime: $
*
****************************************************************************
*
* (c) Copyright 2005 JENNIC Ltd
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include "jendefs.h"
#include "LcdDriver.h"
#include "ALSdriver.h"
#include "HTSdriver.h"
#include "AppHardwareApi.h"
#include "LedControl.h"
#include "Button.h"
#include "Utilities.h"
#include "gdb.h"
#include "JennicLogo.h"
#include "JZ_Api.h"
#include "HomeDemoProfile.h"
#include "nwk.h"
#include "af.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
/* Block (time slice) values */
#define BLOCK_TIME_IN_32K_PERIODS 1600
#define BLOCK_MIN_RX 2
#define BLOCK_UPDATE (BLOCK_MIN_RX + DEMO_ENDPOINTS)
#define BLOCK_START_TEMP 13
#define BLOCK_READ_TEMP 15
#define BLOCK_START_HUMIDITY 16
#define BLOCK_READ_HUMIDITY 18
#define BLOCK_READ_LIGHT 19
#define MAX_BLOCKS 20
/* Control screen and alarm values */
#define FRAMES_MISSED_INDICATION 9
#define CHANNEL_MIN 11
#define CHANNEL_MAX 26
#define CHANNEL_RANGE (CHANNEL_MAX - CHANNEL_MIN + 1)
#define TEST_ENDPOINTS 4
#define TEST_SYNC_COUNT 20
/* Number of points in graph of previous values. Must be multiple of 2 */
#define DEMO_HISTORY_LEN 16
/* Number of endpoints in system */
#define DEMO_ENDPOINTS 4
#define DEMO_ENDPOINT_POSITIONS 4
#define HW_INT_Q_SIZE 8
#define HW_INT_Q_PTR_MASK 0x7
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
typedef enum
{
E_SENSOR_TEMP = 0,
E_SENSOR_HTS,
E_SENSOR_ALS,
DEMO_SENSOR_LIST_LEN
} teSensor;
/* Holds all stored data for a particular sensor for a node */
typedef struct
{
uint8 u8NowValue;
uint8 au8GraphData[DEMO_HISTORY_LEN];
} tsNodeElementData;
/* Holds all stored data for a node */
typedef struct
{
tsNodeElementData asNodeElementData[DEMO_SENSOR_LIST_LEN];
uint64 u64ExtAdr;
uint16 u16ShortAdr;
uint8 u8FramesMissed;
uint8 u8SwitchOn;
} tsNodeData;
/* System states with respect to screen display being shown */
typedef enum
{
E_STATE_SPLASH,
E_STATE_NETWORK,
E_STATE_NODE
} teState;
/* Button values */
typedef enum
{
E_KEY_0 = BUTTON_0_MASK,
E_KEY_1 = BUTTON_1_MASK,
E_KEY_2 = BUTTON_2_MASK,
E_KEY_3 = BUTTON_3_MASK,
} teKeyValues;
typedef struct
{
uint32 u32Device;
uint32 u32ItemBitmap;
} tsHwIntData;
/* All application data with scope within the entire file is kept here,
including all stored node data, GUI settings and current state */
typedef struct
{
struct
{
tsNodeData asNodeData[DEMO_ENDPOINTS];
uint8 u8AssociatedNodes;
} sNode;
struct
{
teSensor eCurrentSensor;
uint8 u8CurrentNode;
uint8 u8GraphPos;
uint8 u8Keys;
} sGui;
struct
{
teState eState;
uint32 u32ZigbeeStackVersion;
uint32 u32CalibratedTimeout;
uint8 u8TimeBlock;
uint8 u8Channel;
} sSystem;
/* Queue for hardware interrupts */
struct
{
tsHwIntData asHwIntData[HW_INT_Q_SIZE];
volatile uint8 u8ReadPtr;
volatile uint8 u8WritePtr;
} sQueue;
struct
{
bool_t bTestMode;
bool_t bSensorsTested;
uint8 au8SyncLoss[TEST_ENDPOINTS];
uint8 u8Count;
char acCommand[3];
uint8 u8CommandDigit;
} sTestData;
} tsDemoData;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
PRIVATE void vInitDemoSystem(void);
PRIVATE void vInitCoord(void);
PRIVATE void vSetTimer(void);
PRIVATE void vProcessCurrentTimeBlock(uint8 u8TimeBlock);
PRIVATE void vProcessKeys(uint8 *pu8Keys);
PRIVATE uint8 u8UpdateTimeBlock(uint8 u8TimeBlock);
PRIVATE void vProcessUpdateBlock(void);
PRIVATE void vSendData(uint16 u16Addr, uint8 u8Switch);
PRIVATE void vProcessSplashKeyPress(uint8 u8KeyMap);
PRIVATE void vProcessNetworkKeyPress(uint8 u8KeyMap);
PRIVATE void vProcessNodeKeyPress(uint8 u8KeyMap);
PRIVATE void vBuildNetworkScreen(void);
PRIVATE void vUpdateNetworkScreen(teSensor eSensor);
PRIVATE void vUpdateSplashScreen(void);
PRIVATE void vBuildNodeScreen(uint8 u8Node);
PRIVATE void vUpdateNodeScreen(uint8 u8Node);
PRIVATE void vLcdUpdateElement(tsNodeData *psNodeData, teSensor eSensor,
uint8 u8Row, uint8 u8Col, bool_t boShowInfo);
PRIVATE void vDrawGraph(uint8 *pu8GraphData, uint8 u8StartCol,
uint8 u8StartRow);
PRIVATE void vStringCopy(char *pcFrom,char *pcTo);
PRIVATE void vValToDec(char *pcOutString, uint8 u8Value, char *pcLabel);
PRIVATE void vAddDesc(void);
PRIVATE void vSendOnUart(const char *pcString);
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
/* File scope data */
PRIVATE tsDemoData sDemoData;
/* Row and column positions of info fields on LCD */
static const uint8 au8NodeLcdRow[DEMO_ENDPOINT_POSITIONS] = {0, 0, 3, 3};
static const uint8 au8NodeLcdCol[DEMO_ENDPOINT_POSITIONS] = {0, 64, 0, 64};
static const char *apcNodeNameList[DEMO_ENDPOINTS] = {
"Hall", "Bedroom", "Lounge", "Bathroom"};
/* Test messages */
const char acTestStart[] = "DCTS"; /* Demo Coord Test Start */
const char acStartConfigure[] = "DS"; /* Demo Coord Start */
const char acTemperatureTestPassed[] = "DCTP"; /* Demo Coord Temp Passed */
const char acHumidityTestPassed[] = "DCHP"; /* Demo Coord Humidity Passed*/
const char acLightTestPassed[] = "DCLP"; /* Demo Coord Light Passed */
const char acSensorTestsComplete[] = "DCSC"; /* Demo Coord Sensor Complete */
char acEndpointAssociated[] = "DCA "; /* Demo Coord Association */
char acAssocFail[] = "DCF "; /* Demo Coord Association Fail */
const char acAssocComplete[] = "DCAC"; /* Demo Coord Association Complete */
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
/****************************************************************************
*
* 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();
/* General initialisation: reset hardware, set some values in PIB */
JZS_sConfig.u32Channel = CHANNEL_DEFAULT;
JZS_sConfig.u16PanId = DEMO_PAN_ID;
JZS_sConfig.u16AppDataLength = 0;
vInitDemoSystem();
/* 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();
}
/****************************************************************************
*
* NAME: JZA_boAppStart
*
* DESCRIPTION:
* Called by Zigbee stack during initialisation. Sets up the profile
* information and starts the networking activity
*
* RETURNS:
* TRUE
*
****************************************************************************/
PUBLIC bool_t JZA_boAppStart(void)
{
/* Don't start stack yet - not needed now for JZA_vAppEventHandler to be
called, so delay start until user has selected a channel */
return TRUE;
}
/****************************************************************************
*
* 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.
*
****************************************************************************/
PUBLIC void JZA_vAppEventHandler(void)
{
tsHwIntData *psHwIntData;
/* Check queue for hardware interrupts, and process */
while (sDemoData.sQueue.u8WritePtr != sDemoData.sQueue.u8ReadPtr)
{
/* Get entry from queue */
psHwIntData = &sDemoData.sQueue.asHwIntData[sDemoData.sQueue.u8ReadPtr];
switch (psHwIntData->u32Device)
{
case E_AHI_DEVICE_SYSCTRL:
/* Check for wake timer */
if (psHwIntData->u32ItemBitmap & (1 << E_AHI_SYSCTRL_WK1))
{
/* Set the timer for the next interval */
vSetTimer();
/* Perform scheduler action */
vProcessCurrentTimeBlock(sDemoData.sSystem.u8TimeBlock);
/* Check keys */
vProcessKeys(&sDemoData.sGui.u8Keys);
/* Increment scheduler time block for next time */
sDemoData.sSystem.u8TimeBlock = u8UpdateTimeBlock(sDemoData.sSystem.u8TimeBlock);
}
break;
/* Check for anything arriving on UART: this is only used in test mode
on channel set screen to set channel and start running */
case E_AHI_DEVICE_UART0:
switch (psHwIntData->u32ItemBitmap & 0xff)
{
case E_AHI_UART_INT_RXDATA:
case E_AHI_UART_INT_TIMEOUT:
if (sDemoData.sTestData.u8CommandDigit < 3)
{
sDemoData.sTestData.acCommand[sDemoData.sTestData.u8CommandDigit]
= (char)(psHwIntData->u32ItemBitmap >> 8);
sDemoData.sTestData.u8CommandDigit++;
if (sDemoData.sTestData.u8CommandDigit == 3)
{
if ((sDemoData.sTestData.acCommand[0] == acStartConfigure[0])
&& (sDemoData.sTestData.acCommand[1] == acStartConfigure[1]))
{
uint8 u8Channel;
u8Channel = sDemoData.sTestData.acCommand[2] - 'A' + 1;
if ((u8Channel >= 11) && (u8Channel <= 26))
{
sDemoData.sTestData.bSensorsTested = FALSE;
sDemoData.sTestData.bTestMode = TRUE;
JZS_sConfig.u32Channel = u8Channel;
JZS_vStartStack();
sDemoData.sSystem.eState = E_STATE_NETWORK;
vBuildNetworkScreen();
}
}
}
}
break;
default:
break;
}
break;
default:
break;
}
/* Move read pointer forwards, wrapping around if necessary */
sDemoData.sQueue.u8ReadPtr = (sDemoData.sQueue.u8ReadPtr + 1) & HW_INT_Q_PTR_MASK;
}
}
/****************************************************************************
*
* NAME: JZA_vPeripheralEvent
*
* DESCRIPTION:
* Called when a hardware event causes an interrupt. This function is called
* from within the interrupt context so should be brief. In this case, the
* information is placed on a simple FIFO queue to be processed later.
*
* PARAMETERS: Name RW Usage
* u32Device R Peripheral generating interrupt
* u32ItemBitmap R Bitmap of interrupt sources within peripheral
*
****************************************************************************/
PUBLIC void JZA_vPeripheralEvent(uint32 u32Device, uint32 u32ItemBitmap)
{
tsHwIntData *psHwIntData;
uint8 u8WriteNextPtr;
/* Queue event for subsequent processing by JZ_vAppEventHandler */
u8WriteNextPtr = (sDemoData.sQueue.u8WritePtr + 1) & HW_INT_Q_PTR_MASK;
if (u8WriteNextPtr != sDemoData.sQueue.u8ReadPtr)
{
/* There is space on queue */
psHwIntData = &sDemoData.sQueue.asHwIntData[sDemoData.sQueue.u8WritePtr];
psHwIntData->u32Device = u32Device;
psHwIntData->u32ItemBitmap = u32ItemBitmap;
sDemoData.sQueue.u8WritePtr = u8WriteNextPtr;
}
/* If no space on queue, interrupt is silently discarded */
}
/****************************************************************************
*
* NAME: JZA_vAppDefineTasks
*
* DESCRIPTION:
* Called by Zigbee stack during initialisation to allow the application to
* initialise any tasks that it requires. This application requires none.
*
* RETURNS:
* void
*
****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -