Exemplo n.º 1
0
        public TimeInfo(byte[] t)
        {
            this.year = 2000 + ((t[7] >> 2) & 0x3F);
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
            {
                this.MONTH_DAYS[1] = 29;
            }
            this.day_offset = ((t[7] & 0x3) << 7) | ((t[8] >> 1) & 0x7F);
            for (this.month = 0; day_offset > 0; ++this.month)
            {
                if (day_offset - MONTH_DAYS[this.month] > 0)
                {
                    day_offset -= MONTH_DAYS[this.month];
                }
                else
                {
                    ++this.month;
                    break;
                }
            }
            this.hour          = ((t[8] & 0x1) << 4) | (t[9] >> 4) & 0xF;
            this.minute        = ((t[9] & 0xF) << 2) | ((t[10] >> 6) & 0x3);
            this.second        = (t[10] & 0x3F);
            this.satelliteInfo = new BD_GPS(t);
            int usecond = (int)(BitConverter.ToUInt32(t, 11) / 192);

            this.millisecond = usecond / 1000;//修改
            this.microsecond = usecond % 1000;

            if (this.year > 0 &&
                this.month >= 1 && this.month <= 12 &&
                this.day_offset > 0 && this.day_offset <= 31 &&
                this.hour >= 0 && this.hour <= 24 &&
                this.minute >= 0 && this.minute <= 60 &&
                this.second >= 0 && this.second <= 60)
            {
                DateTime dt_org = new DateTime(year, month, day_offset, hour, minute, second);
                DateTime dt     = dt_org.AddSeconds(1);
                this.year       = dt.Year;
                this.month      = dt.Month;
                this.day_offset = dt.Day;
                this.hour       = dt.Hour;
                this.minute     = dt.Minute;
                this.second     = dt.Second;
            }
        }
Exemplo n.º 2
0
        public TimeInfo(byte[] t)
        {
            this.year = 2000 + ((t[7] >> 2) & 0x3F);
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
            {
                this.MONTH_DAYS[1] = 29;
            }
            this.day_offset = ((t[7] & 0x3) << 7) | ((t[8] >> 1) & 0x7F);
            for (this.month = 0; day_offset > 0; ++this.month)
            {
                if (day_offset - MONTH_DAYS[this.month] > 0)
                {
                    day_offset -= MONTH_DAYS[this.month];
                }
                else
                {
                    ++this.month;
                    break;
                }
            }
            this.hour          = ((t[8] & 0x1) << 4) | (t[9] >> 4) & 0xF;
            this.minute        = ((t[9] & 0xF) << 2) | ((t[10] >> 6) & 0x3);
            this.second        = (t[10] & 0x3F);
            this.satelliteInfo = new BD_GPS(t);
            int nanosecond = ((t[11] << 24) + (t[12] << 16) + (t[13] << 8) + t[14]) / 192;

            this.millisecond = nanosecond / 1000;
            this.microsecond = nanosecond % 1000;

            if (this.year > 0 &&
                this.month >= 1 && this.month <= 12 &&
                this.day_offset > 0 && this.day_offset <= 31 &&
                this.hour >= 0 && this.hour <= 24 &&
                this.minute >= 0 && this.minute <= 60 &&
                this.second >= 0 && this.second <= 60)
            {
                int      AddSecond = t[1] == 2 ? 2:1;
                DateTime dt        = new DateTime(year, month, day_offset, hour, minute, second).AddSeconds(AddSecond);
                this.year       = dt.Year;
                this.month      = dt.Month;
                this.day_offset = dt.Day;
                this.hour       = dt.Hour;
                this.minute     = dt.Minute;
                this.second     = dt.Second;
            }
        }