void displaySignalText() { RawOpenVibeSignal s = lastSignal; StringBuilder sb = new StringBuilder(); for (int i = 0; i < lastSignal.samples; i++) { sb.AppendLine("Sample" + i + "\t"); for (int j = 0; j < lastSignal.channels; j++) { try { sb.AppendLine("Channel" + j).Append(lastSignal.signalMatrix[i, j]); } catch { Debug.Log("i:" + i + "-j:" + j); } } } // Debug.Log(sb.ToString()); }
public double readSocket() { if (!socketReady) return 0; // TODO if (theStream.DataAvailable) { // read header once if (testHeader) { readHeader(); } if (testSignal) { // raw signal data // [nSamples x nChannels] // all channels for one sample are sent in a sequence, then all channels of the next sample // create a signal object to send it to another RawOpenVibeSignal newSignal = new RawOpenVibeSignal(); newSignal.samples = testSampleCount; newSignal.channels = testChannelCount; double[,] newMatrix = new double[testSampleCount,testChannelCount]; byte[] buffer = new byte[testSampleChannelSize]; theStream.Read(buffer, 0, testSampleChannelSize); int row = 0; int col = 0; for (int i = 0; i < testSampleCount * testChannelCount * (sizeof(double)); i = i + (sizeof(double) * testChannelCount)) { for (int j = 0; j < testChannelCount * sizeof(double); j = j + sizeof(double)) { byte[] temp = new byte[8]; for(int k = 0; k < 8; k++) { temp[k] = buffer[i + j + k]; } if (BitConverter.IsLittleEndian) { // Array.Reverse(temp); double test = BitConverter.ToDouble(temp, 0); // TODO TEST THIS //newMatrix[i / (8 * testChannelCount), j / 8] = test; newMatrix[row, col] = test; } col++; } row++; col = 0; } newSignal.signalMatrix = newMatrix; lastSignal = newSignal; lastMatrix = newMatrix; displaySignalText(); return newMatrix[0, 0]; } else if (isString) { Debug.Log(theReader.ReadLine()); } } return 0; }
public double ReadSocket() { if (theStream == null) { return(-1); } if (theStream.DataAvailable) { // read header once if (bciState == BCIState.ReceivingHeader) { ReadHeader(); bciState = BCIState.ReceivingData; LogStateEvent(); onBCIStateChanged.Invoke(Enum.GetName(typeof(BCIState), bciState), ""); } if (bciState == BCIState.ReceivingData) { // raw signal data // [nSamples x nChannels] // all channels for one sample are sent in a sequence, then all channels of the next sample // create a signal object to send it to another RawOpenVibeSignal newSignal = new RawOpenVibeSignal(); newSignal.samples = testSampleCount; newSignal.channels = testChannelCount; double[,] newMatrix = new double[testSampleCount, testChannelCount]; //Debug.Log("SampleCount: " + testSampleCount); //Debug.Log("ChannelCount: " + testChannelCount); byte[] buffer = new byte[testSampleChannelSize]; theStream.Read(buffer, 0, testSampleChannelSize); int row = 0; int col = 0; for (int i = 0; i < testSampleCount * testChannelCount * (sizeof(double)); i = i + (sizeof(double) * testChannelCount)) { for (int j = 0; j < testChannelCount * sizeof(double); j = j + sizeof(double)) { byte[] temp = new byte[8]; for (int k = 0; k < 8; k++) { temp[k] = buffer[i + j + k]; } if (BitConverter.IsLittleEndian) { // Array.Reverse(temp); double test = BitConverter.ToDouble(temp, 0); // TODO TEST THIS //newMatrix[i / (8 * testChannelCount), j / 8] = test; newMatrix[row, col] = test; } col++; } row++; col = 0; } newSignal.signalMatrix = newMatrix; lastSignal = newSignal; lastMatrix = newMatrix; return(newMatrix[0, 0]); } } return(-1); }