Ejemplo n.º 1
0
        private static byte[] Encode(String imei, bool useSerialNo, int serialNo, byte[] command, byte[] content, int lenth)
        {
            MemoryStream memoryStream = new MemoryStream();

            try
            {
                memoryStream.Write(command, 0, command.Length);
                memoryStream.Write(new byte[] { 0x00, (byte)lenth }, 0, 2);
                if (useSerialNo)
                {
                    memoryStream.Write(BytesUtils.Short2Bytes(serialNo), 0, 2);
                }
                else
                {
                    memoryStream.Write(new byte[] { 0x00, 0x01 }, 0, 2);
                }
                byte[] imeiBytes = EncodeImei(imei);
                memoryStream.Write(imeiBytes, 0, imeiBytes.Length);
                memoryStream.Write(content, 0, content.Length);
                return(memoryStream.ToArray());
            }
            finally
            {
                memoryStream.Close();
            }
        }
Ejemplo n.º 2
0
        private static byte[] Encode(String imei, bool useSerialNo, int serialNo, byte[] command, byte protocol, byte[] content)
        {
            MemoryStream memoryStream = new MemoryStream();

            try
            {
                memoryStream.Write(command, 0, command.Length);
                int packageSize = Math.Min(0x10, 32767);
                memoryStream.Write(new byte[] { 0x00, (byte)packageSize }, 0, 2);
                if (useSerialNo)
                {
                    memoryStream.Write(BytesUtils.Short2Bytes(serialNo), 0, 2);
                }
                else
                {
                    memoryStream.Write(new byte[] { 0x00, 0x01 }, 0, 2);
                }
                byte[] imeiBytes = EncodeImei(imei);
                memoryStream.Write(imeiBytes, 0, imeiBytes.Length);
                memoryStream.WriteByte(protocol);
                memoryStream.Write(content, 0, content.Length);
                return(memoryStream.ToArray());
            }
            finally
            {
                memoryStream.Close();
            }
        }
Ejemplo n.º 3
0
 public static string Decode(byte[] bytes, int index)
 {
     if (bytes != null && index > 0 && (bytes.Length - index) >= 8)
     {
         string str = BytesUtils.Bytes2HexString(bytes, index);
         return(str.Substring(1, 15));
     }
     throw new ArgumentException("invalid bytes length & index!");
 }
Ejemplo n.º 4
0
        public static DateTime getGTM0Date(byte[] bytes, int startIndex)
        {
            String datetime = BytesUtils.GetDateStr(bytes, startIndex);
            int    year     = Convert.ToInt32(datetime.Substring(0, 4));
            int    month    = Convert.ToInt32(datetime.Substring(4, 2));
            int    day      = Convert.ToInt32(datetime.Substring(6, 2));
            int    hour     = Convert.ToInt32(datetime.Substring(8, 2));
            int    minutes  = Convert.ToInt32(datetime.Substring(10, 2));
            int    seconds  = Convert.ToInt32(datetime.Substring(12, 2));

            return(new DateTime(year, month, day, hour, minutes, seconds, DateTimeKind.Utc));
        }
Ejemplo n.º 5
0
 private static byte[] EncodeImei(String imei)
 {
     return(BytesUtils.HexString2Bytes("0" + imei));
 }
Ejemplo n.º 6
0
 public static string GetDateStr(byte[] data, int startIndex)
 {
     byte[] dateBytes = new byte[6];
     Array.Copy(data, startIndex, dateBytes, 0, 6);
     return("20" + BytesUtils.Bytes2HexString(dateBytes, 0));
 }