Esempio n. 1
0
 bool ProcessBinaryPacket(byte[] buffer, ref int from)
 {
     if (m_IMEI == 0)
     {
         m_IMEI = BIConverter.ToInt64(buffer, from + 2);
         if (!IMEIIsValid())
         {
             return(false);
         }
     }
     m_SeqID = BIConverter.ToUInt16(buffer, from + 10);
     from   += 12;
     return(true);
 }
Esempio n. 2
0
    ////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////
    public override bool ProcessBuffer(byte[] buffer, int size)      //если вернет false - разорвать соединение
    {
        string str = Encoding.ASCII.GetString(buffer, 0, size);

        LogEvent(LogLevel.DEBUG, "<< " + str);

        if (buffer[0] != 0xFE)
        {
            string[] packets = str.Split('\n');
            for (int i = 0; i < packets.Length; i++)
            {
                if (packets[i].Length > 2 && !ProcessPacket(packets[i]))
                {
                    return(false);
                }
            }
        }
        else
        {
            int from = 0;
            while (from < size)
            {
                if (!ProcessBinaryPacket(buffer, ref from))
                {
                    return(false);
                }
            }
        }
        byte[] reply = new byte[12] {
            0xFE, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        };
        BIConverter.GetBytes(m_IMEI).CopyTo(reply, 2);
        BIConverter.GetBytes(m_SeqID).CopyTo(reply, 10);
        Send(reply, reply.Length);
        return(true);
    }
Esempio n. 3
0
    ////////////////////////////////////////////////////////////////////////
    bool ProcessRecord(byte[] buffer, ref int from)
    {
        if (buffer[from++] != 0x78 || buffer[from++] != 0x78)
        {
            return(false);
        }

        int len = buffer[from++];

        if (from + len + 2 > buffer.Length)
        {
            return(false);
        }

        if (buffer[from + len] != 13 || buffer[from + len + 1] != 10)
        {
            return(false);
        }

        int crc = GetCrc16(buffer, from - 1, len - 1);

        if (crc != BIConverter.ToUInt16(buffer, from + len - 2))
        {
            return(false);
        }

        byte pn = buffer[from++];
        int  sn = BitConverter.ToUInt16(buffer, from + len - 5);

        switch (pn)
        {
        case 1:    //login
        {
            m_IMEI = GetNumberFromHex(buffer, from, 8);
            if (!IMEIIsValid())
            {
                return(false);
            }

            byte[] reply = new byte[10] {
                0x78, 0x78, 0x05, pn, (byte)(sn >> 8), (byte)sn, 0x00, 0x00, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);

            break;
        }

        case 0x10:    //GPS
        {
            TrackerPacket packet = new TrackerPacket(m_IMEI);
            if (buffer[from] > 0)
            {
                packet.m_Time = CTime.GetTime(new DateTime(2000 + buffer[from], buffer[from + 1], buffer[from + 2], buffer[from + 3], buffer[from + 4], buffer[from + 5]));
            }
            packet.m_SatteliteCount = (byte)(((buffer[from + 16] & 16) == 0) ? 0 : buffer[from + 6] & 0x0F);
            packet.m_fLat           = (float)(BIConverter.ToUInt32(buffer, from + 7) / 1800000.0 * (((buffer[from + 16] & 4) == 0) ? -1 : 1));
            packet.m_fLng           = (float)(BIConverter.ToUInt32(buffer, from + 11) / 1800000.0 * (((buffer[from + 16] & 8) == 0) ? 1 : -1));
            packet.m_Speed          = buffer[from + 15];
            packet.m_Direction      = (ushort)(BIConverter.ToUInt16(buffer, from + 16) & 0x3FF);
            if (Math.Abs(CTime.GetTime(DateTime.UtcNow) - packet.m_Time) < 600)
            {
                packet.SetInput("ACC", m_Volt);
            }
            if (!PushPacket(packet))
            {
                return(false);
            }
            break;
        }

        case 0x12:    //GPS
        {
            TrackerPacket packet = new TrackerPacket(m_IMEI);
            if (buffer[from] > 0)
            {
                packet.m_Time = CTime.GetTime(new DateTime(2000 + buffer[from], buffer[from + 1], buffer[from + 2], buffer[from + 3], buffer[from + 4], buffer[from + 5]));
            }
            packet.m_SatteliteCount = (byte)(((buffer[from + 16] & 16) == 0) ? 0 : buffer[from + 6] & 0x0F);
            packet.m_fLat           = (float)(BIConverter.ToUInt32(buffer, from + 7) / 1800000.0 * (((buffer[from + 16] & 4) == 0) ? -1 : 1));
            packet.m_fLng           = (float)(BIConverter.ToUInt32(buffer, from + 11) / 1800000.0 * (((buffer[from + 16] & 8) == 0) ? 1 : -1));
            packet.m_Speed          = buffer[from + 15];
            packet.m_Direction      = (ushort)(BIConverter.ToUInt16(buffer, from + 16) & 0x3FF);
            if (Math.Abs(CTime.GetTime(DateTime.UtcNow) - packet.m_Time) < 600)
            {
                packet.SetInput("ACC", m_Volt);
            }
            if (!PushPacket(packet))
            {
                return(false);
            }
            break;
        }

        case 0x13:    //Status package
        {
            switch (buffer[from + 1])
            {
            case 1: m_Volt = 5; break;

            case 2: m_Volt = 10; break;

            case 3: m_Volt = 30; break;

            case 4: m_Volt = 50; break;

            case 5: m_Volt = 75; break;

            case 6: m_Volt = 100; break;

            default: m_Volt = 0; break;
            }

            byte[] reply = new byte[10] {
                0x78, 0x78, 0x05, pn, (byte)(sn >> 8), (byte)sn, 0x00, 0x00, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            break;
        }

        case 0x16:    //GPS LBS status combined package
        {
            byte[] reply = new byte[15] {
                0x78, 0x78, 11, pn, 0, 0x00, 0x00, 0x00, 0x01, (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);

            m_Logger.Push(LogLevel.DEBUG, 0, "GPS LBS status combined package");
            break;
        }

        case 0x17:    //LBS telephone number address searching package
        {
            byte[] reply = new byte[15] {
                0x78, 0x78, 11, pn, 0, 0x00, 0x00, 0x00, 0x01, (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            m_Logger.Push(LogLevel.DEBUG, 0, "LBS telephone number address searching package");
            break;
        }

        case 0x18:    //LBS extension package
        {
            TrackerPacket packet = new TrackerPacket(m_IMEI);
            if (buffer[from] > 0)
            {
                packet.m_Time = CTime.GetTime(new DateTime(2000 + buffer[from], buffer[from + 1], buffer[from + 2], buffer[from + 3], buffer[from + 4], buffer[from + 5]));
            }
            packet.SetGSMInfo(BIConverter.ToUInt16(buffer, from + 6), buffer[from + 8], BIConverter.ToUInt16(buffer, from + 9), BIConverter.ToUInt16(buffer, from + 12));
            if (Math.Abs(CTime.GetTime(DateTime.UtcNow) - packet.m_Time) < 600)
            {
                packet.SetInput("ACC", m_Volt);
            }
            if (!PushPacket(packet))
            {
                return(false);
            }
            break;
        }

        case 0x19:    //LBS status combined package
        {
            byte[] reply = new byte[15] {
                0x78, 0x78, 11, pn, 0, 0x00, 0x00, 0x00, 0x01, (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            m_Logger.Push(LogLevel.DEBUG, 0, "LBS status combined package");
            break;
        }

        case 0x1A:    //GPS telephone number address searching package
        {
            byte[] reply = new byte[15] {
                0x78, 0x78, 11, pn, 0, 0x00, 0x00, 0x00, 0x01, (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            m_Logger.Push(LogLevel.DEBUG, 0, "GPS telephone number address searching package");
            break;
        }

        case 0x1F:    //Time Synchronization packets
        {
            long   time  = CTime.GetTime(DateTime.UtcNow);
            byte[] reply = new byte[14] {
                0x78, 0x78, 10, pn, (byte)(time >> 24), (byte)(time >> 16), (byte)(time >> 8), (byte)(time), (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            m_Logger.Push(LogLevel.DEBUG, 0, "Time Synchronization package ");
            break;
        }

        case 0x80:    //Command Package
        case 0x81:    //
        {
            /*byte[] reply = new byte[] { 0x78, 0x78, 0x1A, pn, 0x12, 0x00, 0x46, 0x04, 0x46, 0x50, 0x41, 0x52, 0x41, 0x4D, 0x3D, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x21, 0x00, 0x02, 0x00, 0x6D, 0x72, 0x7D, 0x0D, 0x0A };
             * crc = GetCrc16(reply, 2, reply.Length - 6);
             * reply[reply.Length - 4] = (byte)(crc >> 8);
             * reply[reply.Length - 3] = (byte)crc;
             * Send(reply, reply.Length);*/
            break;
        }

        default:
        {
            m_Logger.Push(LogLevel.DEBUG, 0, "unknown package " + pn);
            break;
        }
        }
        from += len - 1; //13 10
        from += 2;       //13 10
        return(true);
    }
Esempio n. 4
0
    byte[] GetPacket(TrackerPacket point)
    {
        int i = 0;

        byte[] buf = new byte[45 + 20];
        for (int j = 0; j < buf.Length; j++)
        {
            buf[j] = 0;
        }

        buf[i++] = 0x29;
        buf[i++] = 0x29;
        buf[i++] = 0x80;
        i       += 2; // length

        uint imei = (uint)(m_Tracker.m_IMEI - 14100000000);

        for (int k = 0; k < 4; k++)
        {
            buf[i + 3 - k] = (byte)(imei % 100);
            if (k != 2)
            {
                buf[i + 3 - k] |= 0x80;
            }
            imei = imei / 100;
        }
        i += 4;

        DateTime dt = CTime.GetTime(point.m_Time + 3600 * 2);

        buf[i++] = BCDConverter.GetBytes(dt.Year - 2000, 1)[0];
        buf[i++] = BCDConverter.GetBytes(dt.Month, 1)[0];
        buf[i++] = BCDConverter.GetBytes(dt.Day, 1)[0];
        buf[i++] = BCDConverter.GetBytes(dt.Hour, 1)[0];
        buf[i++] = BCDConverter.GetBytes(dt.Minute, 1)[0];
        buf[i++] = BCDConverter.GetBytes(dt.Second, 1)[0];

        GetCoord(point.m_fLat).CopyTo(buf, i); i += 4;
        GetCoord(point.m_fLng).CopyTo(buf, i); i += 4;

        BCDConverter.GetBytes(point.m_Speed, 2).CopyTo(buf, i); i     += 2;
        BCDConverter.GetBytes(point.m_Direction, 2).CopyTo(buf, i); i += 2;

        decimal odo = 0, ignition = 0, oilcut = 0, pwr = 12000;
        decimal din1 = 0, din2 = 0, din3 = 0, din4 = 0;

        point.GetInput("DIN6", out ignition);
        point.GetInput("DIN7", out oilcut);
        point.GetInput("PWR", out pwr);
        point.GetInput("ODO", out odo);
        point.GetInput("DIN1", out din1);
        point.GetInput("DIN2", out din2);
        point.GetInput("DIN3", out din3);
        point.GetInput("DIN4", out din4);

        BIConverter.GetBytes((int)odo).CopyTo(buf, i);
        buf[i++] = (byte)(((pwr == 0) ? 16 : (pwr > 3000) ? 24 : 8) + ((point.IsFixed(false) ? 224 : 0)));
        i       += 3;

        buf[i++] = (byte)(1 +
                          ((oilcut > 0) ? 0 : 4) +
                          ((din1 > 0) ? 0 : 8) +
                          ((din2 > 0) ? 0 : 16) +
                          ((din3 > 0) ? 0 : 32) +
                          ((din4 > 0) ? 0 : 64) +
                          ((ignition > 0) ? 0 : 128)); //ign, pwr, oil cut
        buf[i++] = 0xFC;                               //alarms
        buf[i++] = 0x36;                               // 32;//tcp
        buf[i++] = 0x00;

        buf[i++] = 0x00;
        buf[i++] = 0x78;
        buf[i++] = 0x00;
        buf[i++] = 0x00;
        buf[i++] = 0x00;
        buf[i++] = 0x00;
        buf[i++] = 0x3C;
        buf[i++] = 0x00;

        decimal fuel = 0;

        if (point.GetInput("FUEL", out fuel))
        {
            string data = fuel.ToString("000.00").Replace(",", ".");
            BIConverter.GetBytes((ushort)(data.Length + 2)).CopyTo(buf, i); i += 2;
            BIConverter.GetBytes((ushort)0x0023).CopyTo(buf, i); i            += 2;
            Encoding.ASCII.GetBytes(data).CopyTo(buf, i);
            i += data.Length;
        }
        if (point.GetInput("AIN5", out fuel))
        {
            BIConverter.GetBytes((ushort)4).CopyTo(buf, i); i      += 2;
            BIConverter.GetBytes((ushort)0x002D).CopyTo(buf, i); i += 2;
            BIConverter.GetBytes((ushort)fuel).CopyTo(buf, i); i   += 2;
        }

        BIConverter.GetBytes((ushort)(i - 3)).CopyTo(buf, 3);
        buf[i++] = GetCRC(buf, 0, i);
        buf[i++] = 0x0D;

        byte[] res = new byte[i];

        string str = "<<";

        for (int j = 0; j < i; j++)
        {
            res[j] = buf[j];
            str   += " " + buf[j].ToString("X2");
        }
        m_Logger.Push(LogLevel.INFO, 0, str);

        return(res);
    }
Esempio n. 5
0
    ////////////////////////////////////////////////////////////////////////
    bool ProcessRecord(byte[] buffer, ref int from)
    {
        bool len2bytes = buffer[from] == 0x79;

        if ((buffer[from] != 0x78 && buffer[from] != 0x79) || buffer[from + 1] != buffer[from])
        {
            return(false);
        }
        from += 2;

        int len = len2bytes ? (BIConverter.ToUInt16(buffer, from)) : buffer[from];

        from += len2bytes ? 2 : 1;

        if (from + len + 2 > buffer.Length)
        {
            return(false);
        }

        if (buffer[from + len] != 13 || buffer[from + len + 1] != 10)
        {
            return(false);
        }

        int crc = GetCrc16(buffer, from - (len2bytes ? 2 : 1), len - 2 + (len2bytes ? 2 : 1));

        if (crc != BIConverter.ToUInt16(buffer, from + len - 2))
        {
            return(false);
        }

        byte pn = buffer[from++];
        int  sn = BIConverter.ToUInt16(buffer, from + len - 5);

        switch (pn)
        {
        case 1:    //login
        {
            m_IMEI = GetNumberFromHex(buffer, from, 8);
            if (!IMEIIsValid())
            {
                return(false);
            }

            byte[] reply = new byte[10] {
                0x78, 0x78, 0x05, pn, (byte)(sn >> 8), (byte)sn, 0x00, 0x00, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            break;
        }

        case 0x10:    //GPS
        {
            TrackerPacket packet = new TrackerPacket(m_IMEI);
            if (buffer[from] > 0)
            {
                packet.m_Time = CTime.GetTime(new DateTime(2000 + buffer[from], buffer[from + 1], buffer[from + 2], buffer[from + 3], buffer[from + 4], buffer[from + 5]));
            }
            packet.m_SatteliteCount = (byte)(((buffer[from + 16] & 16) == 0) ? 0 : buffer[from + 6] & 0x0F);
            packet.m_fLat           = (float)(BIConverter.ToUInt32(buffer, from + 7) / 1800000.0 * (((buffer[from + 16] & 4) == 0) ? -1 : 1));
            packet.m_fLng           = (float)(BIConverter.ToUInt32(buffer, from + 11) / 1800000.0 * (((buffer[from + 16] & 8) == 0) ? 1 : -1));
            packet.m_Speed          = buffer[from + 15];
            ushort dir = BIConverter.ToUInt16(buffer, from + 16);
            packet.m_Direction = (ushort)(dir & 0x3FF);

            PutExtData2Packet(packet);

            if (!PushPacket(packet))
            {
                return(false);
            }
            break;
        }

        case 0x12:    //location data packet
        {
            TrackerPacket packet = new TrackerPacket(m_IMEI);
            if (buffer[from] > 0)
            {
                packet.m_Time = CTime.GetTime(new DateTime(2000 + buffer[from], buffer[from + 1], buffer[from + 2], buffer[from + 3], buffer[from + 4], buffer[from + 5]));
            }
            packet.m_SatteliteCount = (byte)(((buffer[from + 16] & 16) == 0) ? 0 : buffer[from + 6] & 0x0F);
            packet.m_fLat           = (float)(BIConverter.ToUInt32(buffer, from + 7) / 1800000.0 * (((buffer[from + 16] & 4) == 0) ? -1 : 1));
            packet.m_fLng           = (float)(BIConverter.ToUInt32(buffer, from + 11) / 1800000.0 * (((buffer[from + 16] & 8) == 0) ? 1 : -1));
            packet.m_Speed          = buffer[from + 15];
            ushort dir = BIConverter.ToUInt16(buffer, from + 16);
            packet.m_Direction = (ushort)(dir & 0x3FF);

            PutExtData2Packet(packet);

            if (!PushPacket(packet))
            {
                return(false);
            }
            break;
        }

        case 0x13:    //Status package
        {
            m_LastStatusByte = buffer[from];
            switch (buffer[from + 1])
            {
            case 1: m_fAcc = 5; break;

            case 2: m_fAcc = 10; break;

            case 3: m_fAcc = 30; break;

            case 4: m_fAcc = 50; break;

            case 5: m_fAcc = 75; break;

            case 6: m_fAcc = 100; break;

            default: m_fAcc = 0; break;
            }

            byte[] reply = new byte[10] {
                0x78, 0x78, 0x05, pn, (byte)(sn >> 8), (byte)sn, 0x00, 0x00, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            break;
        }

        case 0x15:    //command reply
        {
            string str = Encoding.ASCII.GetString(buffer, from + 5, buffer[from] - 4);
            break;
        }

        case 0x16:    //GPS LBS status combined package
        {
            byte[] reply = new byte[15] {
                0x78, 0x78, 11, pn, 0, 0x00, 0x00, 0x00, 0x01, (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);

            TrackerPacket packet = new TrackerPacket(m_IMEI);
            if (buffer[from] > 0)
            {
                packet.m_Time = CTime.GetTime(new DateTime(2000 + buffer[from], buffer[from + 1], buffer[from + 2], buffer[from + 3], buffer[from + 4], buffer[from + 5]));
            }
            packet.m_SatteliteCount = (byte)(((buffer[from + 16] & 16) == 0) ? 0 : buffer[from + 6] & 0x0F);
            packet.m_fLat           = (float)(BIConverter.ToUInt32(buffer, from + 7) / 1800000.0 * (((buffer[from + 16] & 4) == 0) ? -1 : 1));
            packet.m_fLng           = (float)(BIConverter.ToUInt32(buffer, from + 11) / 1800000.0 * (((buffer[from + 16] & 8) == 0) ? 1 : -1));
            packet.m_Speed          = buffer[from + 15];
            ushort dir = BIConverter.ToUInt16(buffer, from + 16);
            packet.m_Direction = (ushort)(dir & 0x3FF);

            byte alarm = buffer[from + 30];
            if (alarm == 1)    //SOS
            {
                m_iAlarm = 1;
            }
            PutExtData2Packet(packet);
            m_iAlarm = 0;

            if (!PushPacket(packet))
            {
                return(false);
            }
            break;
        }

        case 0x17:    //LBS telephone number address searching package
        {
            byte[] reply = new byte[15] {
                0x78, 0x78, 11, pn, 0, 0x00, 0x00, 0x00, 0x01, (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            m_Logger.Push(LogLevel.DEBUG, 0, "LBS telephone number address searching package");
            break;
        }

        case 0x18:    //LBS extension package
        {
            break;
        }

        case 0x19:    //LBS status combined package
        {
            //StoreEvent(CEvent.EventType.ALARM, CTime.GetTime(DateTime.UtcNow), "");

            byte[] reply = new byte[15] {
                0x78, 0x78, 11, pn, 0, 0x00, 0x00, 0x00, 0x01, (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            m_Logger.Push(LogLevel.DEBUG, 0, "LBS status combined package");
            break;
        }

        case 0x1A:    //GPS telephone number address searching package
        {
            byte[] reply = new byte[15] {
                0x78, 0x78, 11, pn, 0, 0x00, 0x00, 0x00, 0x01, (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            m_Logger.Push(LogLevel.DEBUG, 0, "GPS telephone number address searching package");
            break;
        }

        case 0x1F:    //Time Synchronization packets
        {
            long   time  = CTime.GetTime(DateTime.UtcNow);
            byte[] reply = new byte[14] {
                0x78, 0x78, 10, pn, (byte)(time >> 24), (byte)(time >> 16), (byte)(time >> 8), (byte)(time), (byte)(sn >> 8), (byte)sn, 0, 0, 0x0D, 0x0A
            };
            crc = GetCrc16(reply, 2, reply.Length - 6);
            reply[reply.Length - 4] = (byte)(crc >> 8);
            reply[reply.Length - 3] = (byte)crc;
            Send(reply, reply.Length);
            m_Logger.Push(LogLevel.DEBUG, 0, "Time Synchronization package ");
            break;
        }

        case 0x80:    //Command Package
        case 0x81:    //
        {
            //need reply
            break;
        }

        case 0x8a:    //?????
        {
            break;
        }

        case 0x94:    //?????
        {
            byte id = buffer[from];
            int  k  = from + 1;
            switch (id)
            {
            case 0x00:        //power
            {
                m_fPwr = (float)(BIConverter.ToUInt16(buffer, k) / 100.0);
                k     += 2;
                break;
            }

            case 0x04:        //ascii content ALM1=75;ALM2=D5;ALM3=5F;STA1=40;DYD=01;SOS=+917226938881,+919904038880,+917226038882;CENTER=;FENCE=Fence,OFF,0,0.000000,0.000000,300,IN or OUT,1;
            {
                string str = Encoding.ASCII.GetString(buffer, k, len - 6);
                LogEvent(LogLevel.DEBUG, "0x94:     " + str);

                string[] parts = str.Split(new char[] { ';' });
                for (int i = 0; i < parts.Length; i++)
                {
                    string[] s = parts[i].Split(new char[] { '=' });
                    if (s.Length == 2)
                    {
                        switch (s[0])
                        {
                        /*case "ALM1":
                         *  m_iAlarm = m_iAlarm & 0xFFFF00;
                         *  m_iAlarm = m_iAlarm | int.Parse(s[1], System.Globalization.NumberStyles.HexNumber, null);
                         *  break;
                         * case "ALM2":
                         *  m_iAlarm = m_iAlarm & 0xFF00FF;
                         *  m_iAlarm = m_iAlarm | (int.Parse(s[1], System.Globalization.NumberStyles.HexNumber, null) << 8);
                         *  break;
                         * case "ALM3":
                         *  m_iAlarm = m_iAlarm & 0x00FFFF;
                         *  m_iAlarm = m_iAlarm | (int.Parse(s[1], System.Globalization.NumberStyles.HexNumber, null) << 16);
                         *  break;*/
                        case "STA1":
                            m_iStatus = m_iStatus & 0xFFFF00;
                            m_iStatus = m_iStatus | int.Parse(s[1], System.Globalization.NumberStyles.HexNumber, null);
                            break;

                        case "DYD":
                            m_iStatus = m_iStatus & 0xFF00FF;
                            m_iStatus = m_iStatus | (int.Parse(s[1], System.Globalization.NumberStyles.HexNumber, null) << 8);
                            break;
                        }
                    }
                }


                k += len - 6;
                break;
            }

            case 0x05:        //door status
            {
                m_fDoor = (float)buffer[k];
                k      += 1;
                break;
            }

            default:
                break;
            }
            break;
        }

        default:
        {
            m_Logger.Push(LogLevel.DEBUG, 0, "unknown package " + pn);
            break;
        }
        }
        from += len - 1; //13 10
        from += 2;       //13 10
        return(true);
    }