#ifndef __TYPEDEFINE_H__
#define __TYPEDEFINE_H__
/*--------------------------------------------------------------------------------------
*  @file     TypeDefine.h
*  @author   ZhangJing
*  @version  base on stm32f0x   
*  @date     2015.09.11
*  @brief    公共变量、函数定义
---------------------------------------------------------------------------------------*/

#include "stdint.h"
#include "stm32f10x.h"

//类型转换
typedef unsigned char      bool;

#define  True  1						//真
#define  False 0						//假

//#define OLD_LCD						1

#define TASK_FLAG_CLEAR			0//任务标志清除
#define TASK_FLAG_SET				1//任务标志置位
#define TASK_FLAG_WAIT			2//任务等待标志
#define TASK_FLAG_OVERTIME	3	//任务超时标志
#define TASK_FLAG_FAIL			4	//任务执行失败
#define TASK_FLAG_WCLEAR		5 //等待清除
#define TASK_FLAG_WSET			6 //等待置位

#define	SendFailure				0//发送失败
#define SendSuceed				1//发送成功
#define SendWait				3//发送等待

#define HornOFF					0//关闭喇叭声音
#define HornWarningTone 		1//单生提示音
#define HornAlarmSound			2//报警音
#define HornMaxSound 			3//最大音量
#define HornSelence				4//静音
#define HornLowPriWarning		5//低优先级报警


#define LED_STATE_OFF			0//LED关
#define LED_STATE_ON			1//LED开

#define ENGINEERINGMODE_OFF		1		//工程模式关
#define ENGINEERINGMODE_ON		0		//工程模式开

#define MOTOR_WORK_OFF			0	//电机工作停止
#define MOTOR_TRIGGER_OFF		1	//电机停止触发
#define MOTOR_WORK_ON				2	//电机工作启动
#define MOTOR_TRIGGER_ON		3	//电机启动触发
#define MOTOR_WORK_WAIT			0Xff	//电机启动等待

#define ONE_HOUR_TIMER						3600000//1小时计时
#define ONE_SECOND_TIMER					1000//1s计时  
#define TWO_SECOND_TIMER					2000//2s计时
#define TWO_FIVE_SECOND_TIMER			2500//2.5s计时
#define TRI_SECOND_TIMER					3000//3s计时
#define FOUR_SECOND_TIMER					4000//4s计时
#define FIVE_SECOND_TIMER					5000//5s计时
#define TEN_SECOND_TIMER					10000//10s计时
#define FIFTEEN_SECOND_TIMER			15000//15s计时
#define TWENTY_SECOND_TIMER				20000//20s计时
#define THIRTY_SECOND_TIMER				30000//30s计时
#define FIFTY_MSEC_TIMER						50//50ms计时
#define ONE_MSEC_TIMER						100//100ms计时
#define ONE_TWO_FIVE_MSEC_TIMER		125//125ms计时
#define TWO_MSEC_TIMER						200//200ms计时
#define THREE_MSEC_TIMER					300//300ms计时
#define HALF_SECOND_TIMER					500//500ms计时
#define EnterDelay_TIMER					500//
#define SEVEN_MSECOND_TIMER					700//500ms计时
#define TWO_MINUTE_TIMER				  120000//2分钟
#define THREE_MINUTE_TIMER				180000//3分钟
#define FIVE_MINUTE_TIMER               300000//5分钟计时
#define TWENTY_MINUTE_TIMER				1200000//20分钟 测试
#define THIRTY_MINUTE_TIMER				1800000//30分钟
#define FORTY_MINUTE_TIMER				2400000//40分钟

#define TASK_TIMER_XMIT_RTD				60000//1分钟
//#define TASK_TIMER_PRES_CONV			100//100ms转换一次压力
#define TASK_TIMER_PRES_CONV			20//100ms转换一次压力

#define DISP_TIME_AUTO_S_JUMP			3000//页面自动短跳转时间3s
#define DISP_TIME_AUTO_JUMP				5000//页面自动跳转时间5s
#define DISP_TIME_LOCK_JUMP				30000//锁屏跳转时间30s
#define KEY_TIMER_SCAN						150//消抖时间100ms
#define KEY_TIMER_LONGPRESS				3000//按键长按时间3s
#define KEY_TIMER_SHORTEST				150//消抖时间100ms

#define SYS_RUN_TEST_TIMER				5000//系统运行前测试时间5s
#define ALARM_COLLECT_TIMER				1000//报警采集时间10s?
#define MOTOR_COLLECT_TIMER				1800//电机信号采集计时1.8s
#define MOTOR_TESTSELF_TIMER			8400//电机自检计时8.4s		4s改成8.4s

#define ZIGBEE_RECV_LEN						32
#define USART_PDU_START						0xAA
#define USART_PDU_END							0x55

#define	HOSPITALNO_SELECTED				1		//住院号被选择
#define	BEDNO_SELECTED						2		//床号被选择

#define SYS_PASSWORD_DEFAULT			520//系统万能密码

// #define BATTERY_VOLT_LIMIT1				43//3.65V
// #define BATTERY_VOLT_LIMIT2				57//3.85V 60-3.9V
// #define BATTERY_VOLT_LIMIT3				80//4.2V
#define BATTERY_VOLT_LIMIT1				40//3.7V-47 3.3V-20/40
#define BATTERY_VOLT_LIMIT2				87//4.0V/67
#define BATTERY_VOLT_LIMIT3				100//4.3V/87

#define KEY_QTY_SHORTEST					1//按键短按次数
#define KEY_QTY_SHORT							10//判定短按范围
#define KEY_QTY_NORMAL						5//正常按一次的次数
#define KEY_QTY_LONGPRESS					13//15//20//30//按键长按次数

#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 
#define GPIOB_ODR_Addr    (GPIOB_BASE+12) //0x40010C0C 
#define PBout(n)   BIT_ADDR(GPIOB_ODR_Addr,n)  //输出 
#define RLED	PBout(8)
#define R_LED_ON   GPIO_SetBits(GPIOB,GPIO_Pin_8  );	
#define R_LED_OFF  GPIO_ResetBits(GPIOB,GPIO_Pin_8  );
#define G_LED_ON   GPIO_SetBits(GPIOB,GPIO_Pin_1  );	
#define G_LED_OFF  GPIO_ResetBits(GPIOB,GPIO_Pin_1  );
#define Y_LED_ON   GPIO_SetBits(GPIOB,GPIO_Pin_9  );	
#define Y_LED_OFF  GPIO_ResetBits(GPIOB,GPIO_Pin_9  );
extern uint16_t	G_Led_Time ;//绿色指示灯点亮时间
extern uint16_t	Y_Led_Time ;//黄色指示灯点亮时间
/* KEY Scan Flag structure */
typedef enum
{
	emSpeakerNoneWork = 0,			//蜂鸣器无动作
	emSpeakerWorkStep1 = 1,			//蜂鸣器工作第一步
	emSpeakerWorkStep2 = 2,			//蜂鸣器工作第二步
	emSpeakerWorkStep3 = 3,			//蜂鸣器工作第三步
	emSpeakerWorkStep4 = 4,			//蜂鸣器工作第四步
	emSpeakerWorkStep5 = 5,			//蜂鸣器工作第五步
	emSpeakerWorkStart = 0xfe,	//蜂鸣器工作开始
	emSpeakerWorkDone = 0xff,		//蜂鸣器工作完成
}SpeakerWorkType;

/* KEY Type structure */
typedef enum
{
	emKeyActionOff = 0,	//按键动作-抬起
	emKeyActionOn = 1,	//按键动作-按下
	emKyeActionScanSet = 2,//按键动作-消抖置位
	emKeyActionWait = 0xff,
}KeyActionType;

typedef struct
{
	KeyActionType	keyEnter;			//设置/确认键
	KeyActionType	keyRunPause;	    //运行停止键
	KeyActionType	keyPlus;			//加号键
	KeyActionType	keyMinus;			//负号键
	KeyActionType	keyPower;			//电源键
	KeyActionType	keyAirout;		    //排气/呼叫按键
	KeyActionType	keyPS;				//返回键/静音按键
	KeyActionType keyPCA;				//PCA键
} KeyTypeFrame;

/* KEY Scan Flag structure */
typedef enum
{
	emKeyflagNonePress = 0,			//无按下标志
	emKeyflagShortPress = 1,		//短按下标志
	emKeyflagLongPress = 2,			//长按下标志
	emKeyflagShortRelease = 3,	//短按释放标志
	emKeyflagLongRelease = 4,		//长按释放标志
	emKeyflagMiddlePress = 5,		//中长按下标志
}KeyFlagType;

typedef struct
{
	KeyFlagType	keyEnter;			//进入键
	KeyFlagType	keyRunPause;	//运行停止键
	KeyFlagType	keyPlus;			//加号键
	KeyFlagType	keyMinus;			//负号键
	KeyFlagType	keyPower;			//电源键
	KeyFlagType	keyAirout;		//排气/静音键
	KeyFlagType	keyPS;				//返回键
	KeyFlagType keyPCA;				//PCA键
} KeyFlagFrame;

/* KEY Scan QTY structure */
typedef struct
{
	uint8_t	keyEnter;			//进入键
	uint8_t	keyRunPause;	//运行停止键
	uint8_t	keyPlus;			//加号键
	uint8_t	keyMinus;			//负号键
	uint8_t	keyPower;			//电源键
	uint8_t	keyAirout;		//排气键
	uint8_t	keyPS;				//返回键
	uint8_t keyPCA;				//PCA键
} KeyScanQtyFrame;

/* Task Scheduler structure */
typedef struct
{
	uint8_t initFinishFlag;			    //上电初始化完成标志
	uint8_t	zigbeeRecvFlag;			    //zigbee接收标志
	uint8_t	zigbeeXmitFlag;			    //zigbee发送标志
	uint8_t	zigbeeETXmitFlag;		    //zigbee评价上传标志
	uint8_t zigbeeComReadFlag;	        //zigbee命令读取
	uint8_t zigbeeInNetFlag;	      	//zigbee是否在网络内状态标志：0 无网络 1 有网络
	uint8_t	historyRequestFlag;         //历史数据请求标志
	uint8_t	historyReponseFlag;         //历史数据响应标志
	uint8_t	pressureConvertFlag;        //压力传感器转换标志
	uint8_t	forceConvertFlag;		    //触力传感器转换标志 0：转换 1：读取
	uint8_t fromSlaveRecvFlag;	        //从机数据接收标志
	uint8_t	toSlaveXmitFlag;		    //从机数据发送标志
	uint8_t motorRunFlag;				//电机运行标志
	uint8_t	motorStopFlag;			    //电机停止标志
	uint8_t motorSelfTestFlag;	        //电机自检标志
	uint8_t	ipnutFlag;					//输注标志
	uint8_t timeReadFlag;				//时间读取标志
	uint8_t lockDispFlag;				//锁屏标志
	uint8_t lockTimeFlag;				//锁时标志
	uint8_t SuperadditionFlag;	        //追加量模式标志
	uint8_t hostXmitFlag;				//主芯片发送标志
	uint8_t unlockPasswordFlag;	        //解锁标志
	uint8_t rtdUpdateFlag;			    //实时数据更新标志
	uint8_t	speakerFlag;				//蜂鸣器标志	
	uint8_t silenceFlag;				//静音标志
	uint8_t pcaLockFlag;				//PCA锁时标志 
	uint8_t	pcaCountDispFlag;		    //pca无效次数显示标志
	uint8_t	pcaCountFlashFlag;		    //pca无效次数闪烁标志
	uint8_t pcaLockTimeFlag;		    //pca锁时次数显示标志
	uint8_t batLowPrepareFlag;	        //电池电压低预报标志
	uint8_t autoPowerOffFlag;		    //自动关机标志
	uint8_t sysPowerOffFlag;		    //系统关机标志
	uint8_t callFunctionFlag;		    //呼叫功能标志
	uint8_t lcdBlackFlag;				//LCD背光标志
	uint8_t lcdFlashFlag;				//LCD闪烁标志
	uint8_t lcdFlashFlag1;				//LCD闪烁标志
	uint8_t lcdBlackFlashFlag;	        //LCD背光闪烁标志
	uint8_t sysStandbyFlag;			    //系统休眠标志
	uint8_t limitJudgeFlag;			    //极限量判断标志
	uint8_t sensorPWHallFlag;		    //主芯片低功耗标志，传感器电源控制-霍尔
	uint8_t sensorPWPressureFlag;	    //主芯片低功耗标志，传感器电源控制-压力传感器
	uint8_t sensorPWBatteryFlag;	    //主芯片低功耗标志，传感器电源控制-电池电压
	uint8_t testDispFlag;				//测试显示标志
	uint8_t batteryVoltHeaderFlag;      //电池电压标志
	uint8_t PCAOneTimeFlag;			    //第一次PCA按压
	uint8_t IrregularShutdownFlag;	    //非正常关机标志
    uint8_t NoActionHintFlag;           //参数设置界面30未操作提示标志
    uint8_t JamSelfcheckingFlag;        //堵塞自检标志
    uint8_t PasswordTimeOverFlag;       //密码锁时解除标志
	uint8_t LimitBeginsTime;	//极限计时开始	
	uint8_t StartToRunDontSend;			//运行长数据报第一条数据未发送成功标志	
	uint8_t EnterDelayFlag;				//输注参数长按Enter按键快速循环标志
	uint8_t HistoryDontSetFlag;			//住院号未设置标志
	uint8_t AirOutFlag;					//排气标志
	uint8_t AlarmInitFlag;				//报警初始化标志
	uint8_t PCATimerFlashFlag;			//PCA锁时闪烁标志
	uint8_t PCATimerFlashFlag1;			//允许PCA锁时闪烁标志
	uint8_t LcdLogoFlag;				//lcd屏幕第一排标志上锁、暂停消失标志
	uint8_t MqttSendFlag;   //mqtt发送标志 add by wulianwei
	uint8_t MqttReSendFlag;   //mqtt重发送标志 add by wulianwei
	uint8_t ModuleInitFlag;   //模块初始化 add by wulianwei
	uint8_t NET_ONLINE_FLAG;     //网络在线标志  add by wulianwei
	
} TaskSchedulerFlagFrame;			

/* Task Timer structure */
typedef struct
{
	uint32_t	delayTimer;		        //延时定时器
	uint32_t 	EnterDelayTimer;		//Enter按键长按延时函数
	uint32_t	rtdXmitTimer;	        //实时数据发送定时	
	uint32_t	pcaLockTimer;	        //PCA锁时时长
	uint16_t	initFinishTimer;        //初始化定时-系统运行超过3s后进入稳定工作状态，初始化完成
	uint16_t	pressureConvertTimer;   //压力传感器转换定时
	uint16_t	timeReadTimer;	        //时间读取定时	
	uint16_t	dispAutoJumpTimer;	    //LCD页面自动跳转定时
	uint16_t	lockDispTimer;          //锁屏定时时间
	uint16_t	speakerTimer;           //蜂鸣器响声定时
	uint16_t	speakerWaitTimer;       //蜂鸣器等待下次响定时	
	uint32_t	totalDoseOneHourTimer;  //总输注量1小时计时
	uint16_t	sysRunTestTimer;        //系统开始运行前测试计时
	uint16_t	alarmCollectTimer;      //报警采集时间
	uint16_t	motorSignalCollectTimer;//电机信号采集计时	
	uint32_t	motorStopTimer;         //电机停止计时
	uint16_t	motorSelfTestTimer;     //电机自检时间
	uint16_t	hostXmitTimer;          //主芯片发送给从芯片数据计时
	uint32_t	lockPassWordTimer;      //锁定密码页计时
	uint16_t	universalTimer;     	//通用计时，可随意设置值
	uint16_t	pcaCountsDispTimer;     //PCA次数显示计时
	uint16_t	pcaCountsFlashTimer;    //PCA次数闪烁计时
	uint16_t	pcaLockTimeDispTimer;   //PCA锁时次数显示计时
	uint16_t	batLowPrepareDispTimer; //电池低压预报显示计时
	uint16_t	alarmLCDFlashTimer;     //报警闪屏计时
	uint32_t	autoPowerOffTimer;      //自动关机计时	
	uint16_t	lcdBlackCloseTimer;     //LCD背光关闭计时
	uint16_t	sysStandbyTimer;        //系统休眠计时
	uint16_t	hostPowerSaveTimer;     //主芯片节能计时
	uint16_t	batteryVoltTimer;       //电池电压采集计时
	uint8_t		enterKeyScanTimer;      //enter key 扫描时间
	uint8_t		runPauseKeyScanTimer;   //run/pause key 扫描时间
	uint8_t		psKeyScanTimer;         //密码/静音键 扫描时间
	uint8_t		plusKeyScanTimer;       //加号键 扫描时间
	uint8_t		minusKeyScanTimer;      //负号键 扫描时间
	uint8_t		pcaKeyScanTimer;        //PCA键 扫描时间
	uint8_t		powerKeyScanTimer;      //电源键扫描时间
	uint8_t		airoutKeyScanTimer;     //Airout键扫描时间
	uint32_t    pcaOneHourTimer;        //PCA一小时锁时
    uint32_t    NoActionHintTimer;      //参数设置界面30min计时
    uint32_t    JamSelfcheckingTimer;   //堵塞自检5min计时
	uint16_t	PainAssessmentUploadTimer;//疼痛评价确认上传成功时间，假时间，
	uint32_t	ModuleInitTimer;	        //模块初始化间隔时间 add by wulianwei
	uint32_t	MQTTSendTimer;	        //模块初始化间隔时间 add by wulianwei
	uint32_t	MQTTReSendTimer;	        //重发等地时间 add by wulianwei
} TaskSchedulerTimerFrame;

typedef struct
{
	uint8_t		modifyInfoType;	        //修改信息的类型 1住院号 2床号
	uint16_t	sickroom;				//病区3位
	uint16_t	bedNO;					//床号3位
	uint64_t	hospitalNO;			    //住院号10位
}VerifyInfoSetFrame;

typedef enum
{
	FirstEnter = 1, //页面首次运行
	Update = 2,     //页面数据更新运行
}PictureEnterType;

typedef enum
{
	FirstRun = 1,   //首次运行
	MainRun = 2,    //主页运行
	PCARun = 3,     //PCA运行
	Pause = 4,      //暂停
	Finsh = 5,      //输液完成
	Airout = 6,     //排气
	Poweroff = 7,   //关机
	Poweron = 8,    //开机
	StartWork = 9,  //在开机了还没到确认信息处算开机工作状态
	StandBy = 10,   //待机状态	
	Alarm = 11,     //报警状态
	SelfTest = 12,  //自检状态
	WaitState = 0xff,//等待状态
}RunStateType;

typedef enum
{
	Year = 1,   //年
	Month = 2,  //月
	Date = 3,   //日
	Hour = 4,   //时
	Minute = 5, //分
}SetTimeType;

typedef enum
{
	TotalDose = 1,      //总量
	FirstDose = 2,      //首次量
	continueDose = 3,   //持续运行
	Superaddition = 4,  //追加量
	LockTime = 5,       //锁时
	LimitDose = 6,      //极限量
	continueDose2 = 7,  //持续运行2
	Superaddition2 = 8, //追加量2
	LockTime2 = 9,      //锁时2
	LimitDose2 = 10,    //极限量2
}ParamType;

typedef enum
{
	Pruritus = 1,       //瘙痒
	RASS = 2,           //镇静评分
	PONV = 3,           //恶心呕吐
	LimbMyodynamia = 4, //四肢肌力
	PainEvaluate = 5,   //疼痛评价
	VerifyEvaluate = 6,//确认评价	
	LeftArm = 7,//左上肢
	RightArm = 8,//右上肢
	LeftLeg = 9,//左下肢
	RightLeg = 10,//右下肢
	Static = 11,//静止
	Activity = 12,//活动
	CACSI = 13,//满意度
	Valuer = 14,//评价人
	VerifyUpload = 15,//上传确认
	Uploading = 16,//上传中
	UploadFinshed	= 17,//已上传完成
	UploadFall = 18,//上传失败
}EvaluateTransfuseType;

typedef struct
{
	ParamType emModifyParam;
	uint8_t		deviceID[16];			//设备ID
	uint8_t		password[3];			//密码
	uint8_t		pwmSetValue[4];		//pwm占空比设置值
	uint8_t		sickroom[3];			//病区3位
	uint8_t		bedNO[3];					//床号3位
	uint8_t		hospitalNO[10];		//住院号10位
	uint16_t	totalDose;				//总量
	uint16_t	firstDose;				//首次量
	uint16_t	continueDose1;		//持续量(第一次输注参数)
	uint16_t	superaddition1;		//追加量(第一次输注参数)
	uint16_t	lockTime1;				//锁时(第一次输注参数)
	uint16_t	limitDose1;				//极限量(第一次输注参数)
	uint16_t	continueDose2;		//持续量(第二次输注参数)
	uint16_t	superaddition2;		//追加量(第二次输注参数)
	uint16_t	lockTime2;				//锁时(第二次输注参数)
	uint16_t	limitDose2;				//极限量(第二次输注参数)
}SetParamFrame;

typedef struct
{
	uint16_t	pwmSetValue;			//pwm占空比设置值
	uint16_t	totalDose;				//总量
	uint16_t	firstDose;				//首次量
	uint16_t	continueDose;			//持续量
	uint16_t	limitDose;				//极限量
	uint16_t	superaddition;		//追加量
	uint16_t	lockTime;					//锁时
}RunParamFrame;//运行参数

typedef struct
{	
	uint16_t	airoutValue;			//排气量
// 	uint16_t	totalDose;				//总量
 	uint16_t	firstDose;				//首次量
	uint16_t	continueDose;			//持续量
	uint16_t	superaddition;		//追加量
	uint16_t	lockTime;					//锁时
	uint16_t	limitDose;				//极限量
	uint16_t	pressureF;				//压力值
	uint16_t	pressure;					//压强值
	uint16_t	pressureF2;				//压力值
	uint16_t	pressure2;				//压强值
	uint16_t	batteryVolt;			//电池电压值
	uint16_t	hall1Counter;			//霍尔1计数器，当电机转两圈时数值+2，电机转动一圈是0.05ml
	uint16_t	hall2Counter;			//霍尔2计数器，当电机转两圈时数值+4，电机转动一圈是0.05ml
	uint16_t	preHall1;					//前一次霍尔1计数值
	uint16_t	preHall2;					//前一次霍尔2计数值
	uint16_t	motorSelfTestCount;//电机自检计数
	uint16_t	surplusDose;			//剩余量
	uint16_t	selfContolDose;		//自控量
	uint16_t	inputDose;				//已输入量
	uint16_t	inputLimitDose;		//已输入极限量
	uint16_t	validCount;				//有效次数
	uint16_t	invalidCount;			//无效次数
	uint8_t		statePOST;				//开机自检状态 power on self test
	RunStateType	stateRun;			//运行状态
	RunStateType	ctlSlaveRun;	//控制从机运行状态
	uint8_t		statePause;				//暂停状态
	uint64_t	deviceID;					//设备ID
	uint32_t	InputTotalDose;		//已输入总量
	uint8_t 	infusionMode; 		//实时输注状态（2017.7.22）
}RTDFrame;//实时数据

typedef struct
{	
	uint16_t year; //年		
	uint8_t	month; //月
	uint8_t	date;  //日
	uint8_t week;  //周
	uint8_t	hour;  //时
	uint8_t	minute;//分
	uint8_t seconds;//秒
}TimeFrame;

typedef struct
{
	uint8_t		alarmTimeMonth;//报警时间-月
	uint8_t		alarmTimeDate;//报警时间-日
	uint8_t		alarmTimeHour;//报警时间-时
	uint8_t		alarmTimeMinute;//报警时间-分		
	uint8_t		alarmType;//报警类型 0：无报警	1：机械报警		2：堵塞报警		3：极限值
											//4：气泡或无液		5：未装药盒		6：电池电量		7：管道脱落	  8：输注结束
}AlarmFrame;

typedef struct
{
	uint8_t pruritus;//瘙痒
	uint8_t RASS;//镇静评分
	uint8_t	PONV;//恶心呕吐
	uint8_t LeftArm;//左上肢
	uint8_t RightArm;//右上肢
	uint8_t LeftLeg;//左下肢
	uint8_t RightLeg;//右下肢
	uint8_t Static;//静止
	uint8_t Activity;//活动
	uint8_t CACSI;//满意度
	uint8_t Valuer;//评价人
}EvaluateTransfuseFrame;

typedef enum
{
	DeviceIDChoose = 1,//设备ID
	PWMValueSetChoose = 2,//PWM值设置
	SickroomQty = 3,//病区位数		
	BedNOQty = 4,//病床倍数	
	HospitalNOQty = 5,//住院号位数
	NetworkState = 6,//网络：开/关
	EvaluateState = 7,//随访：开/关
	SeachState = 8,//查询：开/关
	PasswordState = 9,//密码：开/关
	SilenceState = 10,//静音：开/关
	ClosedState = 11,//扣合：开/关
	JamAlarm = 12,//堵塞：开/关
	BubbleAlarm = 13,//气泡或无液：开/关
	DeviceAlarm = 14,//机械报警：开/关
	Selfcontrol = 15,//自动流速
	Automatic = 16,//自动控制
	pressure_button=17,//压力显示开关
	test = 18,//网络测试开关
}EngineeringModeType;//工程控制画面设置选择

typedef struct
{	
	uint8_t sickroomQty;//病区位数		
	uint8_t	bedNOQty;//病床倍数	
	uint8_t hospitalNOQty;//住院号位数
	uint8_t	networkState;//网络：开/关
	uint8_t	evaluateState;//随访：开/关
	uint8_t seachState;//查询：开/关
	uint8_t passwordState;//密码：开/关
	uint8_t silenceState;//声音：开/关
	uint8_t	closedState;//扣合：开/关
	uint8_t jamAlarm;//堵塞：开/关
	uint8_t	bubbleAlarm;//气泡或无液：开/关
	uint8_t deviceAlarm;//机械报警：开/关
	uint8_t automatic;//自动调整：开/关
	uint16_t	selfcontrol;//自动流速
	uint8_t pressure_switch;//压力显示：开/关
	uint8_t test;
}EngineeringModeFrame;//工程模式

typedef enum
{
	SoundOff,			//静音
	StartupTone,		//开机音	
	VerificationTone,	//确认音
	WarringTone,		//提示音
	InfusionTone,		//输注完毕
	KeypadShortTone,	//短按键音
	KeypadLongTone,		//长按键音
	SoundWait,			//等待提示音完成
	Sound_prepore,   	//预报警声音
	RemindeTone,		//无操作提示音
	LowPriWarning,		//低优先级报警
	SoundWate			//等待
}SpeakerType;

extern TaskSchedulerFlagFrame	TaskSchedulerFlag;//任务调度标志
extern TaskSchedulerTimerFrame	TaskSchedulerTimer;//任务调度定时器

extern KeyTypeFrame	KeyScanStatus;//按键扫描状态
extern KeyFlagFrame	KeyActionFlag;//按键动作标志
extern KeyScanQtyFrame	KeyScanQty;//按键扫描次数
extern KeyFlagFrame	MoreKeyActionFlag;//多键组合动作标志

extern const uint8_t deviceID[16];//设备ID

extern VerifyInfoSetFrame	verifyInfo;//病人住院信息确认
extern SetParamFrame	setParamInfo;//参数设置信息
extern RTDFrame	realTimeData;//实时数据
extern RunParamFrame runParamInfo;//运行参数，因为有两页参数设置相同的参数，所以要有个运行参数
extern AlarmFrame alarmRecord;//报警信息存储

extern SetTimeType emSetTimeChoose;//时间设置选择
extern TimeFrame	displayTimeBuf;//显示时间
extern TimeFrame	setTimeBuf;//显示时间
extern uint8_t		dateLimit;//日期分为29，30，31

extern EvaluateTransfuseType emEvaluateTransfuseChoose;//随访评价选择类型
extern EvaluateTransfuseFrame	evaluateTransfuseValue;//随访评价中的数据

extern EngineeringModeType emEngineeringMode3Choose;//工程控制画面3设置选择类型
extern EngineeringModeType emEngineeringMode1Choose;//工程控制画面1设置选择类型
extern EngineeringModeFrame EngineeringModeValue;//工程模式中的数据

extern uint8_t lockPasswordStep;//锁定密码步骤
extern uint16_t	lockPasswordDisp;//锁定密码

extern uint8_t	setPasswordBuf[3];//密码设置--设置密码界面变量
extern uint8_t	verifyPasswordBuf[3];//确认密码--设置密码界面变量

extern PictureEnterType emPictureRunState;//页面运行状态，是首次进入，还是有数据更新

extern bool motorWorkState;//电机工作状态 

extern SpeakerType sysPromptToneType;	//蜂鸣器提示音类型
extern SpeakerType SysHornToneType;	//喇叭提示音类型

extern uint8_t	sysPromptToneCounts;//提示音响的次数

extern uint16_t batteryVoltLowValue;//电池电压报警

extern uint8_t testDispCounts;//测试页面数据次数

extern uint8_t RunToLorawawn_flag;//在运行时，发送lorawan数据的标志
extern uint8_t StartToRun_flag;             //当按下运行按键的时候，置位该标志
extern uint8_t  start_flag;                          //运行按键启动标志，用于压力值得判断标志
extern uint8_t  ElectStartCount;        //按运行按键时，电流采集次数，求基准值

extern uint8_t FirstSurplusDose;		//堵塞时首次量剩余量
extern uint8_t PCASurplusDose;			//堵塞时PCA量剩余量
extern SpeakerWorkType speakerWorkStep;//蜂鸣器工作类型

void Delay_ms(uint32_t nCount);
void StateOfSystem( void );
void SystemSWInit( void );
void StartupSWInit( void );
void RunParamUpdate( void );
void SetParamUpdate( void );
void StartupSWInit( void );

uint16_t CalCRC16(uint8_t *puchMsg, uint16_t usDataLen);
void Delay_ms(uint32_t nCount);
#endif
