Ejemplo n.º 1
0
        private FetchEventsResult fetchEventsBlock(IntPtr ControllerHandler, int eventIndex, int eventCount)
        {
            //log.Info("Requested from " + eventIndex + ", count of " + eventCount);
            ZG_EV_TIME    rTime   = new ZG_EV_TIME();
            ZG_CTR_DIRECT nDirect = new ZG_CTR_DIRECT();

            ZG_CTR_EVENT[] aEvents = new ZG_CTR_EVENT[eventCount];
            int            hr      = ZGIntf.ZG_Ctr_ReadEvents(ControllerHandler, eventIndex, aEvents, eventCount, null, IntPtr.Zero);

            if (hr < 0)
            {
                log.Fatal("Ошибка ZG_Ctr_ReadEvents (" + hr + ")");
                throw new ZCommonException("Ошибка ZG_Ctr_ReadEvents").setErrorCode(hr);
            }
            ZG_CTR_EVENT      rEv;
            FetchEventsResult result = new FetchEventsResult();

            result.items = new List <ControllerEvent>();
            for (int j = 0; j < eventCount; j++)
            {
                rEv = aEvents[j];
                switch (rEv.nType)
                {
                case ZG_CTR_EV_TYPE.ZG_EV_KEY_NOT_FOUND:
                case ZG_CTR_EV_TYPE.ZG_EV_KEY_OPEN:
                case ZG_CTR_EV_TYPE.ZG_EV_KEY_ACCESS:
                    int nKeyIdx  = 0;
                    int nKeyBank = 0;
                    ZGIntf.ZG_Ctr_DecodePassEvent(ControllerHandler, rEv.aData, ref rTime, ref nDirect, ref nKeyIdx, ref nKeyBank);
                    ControllerEvent newEvent = new ControllerEvent();
                    newEvent.month    = rTime.nMonth;
                    newEvent.day      = rTime.nDay;
                    newEvent.hour     = rTime.nHour;
                    newEvent.minute   = rTime.nMinute;
                    newEvent.second   = rTime.nSecond;
                    newEvent.keyIndex = nKeyIdx;
                    result.items.Add(newEvent);
                    result.lastReadIndex  = eventIndex + j;
                    result.lastReadMonth  = rTime.nMonth;
                    result.lastReadDay    = rTime.nDay;
                    result.lastReadHour   = rTime.nHour;
                    result.lastReadMinute = rTime.nMinute;
                    result.lastReadSecond = rTime.nSecond;
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        static void ShowEvents(int nStart, int nCount)
        {
            var msg = "";

            ZG_CTR_EVENT[] aEvents = new ZG_CTR_EVENT[6];
            ZG_CTR_EVENT   rEv;
            int            i = 0;
            int            nIdx, nCnt;
            int            hr;

            while (i < nCount)
            {
                nIdx = (nStart + i) % m_nCtrMaxEvents;
                nCnt = (nCount - i);
                if (nCnt > aEvents.Length)
                {
                    nCnt = aEvents.Length;
                }
                if ((nIdx + nCnt) > m_nCtrMaxEvents)
                {
                    nCnt = (m_nCtrMaxEvents - nIdx);
                }
                hr = ZGIntf.ZG_Ctr_ReadEvents(m_hCtr, nIdx, aEvents, nCnt, null, IntPtr.Zero);
                if (hr < 0)
                {
                    Console.WriteLine("Ошибка ZG_Ctr_ReadEvents ({0}).", hr);
                    Console.ReadLine();
                    return;
                }
                for (int j = 0; j < nCnt; j++)
                {
                    rEv = aEvents[j];
                    switch (rEv.nType)
                    {
                    case ZG_CTR_EV_TYPE.ZG_EV_ELECTRO_ON:
                    case ZG_CTR_EV_TYPE.ZG_EV_ELECTRO_OFF:
                    {
                        ZG_EV_TIME   rTime       = new ZG_EV_TIME();
                        ZG_EC_SUB_EV nSubEvent   = new ZG_EC_SUB_EV();
                        UInt32       nPowerFlags = 0;
                        ZGIntf.ZG_Ctr_DecodeEcEvent(m_hCtr, rEv.aData, ref rTime, ref nSubEvent, ref nPowerFlags);
                        msg = string.Format("{0}. {1:D2}.{2:D2} {3:D2}:{4:D2}:{5:D2} {6} Sub_event: {7} Power flags: {8:X2}h",
                                            nIdx + j,
                                            rTime.nDay, rTime.nMonth,
                                            rTime.nHour, rTime.nMinute, rTime.nSecond,
                                            EvTypeStrs[(int)rEv.nType],
                                            EcSubEvStrs[(int)nSubEvent], nPowerFlags);
                        Console.WriteLine(msg);
                        OnReportHandler(msg);         // и т.д. по желанию
                    }
                    break;

                    case ZG_CTR_EV_TYPE.ZG_EV_FIRE_STATE:
                    {
                        ZG_EV_TIME     rTime      = new ZG_EV_TIME();
                        ZG_FIRE_SUB_EV nSubEvent  = new ZG_FIRE_SUB_EV();
                        UInt32         nFireFlags = 0;
                        ZGIntf.ZG_Ctr_DecodeFireEvent(m_hCtr, rEv.aData, ref rTime, ref nSubEvent, ref nFireFlags);
                        Console.WriteLine("{0}. {1:D2}.{2:D2} {3:D2}:{4:D2}:{5:D2} {6} Sub_event: {7} Fire flags: {8:X2}h",
                                          nIdx + j,
                                          rTime.nDay, rTime.nMonth,
                                          rTime.nHour, rTime.nMinute, rTime.nSecond,
                                          EvTypeStrs[(int)rEv.nType],
                                          FireSubEvStrs[(int)nSubEvent], nFireFlags);
                    }
                    break;

                    case ZG_CTR_EV_TYPE.ZG_EV_SECUR_STATE:
                    {
                        ZG_EV_TIME      rTime       = new ZG_EV_TIME();
                        ZG_SECUR_SUB_EV nSubEvent   = new ZG_SECUR_SUB_EV();
                        UInt32          nSecurFlags = 0;
                        ZGIntf.ZG_Ctr_DecodeSecurEvent(m_hCtr, rEv.aData, ref rTime, ref nSubEvent, ref nSecurFlags);
                        Console.WriteLine("{0}. {1:D2}.{2:D2} {3:D2}:{4:D2}:{5:D2} {6} Sub_event: {7} Security flags: {8:X2}h",
                                          nIdx + j,
                                          rTime.nDay, rTime.nMonth,
                                          rTime.nHour, rTime.nMinute, rTime.nSecond,
                                          EvTypeStrs[(int)rEv.nType],
                                          SecurSubEvStrs[(int)nSubEvent], nSecurFlags);
                    }
                    break;

                    case ZG_CTR_EV_TYPE.ZG_EV_MODE_STATE:
                    {
                        ZG_EV_TIME     rTime     = new ZG_EV_TIME();
                        ZG_CTR_MODE    nMode     = new ZG_CTR_MODE();
                        ZG_MODE_SUB_EV nSubEvent = new ZG_MODE_SUB_EV();
                        ZGIntf.ZG_Ctr_DecodeModeEvent(m_hCtr, rEv.aData, ref rTime, ref nMode, ref nSubEvent);
                        msg = string.Format("{0}. {1:D2}.{2:D2} {3:D2}:{4:D2}:{5:D2} {6} Mode: {7} Sub_event: {8}",
                                            nIdx + j,
                                            rTime.nDay, rTime.nMonth,
                                            rTime.nHour, rTime.nMinute, rTime.nSecond,
                                            EvTypeStrs[(int)rEv.nType],
                                            ModeStrs[(int)nMode],
                                            ModeSubEvStrs[(int)nSubEvent]);
                        Console.WriteLine(msg);
                        OnReportHandler(msg);         // и т.д. по желанию
                    }
                    break;

                    case ZG_CTR_EV_TYPE.ZG_EV_UNKNOWN_KEY:
                    {
                        Byte[] rKeyNum = new Byte[16];
                        ZGIntf.ZG_Ctr_DecodeUnkKeyEvent(m_hCtr, rEv.aData, rKeyNum);
                        msg = string.Format("{0}.  Key \"{1}\"",
                                            nIdx + j,
                                            ZGIntf.CardNumToStr(rKeyNum, m_fProximity));
                        Console.WriteLine(msg);
                        OnReportHandler(msg);         // и т.д. по желанию
                    }
                    break;

                    case ZG_CTR_EV_TYPE.ZG_EV_HOTEL40:
                    case ZG_CTR_EV_TYPE.ZG_EV_HOTEL41:
                    {
                        ZG_EV_TIME      rTime     = new ZG_EV_TIME();
                        ZG_HOTEL_MODE   nMode     = new ZG_HOTEL_MODE();
                        ZG_HOTEL_SUB_EV nSubEvent = new ZG_HOTEL_SUB_EV();
                        UInt32          nFlags    = new UInt32();
                        ZGIntf.ZG_DecodeHotelEvent(rEv.aData, ref rTime, ref nMode, ref nSubEvent, ref nFlags);
                        Console.WriteLine("{0}. {1:D2}.{2:D2} {3:D2}:{4:D2}:{5:D2} {6} Mode: {7} Sub_event: {8} flags: {9:X2}h",
                                          nIdx + j,
                                          rTime.nDay, rTime.nMonth,
                                          rTime.nHour, rTime.nMinute, rTime.nSecond,
                                          EvTypeStrs[(int)rEv.nType],
                                          HModeStrs[(int)nMode],
                                          HotelSubEvStrs[(int)nSubEvent],
                                          nFlags);
                    }
                    break;

                    default:
                    {
                        ZG_EV_TIME    rTime    = new ZG_EV_TIME();
                        ZG_CTR_DIRECT nDirect  = new ZG_CTR_DIRECT();
                        int           nKeyIdx  = 0;
                        int           nKeyBank = 0;
                        ZGIntf.ZG_Ctr_DecodePassEvent(m_hCtr, rEv.aData, ref rTime, ref nDirect, ref nKeyIdx, ref nKeyBank);
                        Console.WriteLine("{0}. {1:D2}.{2:D2} {3:D2}:{4:D2}:{5:D2} {6} {7} (key_idx: {8}, bank#: {9})",
                                          nIdx + j,
                                          rTime.nDay, rTime.nMonth,
                                          rTime.nHour, rTime.nMinute, rTime.nSecond,
                                          DirectStrs[(int)nDirect],
                                          EvTypeStrs[(int)rEv.nType],
                                          nKeyIdx, nKeyBank);
                    }
                    break;
                    }
                }
                i += nCnt;
            }
        }