-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add insertMarker and getMarkerChannel methods to all relevant boards
Showing
11 changed files
with
281 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,130 @@ | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
abstract class Board implements DataSource { | ||
|
||
private FixedStack<double[]> accumulatedData = new FixedStack<double[]>(); | ||
private double[][] dataThisFrame; | ||
protected PacketLossTracker packetLossTracker; | ||
|
||
// accessible by all boards, can be returned as valid empty data | ||
protected double[][] emptyData; | ||
|
||
@Override | ||
public boolean initialize() { | ||
boolean res = initializeInternal(); | ||
|
||
double[] fillData = new double[getTotalChannelCount()]; | ||
accumulatedData.setSize(getCurrentBoardBufferSize()); | ||
accumulatedData.fill(fillData); | ||
|
||
emptyData = new double[getTotalChannelCount()][0]; | ||
|
||
packetLossTracker = setupPacketLossTracker(); | ||
|
||
return res; | ||
} | ||
|
||
@Override | ||
public void uninitialize() { | ||
uninitializeInternal(); | ||
} | ||
|
||
@Override | ||
public void startStreaming() { | ||
packetLossTracker.onStreamStart(); | ||
} | ||
|
||
@Override | ||
public void stopStreaming() { | ||
|
||
// empty | ||
} | ||
|
||
@Override | ||
public void update() { | ||
updateInternal(); | ||
|
||
dataThisFrame = getNewDataInternal(); | ||
|
||
for (int i = 0; i < dataThisFrame[0].length; i++) { | ||
double[] newEntry = new double[getTotalChannelCount()]; | ||
for (int j = 0; j < getTotalChannelCount(); j++) { | ||
newEntry[j] = dataThisFrame[j][i]; | ||
} | ||
|
||
accumulatedData.push(newEntry); | ||
} | ||
|
||
if( packetLossTracker != null) { | ||
//TODO: make all API including getNewDataInternal() return List<double[]> | ||
// and we can just pass dataThisFrame here. | ||
packetLossTracker.addSamples(getData(dataThisFrame[0].length)); | ||
} | ||
} | ||
|
||
@Override | ||
public int getNumEXGChannels() { | ||
return getEXGChannels().length; | ||
} | ||
|
||
// returns all the data this board has received in this frame | ||
@Override | ||
public double[][] getFrameData() { | ||
return dataThisFrame; | ||
} | ||
|
||
@Override | ||
public List<double[]> getData(int maxSamples) { | ||
int endIndex = accumulatedData.size(); | ||
int startIndex = max(0, endIndex - maxSamples); | ||
|
||
return accumulatedData.subList(startIndex, endIndex); | ||
} | ||
|
||
public String[] getChannelNames() { | ||
String[] names = new String[getTotalChannelCount()]; | ||
Arrays.fill(names, "Other"); | ||
|
||
names[getTimestampChannel()] = "Timestamp"; | ||
names[getSampleIndexChannel()] = "Sample Index"; | ||
|
||
int[] exgChannels = getEXGChannels(); | ||
for (int i=0; i<exgChannels.length; i++) { | ||
names[exgChannels[i]] = "EXG Channel " + i; | ||
} | ||
|
||
addChannelNamesInternal(names); | ||
return names; | ||
} | ||
|
||
public PacketLossTracker getPacketLossTracker() { | ||
return packetLossTracker; | ||
} | ||
|
||
public abstract boolean isConnected(); | ||
|
||
public abstract boolean isStreaming(); | ||
|
||
public abstract Pair <Boolean, String> sendCommand(String command); | ||
|
||
// *************************************** | ||
// protected methods implemented by board | ||
|
||
// implemented by each board class and used internally here to accumulate the FixedStack | ||
// and provide with public interfaces getFrameData() and getData(int) | ||
protected abstract double[][] getNewDataInternal(); | ||
|
||
protected abstract boolean initializeInternal(); | ||
|
||
protected abstract void uninitializeInternal(); | ||
|
||
protected abstract void updateInternal(); | ||
|
||
protected abstract void addChannelNamesInternal(String[] channelNames); | ||
|
||
protected abstract PacketLossTracker setupPacketLossTracker(); | ||
}; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
abstract class Board implements DataSource { | ||
|
||
private FixedStack<double[]> accumulatedData = new FixedStack<double[]>(); | ||
private double[][] dataThisFrame; | ||
protected PacketLossTracker packetLossTracker; | ||
|
||
// accessible by all boards, can be returned as valid empty data | ||
protected double[][] emptyData; | ||
|
||
@Override | ||
public boolean initialize() { | ||
boolean res = initializeInternal(); | ||
|
||
double[] fillData = new double[getTotalChannelCount()]; | ||
accumulatedData.setSize(getCurrentBoardBufferSize()); | ||
accumulatedData.fill(fillData); | ||
|
||
emptyData = new double[getTotalChannelCount()][0]; | ||
|
||
packetLossTracker = setupPacketLossTracker(); | ||
|
||
return res; | ||
} | ||
|
||
@Override | ||
public void uninitialize() { | ||
uninitializeInternal(); | ||
} | ||
|
||
@Override | ||
public void startStreaming() { | ||
packetLossTracker.onStreamStart(); | ||
} | ||
|
||
@Override | ||
public void stopStreaming() { | ||
|
||
// empty | ||
} | ||
|
||
@Override | ||
public void update() { | ||
updateInternal(); | ||
|
||
dataThisFrame = getNewDataInternal(); | ||
|
||
for (int i = 0; i < dataThisFrame[0].length; i++) { | ||
double[] newEntry = new double[getTotalChannelCount()]; | ||
for (int j = 0; j < getTotalChannelCount(); j++) { | ||
newEntry[j] = dataThisFrame[j][i]; | ||
} | ||
|
||
accumulatedData.push(newEntry); | ||
} | ||
|
||
if( packetLossTracker != null) { | ||
//TODO: make all API including getNewDataInternal() return List<double[]> | ||
// and we can just pass dataThisFrame here. | ||
packetLossTracker.addSamples(getData(dataThisFrame[0].length)); | ||
} | ||
} | ||
|
||
@Override | ||
public int getNumEXGChannels() { | ||
return getEXGChannels().length; | ||
} | ||
|
||
// returns all the data this board has received in this frame | ||
@Override | ||
public double[][] getFrameData() { | ||
return dataThisFrame; | ||
} | ||
|
||
@Override | ||
public List<double[]> getData(int maxSamples) { | ||
int endIndex = accumulatedData.size(); | ||
int startIndex = max(0, endIndex - maxSamples); | ||
|
||
return accumulatedData.subList(startIndex, endIndex); | ||
} | ||
|
||
public String[] getChannelNames() { | ||
String[] names = new String[getTotalChannelCount()]; | ||
Arrays.fill(names, "Other"); | ||
|
||
names[getTimestampChannel()] = "Timestamp"; | ||
names[getSampleIndexChannel()] = "Sample Index"; | ||
|
||
int[] exgChannels = getEXGChannels(); | ||
for (int i=0; i<exgChannels.length; i++) { | ||
names[exgChannels[i]] = "EXG Channel " + i; | ||
} | ||
|
||
addChannelNamesInternal(names); | ||
return names; | ||
} | ||
|
||
public PacketLossTracker getPacketLossTracker() { | ||
return packetLossTracker; | ||
} | ||
|
||
public abstract boolean isConnected(); | ||
|
||
public abstract boolean isStreaming(); | ||
|
||
public abstract Pair <Boolean, String> sendCommand(String command); | ||
|
||
public abstract void insertMarker(int value); | ||
|
||
public abstract void insertMarker(double value); | ||
|
||
// *************************************** | ||
// protected methods implemented by board | ||
|
||
// implemented by each board class and used internally here to accumulate the FixedStack | ||
// and provide with public interfaces getFrameData() and getData(int) | ||
protected abstract double[][] getNewDataInternal(); | ||
|
||
protected abstract boolean initializeInternal(); | ||
|
||
protected abstract void uninitializeInternal(); | ||
|
||
protected abstract void updateInternal(); | ||
|
||
protected abstract void addChannelNamesInternal(String[] channelNames); | ||
|
||
protected abstract PacketLossTracker setupPacketLossTracker(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,101 @@ | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
|
||
/* This class does nothing, it serves as a signal that the board we are using | ||
* is null, but does not crash if we use it. | ||
*/ | ||
class BoardNull extends Board { | ||
|
||
@Override | ||
public boolean initializeInternal() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void uninitializeInternal() { | ||
// empty | ||
} | ||
|
||
@Override | ||
public void updateInternal() { | ||
// empty | ||
} | ||
|
||
@Override | ||
public boolean isConnected() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isStreaming() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getSampleRate() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int[] getEXGChannels() { | ||
return new int[0]; | ||
} | ||
|
||
@Override | ||
public int getTimestampChannel() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getSampleIndexChannel() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void setEXGChannelActive(int channelIndex, boolean active) { | ||
// empty | ||
} | ||
|
||
@Override | ||
public boolean isEXGChannelActive(int channelIndex) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Pair<Boolean, String> sendCommand(String command) { | ||
return new ImmutablePair<Boolean, String>(Boolean.valueOf(true), ""); | ||
} | ||
|
||
protected double[][] getNewDataInternal() { | ||
return new double[1][0]; | ||
} | ||
|
||
@Override | ||
public int getTotalChannelCount() { | ||
return 0; | ||
} | ||
|
||
protected void addChannelNamesInternal(String[] channelNames) { | ||
// nothing | ||
} | ||
|
||
@Override | ||
protected PacketLossTracker setupPacketLossTracker() { | ||
return null; | ||
} | ||
}; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
|
||
/* This class does nothing, it serves as a signal that the board we are using | ||
* is null, but does not crash if we use it. | ||
*/ | ||
class BoardNull extends Board { | ||
|
||
@Override | ||
public boolean initializeInternal() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void uninitializeInternal() { | ||
// empty | ||
} | ||
|
||
@Override | ||
public void updateInternal() { | ||
// empty | ||
} | ||
|
||
@Override | ||
public boolean isConnected() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isStreaming() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getSampleRate() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int[] getEXGChannels() { | ||
return new int[0]; | ||
} | ||
|
||
@Override | ||
public int getTimestampChannel() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getSampleIndexChannel() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getMarkerChannel() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void insertMarker(int marker) { | ||
// empty | ||
} | ||
|
||
@Override | ||
public void insertMarker(double value) { | ||
// empty | ||
} | ||
|
||
@Override | ||
public void setEXGChannelActive(int channelIndex, boolean active) { | ||
// empty | ||
} | ||
|
||
@Override | ||
public boolean isEXGChannelActive(int channelIndex) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Pair<Boolean, String> sendCommand(String command) { | ||
return new ImmutablePair<Boolean, String>(Boolean.valueOf(true), ""); | ||
} | ||
|
||
protected double[][] getNewDataInternal() { | ||
return new double[1][0]; | ||
} | ||
|
||
@Override | ||
public int getTotalChannelCount() { | ||
return 0; | ||
} | ||
|
||
protected void addChannelNamesInternal(String[] channelNames) { | ||
// nothing | ||
} | ||
|
||
@Override | ||
protected PacketLossTracker setupPacketLossTracker() { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters