IEnumerable<IEnumerable<byte>> GetPackets(byte[] data)
{
bool packet = false;
for (int i = 0; i < data.Length; i++)
{
if (data[i] == 126)
{
packet = !packet;
if (packet)
{
yield return PacketEnumerable(data, i);
}
}
}
yield break;
}
IEnumerable<byte> PacketEnumerable(byte[] data, int index)
{
yield return data[index];
do
{
yield return data[++index];
}
while (data[index] != 126);
yield break;
}