コード例 #1
0
        //Parse Record From Data String
        public static ControllerRecord ParseRecordFromWatch(byte[] recordPayload)
        {
            String           debugWatch = BitConverter.ToString(recordPayload).Replace("-", "");
            ControllerRecord newRecord  = new ControllerRecord();

            //Response is by byte, 2 digit year, month, weekday, date, hour, min, seconds.
            //Ignore weekday.
            //Format is in BCD
            try
            {
                newRecord.controllerDateTime = new DateTime(2000 + Int32.Parse(recordPayload[0].ToString("X")),
                                                            Int32.Parse(recordPayload[1].ToString("X")),
                                                            Int32.Parse(recordPayload[2].ToString("X")),
                                                            Int32.Parse(recordPayload[4].ToString("X")),
                                                            Int32.Parse(recordPayload[5].ToString("X")),
                                                            Int32.Parse(recordPayload[6].ToString("X")));
            }
            catch (Exception e)   //Catch if Data is out of Range
            {
                return(null);
            }

            //I don't know why the record index is split across bytes but it is. I suspect that the high byte is a memory page number.
            //Look The original code was using 1 Indexed VB Strings and Concatenation To do this.

            UInt32 lng1 = ((UInt32 )WGTools.NetToUInt16(recordPayload, 7) << 8) + (UInt32)(recordPayload[9] & 0x0F);
            UInt32 lng2 = ((UInt32)WGTools.NetToUInt16(recordPayload, 10) << 8) + (UInt32)((recordPayload[9] & 0xF0) >> 4);



            //Check if Card Data Available
            if ((WGTools.NetToUInt32(recordPayload, 12) != 0xFFFFFFFF) && (WGTools.NetToUInt32(recordPayload, 16) == 0xFFFFFFFF))
            {
                //Lost of Door Status Stuff HEre. Ignore it for now
                return(null);
            }

            newRecord.responseType = recordPayload[25];

            newRecord.is10Digit = false;
            //Read In Card Data
            if ((newRecord.responseType & 0x04) > 0)
            {
                newRecord.cardID     = WGTools.NetToUInt32(recordPayload, 12);
                newRecord.statusByte = recordPayload[20];

                newRecord.flagsByte    = (byte)((newRecord.statusByte >= 128) ? 0 : 1); //Scan Success?
                newRecord.readDateTime = WGTools.NetToDateTime32(recordPayload, 16);

                if (newRecord.readDateTime == DateTime.MinValue)
                {
                    return(null);
                }

                if ((newRecord.responseType & 0x08) > 0)
                {
                    newRecord.readDateTime.AddSeconds(1.0);
                }

                if ((newRecord.responseType & 1L) > 0)
                {
                    newRecord.is10Digit = true;
                }

                return(newRecord);
            }
            else
            {
                newRecord.cardID = (UInt32)WGTools.NetToUInt16(recordPayload, 19) + (UInt32)recordPayload[21] * 0x10000;

                newRecord.statusByte = recordPayload[15];
                newRecord.flagsByte  = (byte)((newRecord.statusByte >= 128) ? 0 : 1);  //Scan Success?

                newRecord.readDateTime = WGTools.NetToDateTime32(recordPayload, 16);

                if (newRecord.readDateTime == DateTime.MinValue)
                {
                    return(null);
                }

                return(newRecord);
            }

            return(null);
        }
コード例 #2
0
        //Records have 2x records per transaction
        public static ControllerRecord[] ParseRecordFromRecord(byte[] recordPayload)
        {
            ControllerRecord[] newRecords = new ControllerRecord[2];

            //First Record
            //*******************************************

            newRecords[0]           = new ControllerRecord();
            newRecords[0].is10Digit = false;

            newRecords[0].cardID = (UInt32)WGTools.NetToUInt16(recordPayload, 0) + (UInt32)recordPayload[2] * 0x10000;

            if (newRecords[0].cardID == 22202125)
            {
                return(null);
            }

            newRecords[0].statusByte = recordPayload[3];
            newRecords[0].flagsByte  = (byte)((newRecords[0].statusByte >= 128) ? 0 : 1); //Scan Success? //num5  "Character"

            newRecords[0].readDateTime = WGTools.NetToDateTime32(recordPayload, 4);
            if (newRecords[0].readDateTime == DateTime.MinValue)
            {
                return(null);
            }

            //Check if Card Data Available
            if ((WGTools.NetToUInt64(recordPayload, 8) == 0xFFFFFFFFFFFFFFFF))
            {
                return(null);
            }

            //Get Record ID
            if ((WGTools.NetToUInt32(recordPayload, 8) != 0x00000000) && (WGTools.NetToUInt32(recordPayload, 8) != 0xFFFFFFFF))
            {
                newRecords[0].recordIndex = WGTools.NetToUInt32(recordPayload, 8);
            }

            //Record Local Time
            newRecords[0].localTime = DateTime.Now;

            if (newRecords[0].cardID == 25565535L)  //Special card ID. Not sure what this actually means
            {
                newRecords[0] = null;
            }


            //Second Record
            //*******************************************

            newRecords[1]           = new ControllerRecord();
            newRecords[1].is10Digit = false;

            newRecords[1].cardID = (UInt32)WGTools.NetToUInt16(recordPayload, 12) + (UInt32)recordPayload[14] * 0x10000;

            if (newRecords[1].cardID == 22202125)
            {
                newRecords[1] = null;
                return(newRecords);
            }

            newRecords[1].statusByte = recordPayload[15];
            newRecords[1].flagsByte  = (byte)((newRecords[1].statusByte >= 128) ? 0 : 1); //Scan Success? //num5  "Character"

            newRecords[1].readDateTime = WGTools.NetToDateTime32(recordPayload, 16);
            if (newRecords[1].readDateTime == DateTime.MinValue)
            {
                newRecords[1] = null;
                return(newRecords);
            }

            //Check if Card Data Available
            if (WGTools.NetToUInt64(recordPayload, 20) == 0xFFFFFFFFFFFFFFFF)
            {
                newRecords[1] = null;
                return(newRecords);
            }

            //Get Record ID
            if ((WGTools.NetToUInt32(recordPayload, 20) != 0x00000000) && (WGTools.NetToUInt32(recordPayload, 20) != 0xFFFFFFFF))
            {
                newRecords[1].recordIndex = WGTools.NetToUInt32(recordPayload, 20);
            }

            //Record Local Time
            newRecords[1].localTime = DateTime.Now;

            if (newRecords[1].cardID == 25565535L)  //Special card ID. Not sure what this actually means
            {
                newRecords[1] = null;
                return(newRecords);
            }


            return(newRecords);
        }