using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetSDKCS;
using System.Windows.Threading;
using System.Runtime.InteropServices;

namespace NetClient
{
    public class AlarmClient : BaseClient
    {
        private AlarmEventManager m_AlarmEventManager;
        private bool m_IsStop = true;
        public event AlarmEventHandler AlarmReceived;
        internal void OnAlarmReviced(object sender, AlarmEventArgs args)
        {
            if (AlarmReceived != null)
            {
                IntPtr n_LoginID = (IntPtr)sender;
                if (n_LoginID == LoginID)
                {
                    AlarmReceived(this, args);
                }
            }
        }

        public AlarmClient()
        {
            m_AlarmEventManager = AlarmEventManager.GetInstance();
        }

        ~AlarmClient()
        {
            if (!m_IsStop)
            {
                StopListen();
            }
        }

        public void StartListen()
        {
            m_AlarmEventManager.AddEvent(OnAlarmReviced);
            try
            {
                NETClient.StartListen(LoginID);
                m_IsStop = false;
            }
            catch (NetSDKCS.NETClientExcetion ex)
            {
                m_AlarmEventManager.RemoveEvent(OnAlarmReviced);
                throw new NETClientExcetion(ex.ErrorCode, ex.Message);
            }
        }

        public void StopListen()
        {
            m_AlarmEventManager.RemoveEvent(OnAlarmReviced);
            if (LoginID != IntPtr.Zero)
            {
                try
                {
                    NETClient.StopListen(LoginID);
                    m_IsStop = true;
                }
                catch (NetSDKCS.NETClientExcetion ex)
                {
                    throw new NETClientExcetion(ex.ErrorCode, ex.Message);
                }
            }
        }

        public override void Logout()
        {
            m_AlarmEventManager.RemoveEvent(OnAlarmReviced);
            base.Logout();
        }

        public override void Dispose()
        {
            m_AlarmEventManager.RemoveEvent(OnAlarmReviced);
            base.Dispose();
        }
    }

    public sealed class AlarmEventManager : DispatcherObject
    {
        private readonly fMessCallBackEx m_AlarmCallBack;
        private event AlarmEventHandler m_AlarmReceived;

        private void OnAlarmReviced(object sender, AlarmEventArgs args)
        {
            if (m_AlarmReceived != null)
            {
                m_AlarmReceived(sender, args);
            }
        }

        private AlarmEventManager()
        {
            m_AlarmCallBack = new fMessCallBackEx(AlarmCallBackEx);
            NETClient.SetDVRMessCallBack(m_AlarmCallBack, IntPtr.Zero);
        }

        ~AlarmEventManager()
        {
            m_AlarmReceived = null;
        }

        private bool AlarmCallBackEx(int lCommand, IntPtr lLoginID, IntPtr pBuf, uint dwBufLen, IntPtr pchDVRIP, int nDVRPort, bool bAlarmAckFlag, int nEventID, IntPtr dwUser)
        {
            object obj = GetObject(lCommand, pBuf, (int)dwBufLen);
            AlarmEventArgs args = new AlarmEventArgs((EM_ALARM_TYPE)lCommand, obj, bAlarmAckFlag, nEventID);
            this.Dispatcher.BeginInvoke((Action<object, AlarmEventArgs>)OnAlarmReviced, lLoginID, args);
            return true;
        }

        private object GetObject(int type, IntPtr buffer, int len)
        {
            Object obj = null;
            switch ((EM_ALARM_TYPE)type)
            {
                case EM_ALARM_TYPE.ALARM_ALARM_EX:
                case EM_ALARM_TYPE.MOTION_ALARM_EX:
                case EM_ALARM_TYPE.VIDEOLOST_ALARM_EX:
                case EM_ALARM_TYPE.SHELTER_ALARM_EX:
                case EM_ALARM_TYPE.DISKFULL_ALARM_EX:
                case EM_ALARM_TYPE.DISKERROR_ALARM_EX:
                    byte[] data = new byte[len];
                    Marshal.Copy(buffer, data, 0, len);
                    obj = data;
                    break;
                case EM_ALARM_TYPE.ALARM_AUDIO_ANOMALY:
                    {
                        NET_ALARM_AUDIO_ANOMALY info = new NET_ALARM_AUDIO_ANOMALY();
                        info = (NET_ALARM_AUDIO_ANOMALY)Marshal.PtrToStructure(buffer, typeof(NET_ALARM_AUDIO_ANOMALY));
                        obj = info;
                        break;
                    }
                case EM_ALARM_TYPE.ALARM_AUDIO_MUTATION:
                    {
                        NET_ALARM_AUDIO_MUTATION info = new NET_ALARM_AUDIO_MUTATION();
                        info = (NET_ALARM_AUDIO_MUTATION)Marshal.PtrToStructure(buffer, typeof(NET_ALARM_AUDIO_MUTATION));
                        obj = info;
                        break;
                    }
                default:
                    break;
            }
            return obj;
        }

        public static AlarmEventManager GetInstance()
        {
            if (ClientManager.AlarmEventInstance == null)
            {
                lock (ClientManager.AlarmEventLock)
                {
                    if (ClientManager.AlarmEventInstance == null)
                    {
                        ClientManager.AlarmEventInstance = new AlarmEventManager();
                    }
                }
            }
            return ClientManager.AlarmEventInstance;
        }

        public void AddEvent(AlarmEventHandler handler)
        {
            m_AlarmReceived += handler;
        }

        public void RemoveEvent(AlarmEventHandler handler)
        {
            m_AlarmReceived -= handler;
        }
    }

    public enum EM_ALARM_TYPE
    {
        COMM_ALARM = 0x1100,		// General alarm(Including external alarm, video loss and motion detection)
        SHELTER_ALARM = 0x1101,		// Camera masking alarm 
        DISK_FULL_ALARM = 0x1102,		// HDD full alarm 
        DISK_ERROR_ALARM = 0x1103,		// HDD malfunction alarm 
        SOUND_DETECT_ALARM = 0x1104,		// Audio detection alarm 
        ALARM_DECODER_ALARM = 0x1105,		// Alarm decoder alarm 

        ALARM_ALARM_EX = 0x2101,		// External alarm ,data's length(byte) is same to device's alarm channels' count, 1 means 
        MOTION_ALARM_EX = 0x2102,		// Motion detection alarm 
        VIDEOLOST_ALARM_EX = 0x2103,		// Video loss alarm 
        SHELTER_ALARM_EX = 0x2104,		// Camera masking alarm 
        SOUND_DETECT_ALARM_EX = 0x2105,		// Audio detection alarm 
        DISKFULL_ALARM_EX = 0x2106,		// HDD full alarm 
        DISKERROR_ALARM_EX = 0x2107,		// HDD malfunction alarm 
        ENCODER_ALARM_EX = 0x210A,		// Encoder alarm 
        URGENCY_ALARM_EX = 0x210B,		// Emergency alarm 
        WIRELESS_ALARM_EX = 0x210C,		// Wireless alarm 
        NEW_SOUND_DETECT_ALARM_EX = 0x210D,		// New auido detection alarm. Please refer to NET_NEW_SOUND_ALARM_STATE for alarm information structure;
        ALARM_DECODER_ALARM_EX = 0x210E,		// Alarm decoder alarm 
        DECODER_DECODE_ABILITY = 0x210F,		// NVD:Decoding capacity
        FDDI_DECODER_ABILITY = 0x2110,		// Fiber encoder alarm
        PANORAMA_SWITCH_ALARM_EX = 0x2111,		// Panorama switch alarm
        LOSTFOCUS_ALARM_EX = 0x2112,		// Lost focus alarm
        OEMSTATE_EX = 0x2113,		// oem state
        DSP_ALARM_EX = 0x2114,		// DSP alarm
        ATMPOS_BROKEN_EX = 0x2115,		// atm and pos disconnection alarm, 0:disconnection 1:connection
        RECORD_CHANGED_EX = 0x2116,		// Record state changed alarm
        CONFIG_CHANGED_EX = 0x2117,		// Device config changed alarm
        DEVICE_REBOOT_EX = 0x2118,		// Device rebooting alarm
        WINGDING_ALARM_EX = 0x2119,       // CoilFault alarm
        TRAF_CONGESTION_ALARM_EX = 0x211A,       // traffic congestion alarm
        TRAF_EXCEPTION_ALARM_EX = 0x211B,       // traffic exception alarm
        EQUIPMENT_FILL_ALARM_EX = 0x211C,       // FlashFault alarm
        ALARM_ARM_DISARM_STATE = 0x211D,		// alarm arm disarm 
        ALARM_ACC_POWEROFF = 0x211E,       // ACC power off alarm
        ALARM_3GFLOW_EXCEED = 0x211F,       // Alarm of 3G flow exceed(see struct NET_DEV_3GFLOW_EXCEED_STATE_INFO)
        ALARM_SPEED_LIMIT = 0x2120,       // Speed limit alarm 
        ALARM_VEHICLE_INFO_UPLOAD = 0x2121,       // Vehicle information uploading 
        STATIC_ALARM_EX = 0x2122,       // Static detection alarm
        PTZ_LOCATION_EX = 0x2123,       // ptz location info
        ALARM_CARD_RECORD_UPLOAD = 0x2124,		// card record info(struct NET_ALARM_CARD_RECORD_INFO_UPLOAD)
        ALARM_ATM_INFO_UPLOAD = 0x2125,		// ATM trade info(struct NET_ALARM_ATM_INFO_UPLOAD)
        ALARM_ENCLOSURE = 0x2126,       // enclosure alarm(struct NET_ALARM_ENCLOSURE_INFO)
        ALARM_SIP_STATE = 0x2127,       // SIP state alarm(struct NET_ALARM_SIP_STATE)
        ALARM_RAID_STATE = 0x2128,       // RAID state alarm(struct NET_ALARM_RAID_INFO)
        ALARM_CROSSING_SPEED_LIMIT = 0x2129,	    // crossing speed limit alarm(struct NET_ALARM_SPEED_LIMIT)
        ALARM_OVER_LOADING = 0x212A,       // over loading alarm(struct NET_ALARM_OVER_LOADING)
        ALARM_HARD_BRAKING = 0x212B,       // hard brake alarm(struct NET_ALARM_HARD_BRAKING)
        ALARM_SMOKE_SENSOR = 0x212C,       // smoke sensor alarm(struct NET_ALARM_SMOKE_SENSOR)
        ALARM_TRAFFIC_LIGHT_FAULT = 0x212D,       // traffic light fault alarm(struct NET_ALARM_TRAFFIC_LIGHT_FAULT) 
        ALARM_TRAFFIC_FLUX_STAT = 0x212E,       // traffic flux alarm(struct NET_ALARM_TRAFFIC_FLUX_LANE_INFO)
        ALARM_CAMERA_MOVE = 0x212F,       // camera move alarm(struct NET_ALARM_CAMERA_MOVE_INFO)
        ALARM_DETAILEDMOTION = 0x2130,       // detailed motion alarm(struct NET_ALARM_DETAILEDMOTION_CHNL_INFO)
        ALARM_STORAGE_FAILURE = 0x2131,       // storage failure alarm(struct NET_ALARM_STORAGE_FAILURE)
        ALARM_FRONTDISCONNECT = 0x2132,       // front IPC disconnect alarm(struct NET_ALARM_FRONTDISCONNET_INFO)
        ALARM_ALARM_EX_REMOTE = 0x2133,       // remote external alarm
        ALARM_BATTERYLOWPOWER = 0x2134,       // battery low power alarm(struct NET_ALARM_BATTERYLOWPOWER_INFO)
        ALARM_TEMPERATURE = 0x2135,       // temperature alarm(struct NET_ALARM_TEMPERATURE_INFO)
        ALARM_TIREDDRIVE = 0x2136,       // tired drive alarm(struct NET_ALARM_TIREDDRIVE_INFO)
        ALARM_LOST_RECORD = 0x2137,       // Alarm of record loss (corresponding structure NET_ALARM_LOST_RECORD)
        ALARM_HIGH_CPU = 0x2138,       // Alarm of High CPU Occupancy rate (corresponding structure NET_ALARM_HIGH_CPU) 
        ALARM_LOST_NETPACKET = 0x2139,       // Alarm of net package loss (corresponding structure NET_ALARM_LOST_NETPACKET)
        ALARM_HIGH_MEMORY = 0x213A,       // Alarm of high memory occupancy rate(corresponding structure NET_ALARM_HIGH_MEMORY)
        LONG_TIME_NO_OPERATION = 0x213B,	    // WEB user have no operation for long time (no extended info)
        BLACKLIST_SNAP = 0x213C,       // blacklist snap(corresponding to NET_BLACKLIST_SNAP_INFO)         
        ALARM_DISK = 0x213E,		// alarm of disk(corresponding to NET_ALARM_DISK_INFO)
        ALARM_FILE_SYSTEM = 0x213F,		// alarm of file systemcorresponding to NET_ALARM_FILE_SYSTEM_INFO)
        ALARM_IVS = 0x2140,       // alarm of ivs(corresponding to NET_ALARM_IVS_INFO)
        ALARM_GOODS_WEIGHT_UPLOAD = 0x2141,		// goods weight (corresponding to NET_ALARM_GOODS_WEIGHT_UPLOAD_INFO)
        ALARM_GOODS_WEIGHT = 0x2142,		// alarm of goods weight(corresponding to NET_ALARM_GOODS_WEIGHT_INFO)
        GPS_STATUS = 0x2143,       // GPS orientation info(corresponding to NET_GPS_STATUS_INFO)
        ALARM_DISKBURNED_FULL = 0x2144,       // alarm disk burned full(corresponding to NET_ALARM_DISKBURNED_FULL_INFO)
        ALARM_STORAGE_LOW_SPACE = 0x2145,		// storage low space(corresponding to NET_ALARM_STORAGE_LOW_SPACE_INFO)
        ALARM_DISK_FLUX = 0x2160,		// disk flux abnormal(corresponding to NET_ALARM_DISK_FLUX)
        ALARM_NET_FLUX = 0x2161,		// net flux abnormal(corresponding to NET_ALARM_NET_FLUX)
        ALARM_FAN_SPEED = 0x2162,		// fan speed abnormal(corresponding to NET_ALARM_FAN_SPEED)
        ALARM_STORAGE_FAILURE_EX = 0x2163,       // storage mistake(corresponding to NET_ALARM_STORAGE_FAILURE_EX)
        ALARM_RECORD_FAILED = 0x2164,		// record abnormal(corresponding to NET_ALARM_RECORD_FAILED_INFO)
        ALARM_STORAGE_BREAK_DOWN = 0x2165,		// storage break down(corresponding to NET_ALARM_STORAGE_BREAK_DOWN_INFO)
        ALARM_VIDEO_ININVALID = 0x2166,       // NET_ALARM_VIDEO_ININVALID_INFO
        ALARM_VEHICLE_TURNOVER = 0x2167,		// vehicle turnover arm event(struct NET_ALARM_VEHICEL_TURNOVER_EVENT_INFO)
        ALARM_VEHICLE_COLLISION = 0x2168,       // vehicle collision event(struct NET_ALARM_VEHICEL_COLLISION_EVENT_INFO)
        ALARM_VEHICLE_CONFIRM = 0x2169,       // vehicle confirm information event(struct NET_ALARM_VEHICEL_CONFIRM_INFO)
        ALARM_VEHICLE_LARGE_ANGLE = 0x2170,       // vehicle camero large angle event(struct NET_ALARM_VEHICEL_LARGE_ANGLE)
        ALARM_TALKING_INVITE = 0x2171,		// device talking invite event (struct NET_ALARM_TALKING_INVITE_INFO)
        ALARM_ALARM_EX2 = 0x2175,		// local alarm event (struct NET_ALARM_ALARM_INFO_EX2)
        ALARM_VIDEO_TIMING = 0x2176,       // video timing detecting event(struct NET_ALARM_VIDEO_TIMING)
        ALARM_COMM_PORT = 0x2177,       // COM event(struct NET_ALARM_COMM_PORT_EVENT_INFO)
        ALARM_AUDIO_ANOMALY = 0x2178,       // audio anomaly event(struct NET_ALARM_AUDIO_ANOMALY)
        ALARM_AUDIO_MUTATION = 0x2179,       // audio mutation event(struct NET_ALARM_AUDIO_MUTATION)
        EVENT_TYREINFO = 0x2180,       // Tyre information report event (struct NET_EVENT_TYRE_INFO)
        ALARM_POWER_ABNORMAL = 0X2181,       // Redundant power supplies abnormal alarm(struct NET_ALARM_POWER_ABNORMAL_INFO)
        EVENT_REGISTER_OFF = 0x2182,		// On-board equipment active offline events(struct  NET_EVENT_REGISTER_OFF_INFO)
        ALARM_NO_DISK = 0x2183,       // No hard disk alarm(struct NET_ALARM_NO_DISK_INFO)
        ALARM_FALLING = 0x2184,       // The fall alarm(struct NET_ALARM_FALLING_INFO)
        ALARM_PROTECTIVE_CAPSULE = 0x2185,       // Protective capsule event(corresponding structure NET_ALARM_PROTECTIVE_CAPSULE_INFO)
        ALARM_NO_RESPONSE = 0x2186,       // Call Non-response alarm(corresponding to NET_ALARM_NO_RESPONSE_INFO)
        ALARM_CONFIG_ENABLE_CHANGE = 0x2187,       // Config enable to change reported event(corresponding to structure  NET_ALARM_CONFIG_ENABLE_CHANGE_INFO)
        EVENT_CROSSLINE_DETECTION = 0x2188,       // Cross warning line event( Corresponding to structure NET_ALARM_EVENT_CROSSLINE_INFO )
        EVENT_CROSSREGION_DETECTION = 0x2189,       // Warning zone event(Corresponding to structure NET_ALARM_EVENT_CROSSREGION_INFO )
        EVENT_LEFT_DETECTION = 0x218a,       // Abandoned object event(Corresponding to structure NET_ALARM_EVENT_LEFT_INFO )
        EVENT_FACE_DETECTION = 0x218b,       // Human face detect event(Corresponding to structure NET_ALARM_EVENT_FACE_INFO ) 
        ALARM_IPC = 0x218c,       // IPC alarm,IPC upload local alarm via DVR or NVR(Corresponding to structure NET_ALARM_IPC_INFO)
        EVENT_TAKENAWAYDETECTION = 0x218d,       // Missing object event(Corresponding to structure NET_ALARM_TAKENAWAY_DETECTION_INFO)
        EVENT_VIDEOABNORMALDETECTION = 0x218e,       // Video abnormal event(Corresponding to structure NET_ALARM_VIDEOABNORMAL_DETECTION_INFO)
        EVENT_MOTIONDETECT = 0x218f,       // Video motion detect event  (Corresponding to structure NET_ALARM_MOTIONDETECT_INFO)
        ALARM_PIR = 0x2190,       // PIR alarm (Corresponding to BYTE*, pBuf length dwBufLen)
        ALARM_STORAGE_HOT_PLUG = 0x2191,       // Storage hot swap event(Corresponding to structure NET_ALARM_STORAGE_HOT_PLUG_INFO)
        ALARM_FLOW_RATE = 0x2192,		// the event of rate of flow(Corresponding to structure NET_ALARM_FLOW_RATE_INFO)
        ALARM_MOVEDETECTION = 0x2193,		// Move detection event(Corresponding to structure NET_ALARM_MOVE_DETECTION_INFO)
        ALARM_WANDERDETECTION = 0x2194,		// WanderDetection event(Corresponding to structure NET_ALARM_WANDERDETECTION_INFO)
        ALARM_CROSSFENCEDETECTION = 0x2195,		// cross fence(Corresponding to NET_ALARM_CROSSFENCEDETECTION_INFO)
        ALARM_PARKINGDETECTION = 0x2196,		// parking detection event(Corresponding to NET_ALARM_PARKINGDETECTION_INFO)
        ALARM_RIOTERDETECTION = 0x2197,		// Rioter detection event(Corresponding to NET_ALARM_RIOTERDETECTION_INFO)

        ALARM_STORAGE_NOT_EXIST = 0x3167,		// A storage group does not exist(struct NET_ALARM_STORAGE_NOT_EXIST_INFO)
        ALARM_NET_ABORT = 0x3169,		// Network fault event(struct NET_ALARM_NETABORT_INFO)
        ALARM_IP_CONFLICT = 0x3170,	    // IP conflict event(struct NET_ALARM_IP_CONFLICT_INFO)
        ALARM_MAC_CONFLICT = 0x3171,		// MAC conflict event(struct NET_ALARM_MAC_CONFLICT_INFO)
        ALARM_POWERFAULT = 0x3172,		// power fault event(struct NET_ALARM_POWERFAULT_INFO)
        ALARM_CHASSISINTRUDED = 0x3173,		// Chassis intrusion, tamper alarm events(struct NET_ALARM_CHASSISINTRUDED_INFO)
        ALARM_ALARMEXTENDED = 0x3174,		// Native extension alarm events(struct NET_ALARM_ALARMEXTENDED_INFO)

        ALARM_ARMMODE_CHANGE_EVENT = 0x3175,		// Cloth removal state change events(struct NET_ALARM_ARMMODE_CHANGE_INFO)
        ALARM_BYPASSMODE_CHANGE_EVENT = 0x3176,		// The bypass state change events(struct NET_ALARM_BYPASSMODE_CHANGE_INFO)

        ALARM_ACCESS_CTL_NOT_CLOSE = 0x3177,		// Entrance guard did not close events(struct NET_ALARM_ACCESS_CTL_NOT_CLOSE_INFO)
        ALARM_ACCESS_CTL_BREAK_IN = 0x3178,		// break-in event(struct NET_ALARM_ACCESS_CTL_BREAK_IN_INFO)
        ALARM_ACCESS_CTL_REPEAT_ENTER = 0x3179,		//access Again and again event(struct NET_ALARM_ACCESS_CTL_REPEAT_ENTER_INFO)
        ALARM_ACCESS_CTL_DURESS = 0x3180,		// Stress CARDS event(struct NET_ALARM_ACCESS_CTL_DURESS_INFO)
        ALARM_ACCESS_CTL_EVENT = 0x3181,		// Access event(struct NET_ALARM_ACCESS_CTL_EVENT_INFO)

        URGENCY_ALARM_EX2 = 0x3182,       // Emergency ALARM EX2(struct NET_ALARM_URGENCY_ALARM_EX2, Artificially triggered emergency, general processing is linked external communication function requests for help
        ALARM_INPUT_SOURCE_SIGNAL = 0x3183,       // Alarm input source signal events (as long as there is input will generate the event, whether to play the current mode, unable to block, struct NET_ALARM_INPUT_SOURCE_SIGNAL_INFO)
        ALARM_ANALOGALARM_EVENT = 0x3184,       //  analog alarm(struct NET_ALARM_ANALOGALARM_EVENT_INFO)
        ALARM_ACCESS_CTL_STATUS = 0x3185,       // Access control status event(corresponding structure NET_ALARM_ACCESS_CTL_STATUS_INFO)
        ALARM_ACCESS_SNAP = 0x3186,       // Access control snapshot event(corresponding to NET_ALARM_ACCESS_SNAP_INFO)
        ALARM_ALARMCLEAR = 0x3187,       // Cancel alarm(corresponding to structure NET_ALARM_ALARMCLEAR_INFO)
        ALARM_CIDEVENT = 0x3188,       // CID event(corresponding to structure NET_ALARM_CIDEVENT_INFO)
        ALARM_TALKING_HANGUP = 0x3189,       // Device hand up evnt(corresponding to structure NET_ALARM_TALKING_HANGUP_INFO)
        ALARM_BANKCARDINSERT = 0x318a,       // Bank card evnt(corresponding to structure NET_ALARM_BANKCARDINSERT_INFO)
        ALARM_RCEMERGENCY_CALL = 0x318b,       // Emergency call alarm event(corresponding to structure NET_ALARM_RCEMERGENCY_CALL_INFO)
        ALARM_OPENDOORGROUP = 0x318c,       // Multi-people group unlock event(corresponding to  structure NET_ALARM_OPEN_DOOR_GROUP_INFO)
        ALARM_FINGER_PRINT = 0x318d,       // get fingerprint event(corresponding to  structure NET_ALARM_CAPTURE_FINGER_PRINT_INFO)
        ALARM_CARD_RECORD = 0x318e,       // card no. record event(corresponding to  structure  NET_ALARM_CARD_RECORD_INFO)
        ALARM_SUBSYSTEM_STATE_CHANGE = 0x318f,       // sub system status change event(corresponding to  structure NET_ALARM_SUBSYSTEM_STATE_CHANGE_INFO)
        ALARM_BATTERYPOWER_EVENT = 0x3190,       // battery scheduled warning event(corresponding to  structure NET_ALARM_BATTERYPOWER_INFO)
        ALARM_BELLSTATUS_EVENT = 0x3191,       // bell status event(corresponding to  structure NET_ALARM_BELLSTATUS_INFO)
        ALARM_DEFENCE_STATE_CHANGE_EVENT = 0x3192,       // zone status change event(corresponding to  structure NET_ALARM_DEFENCE_STATUS_CHANGE_INFO), 
        // customized need￡?and arm/disarm change event, bypass event status have different definitions,
        // The status via QueryDevState port NET_DEVSTATE_DEFENCE_STATE command get
        ALARM_TICKET_STATISTIC = 0x3193,       // ticket statistics info event(corresponding to  structure  NET_ALARM_TICKET_STATISTIC)
        ALARM_LOGIN_FAILIUR = 0x3194,       // login failed event(corresponding to  structure NET_ALARM_LOGIN_FAILIUR_INFO)
        ALARM_MODULE_LOST = 0x3195,       // expansion module offline event(corresponding to  structure  NET_ALARM_MODULE_LOST_INFO)
        ALARM_PSTN_BREAK_LINE = 0x3196,       // PSTN offline event(corresponding to  structure NET_ALARM_PSTN_BREAK_LINE_INFO)
        ALARM_ANALOG_PULSE = 0x3197,       // analog alarm evnet(instant event), specific sensor  trigger(corresponding to  structure NET_ALARM_ANALOGPULSE_INFO)
        ALARM_MISSION_CONFIRM = 0x3198,       // task confirmation event(corresponding to  structure  NET_ALARM_MISSION_CONFIRM_INFO)
        ALARM_DEVICE_MSG_NOTIFY = 0x3199,       // device to platform notice event?t(corresponding to  structure  NET_ALARM_DEVICE_MSG_NOTIFY_INFO)
        ALARM_VEHICLE_STANDING_OVER_TIME = 0x319A,       // parking timeout event(corresponding to  structure  NET_ALARM_VEHICLE_STANDING_OVER_TIME_INFO)
        ALARM_ENCLOSURE_ALARM = 0x319B,       // e-fence event(corresponding to  structure  NET_ALARM_ENCLOSURE_ALARM_INFO)
        ALARM_GUARD_DETECT = 0x319C,	    // station detection event, one in station first report the start event and last on in station report stop event before leave (corresponding to  structure NET_ALARM_GUARD_DETECT_INFO)
        ALARM_GUARD_INFO_UPDATE = 0x319D,	    // station info update event￡?report if people in station(corresponding to  structure NET_ALARM_GUARD_UPDATE_INFO)  
        ALARM_NODE_ACTIVE = 0x319E,       // Node activation event (corresponding to structure NET_ALARM_NODE_ACTIVE_INFO)
        ALARM_VIDEO_STATIC = 0x319F,       // Video static detection event (corresponding to structure NET_ALARM_VIDEO_STATIC_INFO)
        ALARM_REGISTER_REONLINE = 0x31a0,       // Active registration device re-login event (corresponding to structure NET_ALARM_REGISTER_REONLINE_INFO)
        ALARM_ISCSI_STATUS = 0x31a1,       // ISCSI alarm event (corresponding to structure NET_ALARM_ISCSI_STATUS_INFO)
        ALARM_SCADA_DEV_ALARM = 0x31a2,       // detection collection device alarm event (corresponding to structure NET_ALARM_SCADA_DEV_INFO)
        ALARM_AUXILIARY_DEV_STATE = 0x31a3,       // Sub device status(corresponding structure NET_ALARM_AUXILIARY_DEV_STATE)
        ALARM_PARKING_CARD = 0x31a4,       // Parking swipe card event(corresponding structure NET_ALARM_PARKING_CARD)
        ALARM_PROFILE_ALARM_TRANSMIT = 0x31a5,       // Alarm transmit event(corresponding structure NET_ALARM_PROFILE_ALARM_TRANSMIT_INFO)
        ALARM_VEHICLE_ACC = 0x31a6,       // Vehicle acc event(corresponding structure NET_ALARM_VEHICLE_ACC_INFO)
        ALARM_TRAFFIC_SUSPICIOUSCAR = 0x31a7,       // suspiciouscar event(corresponding structure NET_ALARM_TRAFFIC_SUSPICIOUSCAR_INFO)
        ALARM_ACCESS_LOCK_STATUS = 0x31a8,       // the event of latch state (corresponding structure  NET_ALARM_ACCESS_LOCK_STATUS_INFO)
        ALARM_FINACE_SCHEME = 0x31a9,       // Finace scheme event(corresponding structure NET_ALARM_FINACE_SCHEME_INFO)
        ALARM_HEATIMG_TEMPER = 0x31aa,       // Thermal temperature abnormal event alarm(Corresponding to structure NET_ALARM_HEATIMG_TEMPER_INFO)
        ALARM_TALKING_IGNORE_INVITE = 0x31ab,       // Device cancel bidirectional talk query event(Corresponding to structure NET_ALARM_TALKING_IGNORE_INVITE_INFO)
        ALARM_BUS_SHARP_TURN = 0x31ac,       // Vehicle Abrupt-turn event(Corresponding to structure NET_ALARM_BUS_SHARP_TURN_INFO)
        ALARM_BUS_SCRAM = 0x31ad,       // vehicle abrupt stop event(Corresponding to structure NET_ALARM_BUS_SCRAM_INFO)
        ALARM_BUS_SHARP_ACCELERATE = 0x31ae,       // Vehicle abrupt speed up event(Corresponding to structure NET_ALARM_BUS_SHARP_ACCELERATE_INFO)
        ALARM_BUS_SHARP_DECELERATE = 0x31af,       // Vehicle abrupt slow down event (Corresponding to structure NET_ALARM_BUS_SHARP_DECELERATE_INFO)
        ALARM_ACCESS_CARD_OPERATE = 0x31b0,		// A&C data operation event (Corresponding to structure NET_ALARM_ACCESS_CARD_OPERATE_INFO)
        ALARM_POLICE_CHECK = 0x31b1,       // Policeman check in event(Corresponding to structure NET_ALARM_POLICE_CHECK_INFO)
        ALARM_NET = 0x31b2,       // Network alarm event(Corresponding to structure NET_ALARM_NET_INFO)
        ALARM_NEW_FILE = 0X31b3,       // New file event(Corresponding to structure NET_ALARM_NEW_FILE_INFO)

        ALARM_FIREWARNING = 0x31b5,       // Thermal fire position (Corresponding to structure NET_ALARM_FIREWARNING_INFO)
        ALARM_RECORD_LOSS = 0x31b6,       // Record loss event: the HDD is OK, delete results from misoperation.  (Corresponding to structure NET_ALARM_RECORD_LOSS_INFO)
        ALARM_VIDEO_FRAME_LOSS = 0x31b7,       // Frame loss event，it results from poor network environment or insufficient encode capability (Corresponding to structure NET_ALARM_VIDEO_FRAME_LOSS_INFO)
        ALARM_RECORD_VOLUME_FAILURE = 0x31b8,       // Abnormal record results from HDD volume(Corresponding to structure NET_ALARM_RECORD_VOLUME_FAILURE_INFO)
        EVENT_SNAP_UPLOAD = 0X31b9,       // Image upload completion event(Corresponding to structure NET_EVENT_SNAP_UPLOAD_INFO)
        ALARM_AUDIO_DETECT = 0x31ba,       // Audio detect event(Corresponding to structure NET_ALARM_AUDIO_DETECT )
        ALARM_UPLOADPIC_FAILCOUNT = 0x31bb,       // Failure data amount during the image upload process （Corresponding to structure NET_ALARM_UPLOADPIC_FAILCOUNT_INFO）
        ALARM_POS_MANAGE = 0x31bc,       // POS management event(Corresponding to NET_ALARM_POS_MANAGE_INFO )
        ALARM_REMOTE_CTRL_STATUS = 0x31bd,       // remote control status(Corresponding to NET_ALARM_REMOTE_CTRL_STATUS )
        ALARM_PASSENGER_CARD_CHECK = 0x31be,       // desuetude, passenger card check(Corresponding to structure NET_ALARM_PASSENGER_CARD_CHECK )
        ALARM_SOUND = 0x31bf,       // Sound event(Corresponding to NET_ALARM_SOUND )
        ALARM_LOCK_BREAK = 0x31c0,       // Lock break event(Corresponding to NET_ALARM_LOCK_BREAK_INFO )
        ALARM_HUMAN_INSIDE = 0x31c1,       // Human Inside event((Corresponding to structure NET_ALARM_HUMAN_INSIDE_INFO)
        ALARM_HUMAN_TUMBLE_INSIDE = 0x31c2,       // Human tumble Inside(Corresponding to structure NET_ALARM_HUMAN_TUMBLE_INSIDE_INFO)
        ALARM_DISABLE_LOCKIN = 0x31c3,       // Lock entry trigger event(Corresponding to structure NET_ALARM_DISABLE_LOCKIN_INFO)
        ALARM_DISABLE_LOCKOUT = 0x31c4,       // Lock go out trigger(Corresponding to structure NET_ALARM_DISABLE_LOCKOUT_INFO)
        ALARM_UPLOAD_PIC_FAILED = 0x31c5,       // break rules data upload failed (Corresponding to NET_ALARM_UPLOAD_PIC_FAILED_INFO )
        ALARM_FLOW_METER = 0x31c6,       // flow meter info event (NET_ALARM_FLOW_METER_INFO)
        ALARM_WIFI_SEARCH = 0x31c7,       // search around wifi device(Corresponding to NET_ALARM_WIFI_SEARCH_INFO)
        ALARM_WIRELESSDEV_LOWPOWER = 0X31C8,       // lowpower of wirelessdevice(NET_ALARM_WIRELESSDEV_LOWPOWER_INFO)
        ALARM_PTZ_DIAGNOSES = 0x31c9,		// Ptz Diagnoses event(Corresponding to NET_ALARM_PTZ_DIAGNOSES_INFO)
        ALARM_FLASH_LIGHT_FAULT = 0x31ca,       // flash light fault event (Corresponding to NET_ALARM_FLASH_LIGHT_FAULT_INFO)
        ALARM_STROBOSCOPIC_LIGTHT_FAULT = 0x31cb,       // stroboscopic light fault event (Corresponding to NET_ALARM_STROBOSCOPIC_LIGTHT_FAULT_INFO)
        ALARM_HUMAM_NUMBER_STATISTIC = 0x31cc,       // NumberStat event (Corresponding to NET_ALARM_HUMAN_NUMBER_STATISTIC_INFO)
        ALARM_VIDEOUNFOCUS = 0x31ce,       // Video unfocus (Corresponding NET_ALARM_VIDEOUNFOCUS_INFO)
        ALARM_BUF_DROP_FRAME = 0x31cd,       // Video recond buffer drop frame event(Corresponding to NET_ALARM_BUF_DROP_FRAME_INFO)
        ALARM_DOUBLE_DEV_VERSION_ABNORMAL = 0x31cf,       // Abnormal event when master broad'version and slave broad'version different  (Corresponding to NET_ALARM_DOUBLE_DEV_VERSION_ABNORMAL_INFO)
        ALARM_DCSSWITCH = 0x31d0,       // Switch with master and slave(Corresponding to NET_ALARM_DCSSWITCH_INFO)
        ALARM_RADAR_CONNECT_STATE = 0x31d1,       // Radar connect state(Corresponding to NET_ALARM_RADAR_CONNECT_STATE_INFO)
        ALARM_DEFENCE_ARMMODE_CHANGE = 0x31d2,       // Defence arming status change(Corresponding to NET_ALARM_DEFENCE_ARMMODECHANGE_INFO)
        ALARM_SUBSYSTEM_ARMMODE_CHANGE = 0x31d3,       // Subsystem arming status change(Corresponding to NET_ALARM_SUBSYSTEM_ARMMODECHANGE_INFO)
        ALARM_RFID_INFO = 0x31d4,       // infrared detection information event (Corresponding NET_ALARM_RFID_INFO)
        ALARM_SMOKE_DETECTION = 0x31d5,       // smoke detection(Corresponding NET_ALARM_SMOKE_DETECTION_INFO)
        ALARM_BETWEENRULE_TEMP_DIFF = 0x31d6,       // TemperatureDifference Between Rule (Corresponding NET_ALARM_BETWEENRULE_DIFFTEMPER_INFO)
        ALARM_TRAFFIC_PIC_ANALYSE = 0x31d7,		// Traffic picture analyse(Corresponding NET_ALARM_PIC_ANALYSE_INFO)
        ALARM_HOTSPOT_WARNING = 0x31d8,       // Hotspot warning(Corresponding NET_ALARM_HOTSPOT_WARNING_INFO)
        ALARM_COLDSPOT_WARNING = 0x31d9,       // coldspot warning(Corresponding NET_ALARM_COLDSPOT_WARNING_INFO)
        ALARM_FIREWARNING_INFO = 0x31da,       // firewarning (Corresponding NET_ALARM_FIREWARNING_INFO_DETAIL)
        ALARM_FACE_OVERHEATING = 0x31db,       // face overheating(Corresponding NET_ALARM_FACE_OVERHEATING_INFO)
        ALARM_SENSOR_ABNORMAL = 0X31dc,       // Sensor abnormal(Corresponding NET_ALARM_SENSOR_ABNORMAL_INFO)
        ALARM_PATIENTDETECTION = 0x31de,       // patient detection(Corresponding NET_ALARM_PATIENTDETECTION_INFO)
        ALARM_RADAR_HIGH_SPEED = 0x31df,       // radar high speed detection(Corresponding to NET_ALARM_RADAR_HIGH_SPEED_INFO)
        ALARM_POLLING_ALARM = 0x31e0,       // Polling Alarm (Corresponding to NET_ALARM_POLLING_ALARM_INFO)
        ALARM_ITC_HWS000 = 0x31e1,       // the alarm event for ITC_HWS000 (Corresponding NET_ALARM_ITC_HWS000)
        ALARM_TRAFFICSTROBESTATE = 0x31e2,       // Traffic Strobe State(Corresponding to NET_ALARM_TRAFFICSTROBESTATE_INFO)
        ALARM_TELEPHONE_CHECK = 0x31e3,       // telephone number check event(Corresponding to NET_ALARM_TELEPHONE_CHECK_INFO)
        ALARM_PASTE_DETECTION = 0x31e4,       // Paste Detection(Corresponding to NET_ALARM_PASTE_DETECTION_INFO )
        ALARM_SHOOTINGSCORERECOGNITION = 0x31e5,       // the alarm event for Shooting (Corresponding to NET_ALARM_PIC_SHOOTINGSCORERECOGNITION_INFO)
        ALARM_SWIPEOVERTIME = 0x31e6,       // the alarm event for swipe overtime(Corresponding to NET_ALARM_SWIPE_OVERTIME_INFO)
        ALARM_DRIVING_WITHOUTCARD = 0x31e7,       // the alarm event for driving without card(Corresponding to NET_ALARM_DRIVING_WITHOUTCARD_INFO)
        ALARM_TRAFFIC_PEDESTRIAN_RUN_REDLIGHT_DETECTION = 0x31e8,       //red light event (Corresponding to NET_ALARM_TRAFFIC_PEDESTRIAN_RUN_REDLIGHT_DETECTION_INFO)
        ALARM_FIGHTDETECTION = 0x31e9, 		//the alarm event for fight detection(Corresponding to NET_ALARM_FIGHTDETECTION)
    }
}
