-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ added CSV import device (to import data from DS203 and others)
- Loading branch information
Showing
8 changed files
with
537 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>nl.lxtreme.ols</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
<groupId>nl.lxtreme.ols.device</groupId> | ||
<artifactId>csv-import</artifactId> | ||
<packaging>bundle</packaging> | ||
<version>1.0.0</version> | ||
<name>OLS CSV Device</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>nl.lxtreme.ols</groupId> | ||
<artifactId>api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>nl.lxtreme.ols</groupId> | ||
<artifactId>util</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.compendium</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>nl.lxtreme.ols</groupId> | ||
<artifactId>test.util</artifactId> | ||
<type>jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<type>jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<type>jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Bundle-Description>A device to read CSV files.</Bundle-Description> | ||
<Bundle-Copyright>J.W. Janssen (lxtreme.nl) (C) 2010-2011, Florian Frankenberger (C) 2015</Bundle-Copyright> | ||
<Bundle-License>GPLv2;link=http://www.gnu.org/licenses/gpl-2.0.html</Bundle-License> | ||
<Import-Package>org.osgi.framework;version="1.3.0", *</Import-Package> | ||
<OLS-Device>1.0</OLS-Device> | ||
<OLS-DeviceClass>nl.lxtreme.ols.device.csv.CSVDevice</OLS-DeviceClass> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
160 changes: 160 additions & 0 deletions
160
device.csv/src/main/java/nl/lxtreme/ols/device/csv/CSVAcquisitionTask.java
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 |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* OpenBench LogicSniffer / SUMP project | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin St, Fifth Floor, Boston, MA 02110, USA | ||
* | ||
* Copyright (C) 2006-2010 Michael Poppitz, www.sump.org | ||
* Copyright (C) 2010 J.W. Janssen, www.lxtreme.nl | ||
* Copyright (C) 2015 Florian Frankenberger | ||
*/ | ||
package nl.lxtreme.ols.device.csv; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import nl.lxtreme.ols.api.acquisition.*; | ||
import nl.lxtreme.ols.api.data.*; | ||
import nl.lxtreme.ols.api.devices.*; | ||
|
||
/** | ||
* Denotes an acquisition task that imports data from a given csv file. The file needs | ||
* to have this layout: | ||
* | ||
* <pre> | ||
* [Channel Data A], [Channel Data B], ..., [Channel Data X] | ||
* </pre> | ||
* | ||
* Everything not numeric is ignored. | ||
*/ | ||
public class CSVAcquisitionTask implements AcquisitionTask { | ||
private final CSVDeviceDialog configDialog; | ||
private final AcquisitionProgressListener progressListener; | ||
|
||
/** | ||
* Creates a new TestDevice instance. | ||
* | ||
* @param aConfigDialog | ||
* @param aProgressListener | ||
*/ | ||
public CSVAcquisitionTask(final CSVDeviceDialog aConfigDialog, final AcquisitionProgressListener aProgressListener) { | ||
this.configDialog = aConfigDialog; | ||
this.progressListener = aProgressListener; | ||
} | ||
|
||
private final class ChannelData { | ||
private final List<Integer> rawData = new ArrayList<Integer>(); | ||
private Float meanValue = null; | ||
|
||
public void addRawData(int rawData) { | ||
this.rawData.add(rawData); | ||
meanValue = null; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return this.rawData.isEmpty(); | ||
} | ||
|
||
public int length() { | ||
return this.rawData.size(); | ||
} | ||
|
||
public List<Integer> getRawData() { | ||
return rawData; | ||
} | ||
|
||
public void calculateMeanValue() { | ||
long total = 0; | ||
for (int value : rawData) { | ||
total += value; | ||
} | ||
meanValue = total / (float) rawData.size(); | ||
} | ||
|
||
public int getHighLowAt(int index) { | ||
if (meanValue == null) { | ||
throw new IllegalStateException("You need to calculate the mean value first"); | ||
} | ||
if (index >= this.rawData.size()) { | ||
return 0; | ||
} else { | ||
return rawData.get(index) > meanValue ? 1 : 0; | ||
} | ||
} | ||
|
||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public AcquisitionResult call() throws Exception { | ||
final File file = this.configDialog.getFile(); | ||
|
||
int channels = 0; | ||
int trigger = 0; | ||
|
||
//collect all data | ||
List<ChannelData> channelDatas = new ArrayList<ChannelData>(); | ||
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file))); | ||
String line; | ||
while ((line = in.readLine()) != null) { | ||
String[] parts = line.split(","); | ||
for (int i = 0; i < parts.length; ++i) { | ||
String part = parts[i]; | ||
if (channelDatas.size() <= i) { | ||
channelDatas.add(new ChannelData()); | ||
} | ||
ChannelData data = channelDatas.get(i); | ||
try { | ||
Integer partInt = Integer.valueOf(part.trim()); | ||
data.addRawData(partInt); | ||
} catch (NumberFormatException e) { | ||
//ignore for now | ||
} | ||
} | ||
} | ||
|
||
//remove empty lists and count channels | ||
int maxLength = 0; | ||
for (Iterator<ChannelData> iterator = channelDatas.iterator(); iterator.hasNext();) { | ||
final ChannelData channelData = iterator.next(); | ||
if (!channelData.isEmpty()) { | ||
channelData.calculateMeanValue(); | ||
if (channelData.length() > maxLength) { | ||
maxLength = channelData.length(); | ||
} | ||
channels++; | ||
} else { | ||
iterator.remove(); | ||
} | ||
} | ||
|
||
int[] data = new int[maxLength]; | ||
for (int i = 0; i < maxLength; ++i) { | ||
for (int j = 0; j < channelDatas.size(); ++j) { | ||
ChannelData channelData = channelDatas.get(j); | ||
data[i] = data[i] | (channelData.getHighLowAt(i) << j); | ||
} | ||
} | ||
|
||
final int enabledChannels = (int) ((1L << channels) - 1); | ||
return new CapturedData(data, trigger, data.length, channels, enabledChannels); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
device.csv/src/main/java/nl/lxtreme/ols/device/csv/CSVDevice.java
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* OpenBench LogicSniffer / SUMP project | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin St, Fifth Floor, Boston, MA 02110, USA | ||
* | ||
* | ||
* Copyright (C) 2010-2011 - J.W. Janssen, http://www.lxtreme.nl | ||
* Copyright (C) 2015 Florian Frankenberger | ||
*/ | ||
package nl.lxtreme.ols.device.csv; | ||
|
||
import java.awt.*; | ||
import java.io.*; | ||
|
||
import nl.lxtreme.ols.api.acquisition.*; | ||
import nl.lxtreme.ols.api.devices.*; | ||
|
||
/** | ||
* The device controller for the testing device. | ||
*/ | ||
public class CSVDevice implements Device { | ||
|
||
private CSVDeviceDialog configDialog; | ||
private boolean setup = false; | ||
|
||
public CSVDevice() { | ||
super(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void close() throws IOException { | ||
// No-op... | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public AcquisitionTask createAcquisitionTask(final AcquisitionProgressListener aProgressListener) | ||
throws IOException { | ||
return new CSVAcquisitionTask(this.configDialog, aProgressListener); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public CancelTask createCancelTask() throws IOException { | ||
// Nothing special is needed... | ||
return null; | ||
} | ||
|
||
/** | ||
* @see nl.lxtreme.ols.api.devices.Device#getName() | ||
*/ | ||
@Override | ||
public String getName() { | ||
return "CSV Import Device"; | ||
} | ||
|
||
/** | ||
* @see nl.lxtreme.ols.api.devices.Device#isSetup() | ||
*/ | ||
@Override | ||
public boolean isSetup() { | ||
return this.setup; | ||
} | ||
|
||
/** | ||
* @see nl.lxtreme.ols.api.devices.Device#setupCapture() | ||
*/ | ||
@Override | ||
public boolean setupCapture(final Window aOwner) { | ||
// check if dialog exists with different owner and dispose if so | ||
if ((this.configDialog != null) && (this.configDialog.getOwner() != aOwner)) { | ||
this.configDialog.dispose(); | ||
this.configDialog = null; | ||
} | ||
// if no valid dialog exists, create one | ||
if (this.configDialog == null) { | ||
this.configDialog = new CSVDeviceDialog(aOwner); | ||
} | ||
|
||
return (this.setup = this.configDialog.showDialog()); | ||
} | ||
} |
Oops, something went wrong.