#ifndef __SYSTEMALARM_H__
#define __SYSTEMALARM_H__
/*--------------------------------------------------------------------------------------
*  @file     SystemAlarm.h
*  @author   ZhangJing
*  @version  base on stm32f0x   
*  @date     2015.10.12
*  @brief    系统报警处理
---------------------------------------------------------------------------------------*/
#include "stdint.h"

#define ALARM_OFF				0//报警关
#define ALARM_ON				1//报警开
#define ALARM_SCREEN		2//报警屏蔽
#define ALARM_CONTINUE	3//持续报警
#define ALARM_PREPARE		4//预报警

//压力正常值
/*
#define PRESSURE_ALARM_VALUE_A	11	//无药盒报警阈值
//#define PRESSURE_ALARM_VALUE_B	30	//无液或气泡报警阈值低
#define PRESSURE_ALARM_VALUE_B	16	//无液或气泡报警阈值低
#define PRESSURE_ALARM_VALUE_C	10	//管路脱落暂定10kpa
//#define PRESSURE_ALARM_VALUE_D	45	//无液或气泡报警阈值高
#define PRESSURE_ALARM_VALUE_D	23	//无液或气泡报警阈值高
//#define PRESSURE_ALARM_VALUE_E	56	//堵塞报警阈值
#define PRESSURE_ALARM_VALUE_E	33	//堵塞报警阈值*/

#define PRESSURE_ALARM_VALUE_A	11	//无药盒报警阈值
//#define PRESSURE_ALARM_VALUE_B	30	//无液或气泡报警阈值低
#define PRESSURE_ALARM_VALUE_B	11	//无液或气泡报警阈值低
#define PRESSURE_ALARM_VALUE_C	10	//管路脱落暂定10kpa
//#define PRESSURE_ALARM_VALUE_D	45	//无液或气泡报警阈值高
#define PRESSURE_ALARM_VALUE_D	24	//无液或气泡报警阈值高
//#define PRESSURE_ALARM_VALUE_E	56	//堵塞报警阈值
#define PRESSURE_ALARM_VALUE_E	40	//堵塞报警阈值


//压力测试值
// #define PRESSURE_ALARM_VALUE_A	5		//无药盒报警阈值
// #define PRESSURE_ALARM_VALUE_B	7		//无液或气泡报警阈值低
// #define PRESSURE_ALARM_VALUE_C	10	//管路脱落暂定10kpa
// #define PRESSURE_ALARM_VALUE_D	14	//无液或气泡报警阈值高
// #define PRESSURE_ALARM_VALUE_E	24	//堵塞报警阈值

//电压测试值
// #define BATTERY_VOLT_LOW_LIMIT		47 //电池低电压下限 SOC < 47% 3.7V
//电压正常值
#define BATTERY_VOLT_LOW_LIMIT		20 //电池低电压下限 SOC < 40% 3.3V
#define BATTERY_VOLT_LOW_PREPARE	40 //电池低电压预报 SOC < 80% 4.6V


typedef struct
{
	uint8_t SysRunTest;//系统运行测试
	uint8_t alarmCollect;//报警收集
	uint8_t	MechanicalFault;//机械故障
	uint8_t	JamFault;//堵塞故障
	uint8_t	MaxFault;//极限值故障
	uint8_t BubbleFault;//气泡或无液故障
	uint8_t	NonePillCase;//未装药盒故障
	uint8_t	InputEnding;//输液将结束
	uint8_t	InputEnd;		//输液结束
	uint8_t	VoltLowest;	//电池电量低
	uint8_t MotorFalt;//电机故障
	uint8_t LineLost;//管道脱落
	uint8_t InstallFalt;//未夹装到位
	uint8_t Zhentongxiaoguo;//镇痛效果
	uint8_t InputTotal;//输入总量
}AlarmTypeFrame;

typedef struct
{
	uint8_t	JamFaultJudgeFlag;//堵塞故障判断标志
	uint8_t BubbleFaultJudgeFlag;//气泡或无液故障标志
	uint8_t	NonePillCaseJudgeFlag;//未装药盒故障标志
	uint8_t	VoltLowestJudgeFlag;	//电池电量低标志
	uint8_t	JamFaultJudgeCounts;//堵塞故障判断次数
	uint8_t BubbleFaultJudgeCounts;//气泡或无液故障次数
	uint8_t	NonePillCaseJudgeCounts;//未装药盒故障次数
	uint8_t	VoltLowestJudgeCounts;	//电池电量低次数
}AlarmJudgeFrame;

void PECASelfTestHandle( void );
void MechanicalFaultHandle( void );
void JamFaultHandle( void );
void MaxFaultHandle( void );
void BubbleFaultHandle( void );
void NonePillCaseHandle( void );
void BatteryVoltLowHandle( void );
void LineLostHandle( void );
void SystemAlarmJudge( void );
void InputTotalHandle( void );


extern AlarmJudgeFrame SysAlarmJudge;//报警判断
//extern uint8_t MechanicalFaultCounts;//机械故障报警计数，大于2次则报警
extern uint32_t Timer_VoltLowes;        //预报警延时30分钟
extern uint8_t VoltLowest_Alarm_Flag;                     //低电量报警标志     
extern AlarmTypeFrame sysAlarmFlag;                         //报警标志位
extern AlarmTypeFrame AlarmRecord;
extern uint8_t JamSelfcheckCycle;							//堵塞自检周期
extern uint8_t JamSelfcheckThroughCycle;				//堵塞自检通过周期
#endif
