Esempio n. 1
0
 /// <summary>
 /// Gets the field.
 /// </summary>
 /// <param name="list">The list.</param>
 /// <param name="starting">The starting.</param>
 /// <param name="ending">The ending.</param>
 /// <param name="index">The index.</param>
 /// <param name="count">The count.</param>
 /// <returns></returns>
 public static string GetField(List<byte> list, string starting, string ending, int index, int count)
 {
     Encode enc = new Encode();
     enc.ToBinary(starting);
     int start = IndexOfBytes(list.ToArray(), enc.Encoded, index, count);
     if (start == -1)
     {
         return null;
     }
     start = start + enc.Encoded.Length;
     int end = -1;
     enc.ToBinary(ending);
     end = IndexOfBytes(list.ToArray(), enc.Encoded, start + 1, list.Count - start);
     if (end == -1)
     {
         return null;
     }
     List<byte> field = new List<byte>();
     for (int idx = start; idx < end; idx++)
     {
         field.Add(list[idx]);
     }
     Decode dec = new Decode();
     dec.ToReadable(field.ToArray());
     return dec.Decoded;
 }
Esempio n. 2
0
 /// <summary>
 /// Does the send.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="packet">The packet.</param>
 public static void DoSend(object sender, string packet)
 {
     SendEventArgs e = new SendEventArgs();
     e.Packet = packet;
     Encode enc = new Encode();
     enc.ToBinary(packet);
     e.RawStream = enc.Encoded.ToList();
     if (Sending != null)
     {
         Sending(sender, e);
     }
     else
     {
         Console.WriteLine(packet);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Gets the index.
 /// </summary>
 /// <param name="list">The list.</param>
 /// <param name="starting">The starting.</param>
 /// <param name="ending">The ending.</param>
 /// <param name="index">The index.</param>
 /// <param name="count">The count.</param>
 /// <returns></returns>
 public static int GetIndex(List<byte> list, string starting, string ending, int index, int count)
 {
     Encode enc = new Encode();
     enc.ToBinary(starting);
     int start = IndexOfBytes(list.ToArray(), enc.Encoded, index, count);
     if (start == -1)
     {
         return -1;
     }
     enc.ToBinary(ending);
     int end = IndexOfBytes(list.ToArray(), enc.Encoded, start + 1, list.Count - start);
     if (end == -1)
     {
         return -1;
     }
     return start;
 }
Esempio n. 4
0
 /// <summary>
 /// Gets the length.
 /// </summary>
 /// <param name="list">The list.</param>
 /// <param name="starting">The starting.</param>
 /// <param name="ending">The ending.</param>
 /// <returns></returns>
 public static int GetLength(List<byte> list, string starting, string ending)
 {
     Encode enc = new Encode();
     enc.ToBinary(starting);
     int start = IndexOfBytes(list.ToArray(), enc.Encoded, 0, list.Count);
     if (start == -1)
     {
         return -1;
     }
     enc.ToBinary(ending);
     int end = IndexOfBytes(list.ToArray(), enc.Encoded, start + 1, list.Count - start);
     if (end == -1)
     {
         return -1;
     }
     end = end + enc.Encoded.Length - 1;
     return end - start + 1;
 }
Esempio n. 5
0
 /// <summary>
 /// To compute checksum.
 /// </summary>
 /// <param name="packet">The packet.</param>
 public static void ToCompute(string packet)
 {
     if (_table == null)
     {
         Initialize();
     }
     Encode enc = new Encode();
     enc.ToBinary(packet);
     ushort crc = ComputeChecksum(enc.Encoded, 0, enc.Encoded.Length);
     _binaryValue = ConvertCRC16ToFourBytes(crc);
     Decode trn = new Decode();
     trn.ToReadable(BinaryValue);
     _readableValue = trn.Decoded;
 }