Example #1
0
 //Get the E0 uncompressed EEG Packets
 private static void processE0()
 {
     if (debugview)
     {
         System.Diagnostics.Debug.WriteLine("AfterClean:"); for (int b = 0; b < pos; b++)
         {
             System.Diagnostics.Debug.Write(buffer[b].ToString("X2") + " ");
         }
     }
     byte[] EEG = new byte[5];
     for (int a = 0; a < 5; a++)
     {
         EEG[a] = buffer[posAct + a];
     }
     lastEEG = MuseDirect.Get10BitNums(EEG);
     byte[] buf2 = new byte[BUFFSIZE];
     posAct += 5;
     Buffer.BlockCopy(buffer, posAct, buf2, 0, (pos - posAct));
     Buffer.BlockCopy(buf2, 0, buffer, 0, BUFFSIZE);
     pos    = pos - posAct;
     posAct = 0;
 }
Example #2
0
        //Get the C0 Compressed EEG Packets
        private static void processC0()
        {
            if (buffer[posAct] == 0xC0 && pos > (posAct + 8) && !GetC0)
            {
                if (debugview)
                {
                    System.Diagnostics.Debug.WriteLine("Full:"); for (int b = posAct; b < pos; b++)
                    {
                        System.Diagnostics.Debug.Write(buffer[b].ToString("X2") + " ");
                    }
                }

                byte[] cc = new byte[5];
                for (int a = 0; a < 5; a++)
                {
                    cc[a] = buffer[posAct + 1 + a];
                }
                if (debugview)
                {
                    System.Diagnostics.Debug.WriteLine("cc:"); for (int b = 0; b < 5; b++)
                    {
                        System.Diagnostics.Debug.Write(cc[b].ToString("X2") + " ");
                    }
                }


                quantiz = MuseDirect.Get10BitQuants(cc);
                median  = MuseDirect.Get10BitMedian(cc);

                byte[] ll = new byte[2];
                ll[0] = buffer[posAct + 6];
                ll[1] = buffer[posAct + 7];
                if (debugview)
                {
                    System.Diagnostics.Debug.WriteLine("ll:"); for (int b = 0; b < 2; b++)
                    {
                        System.Diagnostics.Debug.Write(ll[b].ToString("X2") + " ");
                    }
                }
                bits = MuseDirect.GetNumbits(ll);
                int bt = 0;
                bt = bits / 8;
                if ((bits % 8) > 0)
                {
                    bt++;
                }
                NumBytes = bt;
                posAct   = posAct + 8;
                GetC0    = true;
            }
            if (GetC0 && pos > (NumBytes + posAct))
            {
                byte[] bts = new byte[NumBytes];
                for (int a = 0; a < NumBytes; a++)
                {
                    bts[a] = buffer[posAct + a];
                }
                posAct += NumBytes;
                if (debugview)
                {
                    System.Diagnostics.Debug.WriteLine("bts:"); for (int b = 0; b < NumBytes; b++)
                    {
                        System.Diagnostics.Debug.Write(bts[b].ToString("X2") + " ");
                    }
                }

                int[,] res = MuseDirect.ParsePacket(bts, lastEEG, median, quantiz);

                // Do here what ever you want in your code with the packets in the array res

                for (int a = 0; a < 4; a++)
                {
                    lastEEG[a] = res[a, 15];
                }
                C0count++;
                GetC0 = false;
                byte[] buf2 = new byte[BUFFSIZE];
                Buffer.BlockCopy(buffer, posAct, buf2, 0, (pos - posAct));
                Buffer.BlockCopy(buf2, 0, buffer, 0, BUFFSIZE);
                pos    = pos - posAct;
                posAct = 0;
            }
        }