From 595119f705cb43cc315a86b8c417f699e080d68c Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Wed, 18 Dec 2013 15:01:18 +0100 Subject: [PATCH] Major reconstruction of the classes. Unnecessary classes were removed and code was streamlined. FDA-99 --- .../src/main/java/ch/psi/fda/cdump/Cdump.java | 140 ++++++++++++++++++ .../java/ch/psi/fda/cdump/CdumpAqLogic.java | 80 ---------- .../ch/psi/fda/cdump/CdumpConfiguration.java | 77 +--------- .../java/ch/psi/fda/cdump/CdumpListener.java | 101 +++++++++++++ .../main/java/ch/psi/fda/cdump/CdumpMain.java | 44 +++--- .../ch/psi/fda/cdump/CdumpSerializer.java | 86 ----------- .../java/ch/psi/fda/cdump/CdumpService.java | 103 ------------- .../ch/psi/fda/cdump/RunConfiguration.java | 103 ------------- .../ch/psi/fda/cdump/CdumpListenerTest.java | 68 +++++++++ .../ch/psi/fda/cdump/CdumpPrLogicTest.java | 65 -------- 10 files changed, 340 insertions(+), 527 deletions(-) create mode 100644 ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/Cdump.java delete mode 100644 ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpAqLogic.java create mode 100644 ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpListener.java delete mode 100644 ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpSerializer.java delete mode 100644 ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpService.java delete mode 100644 ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/RunConfiguration.java create mode 100644 ch.psi.fda.cdump/src/test/java/ch/psi/fda/cdump/CdumpListenerTest.java delete mode 100644 ch.psi.fda.cdump/src/test/java/ch/psi/fda/cdump/CdumpPrLogicTest.java diff --git a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/Cdump.java b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/Cdump.java new file mode 100644 index 0000000..1d6ff4e --- /dev/null +++ b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/Cdump.java @@ -0,0 +1,140 @@ +/** + * + * Copyright 2010 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ + +package ch.psi.fda.cdump; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import java.util.logging.Logger; + +import com.google.common.eventbus.EventBus; + +import ch.psi.jcae.Channel; +import ch.psi.jcae.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; + +/** + * Cdump readout logic - i.e. put monitor on a data waveform channel of the fast + * ADC and send data to the eventbus + */ +public class Cdump { + + private static final Logger logger = Logger.getLogger(Cdump.class.getName()); + + public final static String[] SAMPLING_RATES = new String[] {"1Hz","2Hz", "5Hz", "10Hz", "20Hz", "50Hz", "100Hz", "200Hz", "500Hz", + "1kHz", "2kHz", "5kHz", "10kHz", "20kHz", "50kHz", "100kHz"}; + + private Channel adcData; + + private enum AdcCmd { + READY, GO + }; + + private Channel adcCmd; + + private CdumpListener listener; + private ChannelService cservice; + private CdumpConfiguration configuration; + + public Cdump(ChannelService cservice, EventBus ebus, CdumpConfiguration configuration) { + this.cservice = cservice; + this.configuration = configuration; + this.listener = new CdumpListener(ebus, configuration.getNelements()); + } + + /** + * Acquire data with the given sampling rate + * @param samplingRate + */ + public void acquire(String samplingRate) { + + logger.info("Start acquisition with sampling rate "+ samplingRate); + + try { + // Set ADC sampling rate + Channel smplRate = cservice.createChannel(new ChannelDescriptor<>(Integer.class, configuration.getSamplingRateChannel(), false)); + smplRate.setValue(getIntSamplingRate(samplingRate)); + smplRate.destroy(); + + adcData = cservice.createChannel(new ChannelDescriptor<>(int[].class, configuration.getDataChannel(), true)); + adcCmd = cservice.createChannel(new ChannelDescriptor<>(Integer.class, configuration.getControlChannel(), false)); + + adcCmd.setValue(AdcCmd.GO.ordinal()); + adcData.addPropertyChangeListener(listener); + } catch (ChannelException | TimeoutException | InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + + public void stop() { + + logger.info("Stop acquisition"); + + try { + // Detach listener from channel - i.e. stop data acquisition + adcData.removePropertyChangeListener(listener); + adcCmd.setValue(AdcCmd.READY.ordinal()); + + listener.terminate(); + + adcCmd.destroy(); + adcData.destroy(); + } catch (ChannelException | InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + + /** + * Get sampling rate int value based on the passed rate string. + * If the string does not match any of the strings specified in the rates variable + * this function will set the rate to 1Hz + * + * 0 = 1Hz + * 1 = 2Hz + * 2 = 5Hz + * 3 = 10Hz + * 4 = 20Hz + * 5 = 50Hz + * 6 = 100Hz + * 7 = 200Hz + * 8 = 500Hz + * 9 = 1000Hz + * 10 = 2000Hz + * 11 = 5000Hz + * 12 = 10000Hz + * 13 = 20000Hz + * 14 = 50000Hz + * 15 = 100000Hz + * + * @param rate + */ + private int getIntSamplingRate(String rate){ + + for(int i=0;i. - * - */ - -package ch.psi.fda.cdump; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.concurrent.ExecutionException; - -import com.google.common.eventbus.EventBus; - -import ch.psi.jcae.Channel; -import ch.psi.jcae.ChannelException; - -/** - * Cdump readout logic - i.e. put monitor on a data waveform channel of the fast ADC and send data to - * the eventbus - */ -public class CdumpAqLogic { - - // Cdump channels template - private Channel adcData; - private enum AdcCmd {READY, GO}; - private Channel adcCmd; - - private EventBus eventbus; - /** - * Listener to monitor adc data channel - */ - private PropertyChangeListener listener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - eventbus.post((int[]) evt.getNewValue()); - } - }; - - - public CdumpAqLogic(Channel adcData, Channel adcCmd, EventBus eventbus){ - this.adcData = adcData; - this.adcCmd = adcCmd; - - this.eventbus = eventbus; - } - - /** - * Acquire data - * @throws InterruptedException - * @throws ChannelException - * @throws ExecutionException - * @throws CAException - */ - public void acquire() throws InterruptedException, ExecutionException, ChannelException{ - adcCmd.setValue(AdcCmd.GO.ordinal()); - adcData.addPropertyChangeListener(listener); - } - - public void stop() throws InterruptedException, ExecutionException, ChannelException{ - // Detach listener from channel - i.e. stop data acquisition - adcData.removePropertyChangeListener(listener); - adcCmd.setValue(AdcCmd.READY.ordinal()); - - eventbus.post(new int[]{}); // TODO replace with end of stream message - } -} diff --git a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpConfiguration.java b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpConfiguration.java index 3c7ddd6..32bed4d 100644 --- a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpConfiguration.java +++ b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpConfiguration.java @@ -19,94 +19,35 @@ package ch.psi.fda.cdump; -import java.io.FileNotFoundException; +import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -/** - * Cdump configuration - */ + public class CdumpConfiguration { - private static final CdumpConfiguration instance = new CdumpConfiguration(); - private String dataChannel; private int nelements = 65536; private String controlChannel; private String samplingRateChannel; - private String filePrefix = "${yyyy_MM}/${yyyyMMdd}/${yyyyMMddHHmmss}_${name}/${yyyyMMddHHmm}_"; - private String dataDirectory; - /** - * Singleton - Private constructor - */ - private CdumpConfiguration(){ - loadConfiguration(); - } - - public static CdumpConfiguration getInstance(){ - return instance; - } - /** - * Read configuration from CDUMP_HOME/config/cdump.properties - */ - private void loadConfiguration() { - String config = System.getProperty(CdumpService.APP_HOME); - - if(config == null){ - throw new RuntimeException("No configuration file specified via -D"+CdumpService.APP_HOME+"=..."); - } - + public void loadFile(File file) { Properties properties = new Properties(); try { - properties.load(new FileReader(config+"/config/cdump.properties")); - } catch (FileNotFoundException e) { - throw new RuntimeException("Configuration file "+config+" not found", e); + properties.load(new FileReader(file)); } catch (IOException e) { - throw new RuntimeException("Cannot read configuration file "+config, e); + throw new RuntimeException("Cannot read file "+file, e); } dataChannel = properties.getProperty(CdumpConfiguration.class.getPackage().getName()+".dataChannel", ""); controlChannel = properties.getProperty(CdumpConfiguration.class.getPackage().getName()+".controlChannel", ""); samplingRateChannel = properties.getProperty(CdumpConfiguration.class.getPackage().getName()+".samplingRateChannel", ""); - dataDirectory = config+"/data"; + nelements = Integer.parseInt(properties.getProperty(CdumpConfiguration.class.getPackage().getName()+".nelements", "65536")); } - /** - * Replace macros date and name in passed string - * @param string - * @param date - * @param name - * @return - */ - public String replaceMacros(String string, Date date, String name){ - String newString = string; - - // Replace scan name macros - newString = newString.replaceAll("\\$\\{name\\}", name); - - - // Replace date macros - Pattern pattern = Pattern.compile("\\$\\{[a-z,A-Z,-,_,:]*\\}"); - Matcher matcher = pattern.matcher(newString); - while(matcher.find()){ - String datePattern = matcher.group(); - datePattern = datePattern.replaceAll("\\$\\{", ""); - datePattern = datePattern.replaceAll("\\}", ""); - SimpleDateFormat datef = new SimpleDateFormat(datePattern); - newString = matcher.replaceFirst(datef.format(date)); - matcher = pattern.matcher(newString); - } - return newString; - } - public String getDataChannel() { return dataChannel; } @@ -128,10 +69,4 @@ public class CdumpConfiguration { public int getNelements() { return nelements; } - public String getFilePrefix() { - return filePrefix; - } - public String getDataDirectory() { - return dataDirectory; - } } diff --git a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpListener.java b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpListener.java new file mode 100644 index 0000000..ecfa9b9 --- /dev/null +++ b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpListener.java @@ -0,0 +1,101 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.cdump; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.List; + +import ch.psi.fda.messages.DataMessage; +import ch.psi.fda.messages.EndOfStreamMessage; +import ch.psi.fda.messages.Metadata; + +import com.google.common.eventbus.EventBus; + +/** + * Listener that monitors the adc data channel and splitting up the data + */ +public class CdumpListener implements PropertyChangeListener { + + private final EventBus bus; + private final int numberOfElements; + + private boolean first = true; + private int numberOfWaveforms = 0; + private final List metadata = new ArrayList<>(); + + public CdumpListener(EventBus bus, int numberOfElements){ + this.bus = bus; + this.numberOfElements = numberOfElements; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + transform((int[]) evt.getNewValue()); + } + + + /** + * Transform received waveform + * 1. Take channel waveform + * [wavefrom .......................................................] + * 2. Split up waveform + * [1-number of elements][2-number of elements][3-number of elements] + * 3. Rotate splitted waveforms + * [1-0,2-0,3-0] << thats one message + * [1-1,2-1,3-1] + * ... + * [1-noe, 2-noe, 3-noe] + * + */ + public void transform(int[] value){ + + // The first time check whether received waveform is a multiple of the specified number of elements number + // Calculate how many waveforms are within the received waveform + if(first){ + first=false; + int nelements = value.length; + int n = nelements % numberOfElements; + if (n != 0) { + throw new RuntimeException("Array size is not a multiple of 65536"); + } + numberOfWaveforms = nelements / numberOfElements; + for(int i=0;i "); StringBuilder b = new StringBuilder(); - for(String s: RunConfiguration.rates){ + for(String s: Cdump.SAMPLING_RATES){ b.append(s); b.append(" "); } @@ -50,22 +51,29 @@ public class CdumpMain { System.exit(1); } - c.setSamplingRate(args[0]); + String samplingRate = args[0]; // Calculate data file location/name String fname = args[1]; - CdumpConfiguration cc = CdumpConfiguration.getInstance(); - String d = cc.getDataDirectory()+"/"+cc.replaceMacros(cc.getFilePrefix(), new Date(), fname)+fname+".txt"; - File f = new File(d); + CdumpConfiguration cc = new CdumpConfiguration(); + + String config = System.getProperty(APP_HOME); + + if(config == null){ + throw new RuntimeException("No configuration file specified via -D"+APP_HOME+"=..."); + } + cc.loadFile(new File(config+"/config/cdump.properties")); + + File f = new File(fname); f.getParentFile().mkdirs(); // Create data base directory - // Set file to save data - logger.info("Set data file to: "+f.getAbsolutePath()); - c.setDatafile(f); + // Create execution service - final CdumpService service = new CdumpService(cservice); - + EventBus eventbus = new AsyncEventBus(Executors.newSingleThreadExecutor()); + final Cdump service = new Cdump(cservice, eventbus, cc); + eventbus.register(new SerializerTXT(f)); + // Stop/abort handling of acquisition Signal.handle(new Signal("INT"), new SignalHandler() { /** @@ -92,15 +100,13 @@ public class CdumpMain { System.exit(2); } - service.stopAcquisition(); + service.stop(); cservice.destroy(); } }); - // Take data - service.startAcquisition(c); - + service.acquire(samplingRate); } } diff --git a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpSerializer.java b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpSerializer.java deleted file mode 100644 index 51d2b36..0000000 --- a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpSerializer.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * This code 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 Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.cdump; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; - -import com.google.common.eventbus.Subscribe; - -/** - * Serialization - */ -public class CdumpSerializer { - - private final File file; - private final int numberOfElements; - - private PrintWriter w; - private boolean first = true; - - public CdumpSerializer(File file, int nelements) { - this.file = file; - this.numberOfElements = nelements; - } - - @Subscribe - public void onMessage(int[] value) { - - if (first) { - try { - first = false; - w = new PrintWriter(new BufferedWriter(new FileWriter(file))); - } catch (IOException e) { - throw new RuntimeException(); - } - } - - // End of stream - if (value.length == 0) { - w.close(); - } - - int nelements = value.length; - int n = nelements % numberOfElements; - if (n != 0) { - throw new RuntimeException("Array size is not a multiple of 65536"); - } - int nwaveforms = nelements / numberOfElements; - - // Split and rotate array/waveform - boolean f = true; - for (int x = 0; x < numberOfElements; x++) { - f = true; - for (int t = 0; t < nwaveforms; t++) { - if (f) { - f = false; - } else { - w.print("\t"); - } - w.print(value[x + t * numberOfElements]); - } - w.print("\n"); - } - } - -} diff --git a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpService.java b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpService.java deleted file mode 100644 index 70b1778..0000000 --- a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/CdumpService.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.cdump; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeoutException; -import java.util.logging.Logger; - -import com.google.common.eventbus.AsyncEventBus; -import com.google.common.eventbus.EventBus; - -import ch.psi.jcae.Channel; -import ch.psi.jcae.ChannelDescriptor; -import ch.psi.jcae.ChannelException; -import ch.psi.jcae.ChannelService; - -public class CdumpService { - - public final static String APP_HOME = "ch.psi.cdump.home"; - - private static final Logger logger = Logger.getLogger(CdumpService.class.getName()); - - private CdumpAqLogic aqlogic = null; - private CdumpSerializer prlogic = null; - - private ChannelService cservice; - - private Channel adcData; - private Channel adcCmd; - - private EventBus eventbus; - - public CdumpService(ChannelService cservice){ - this.cservice = cservice; - } - - public void startAcquisition(RunConfiguration c) { - eventbus = new AsyncEventBus(Executors.newCachedThreadPool()); - - logger.info("Start acquisition"); - - CdumpConfiguration configuration = CdumpConfiguration.getInstance(); - - try { - - // Set ADC sampling rate - Channel smplRate = cservice.createChannel(new ChannelDescriptor<>(Integer.class, configuration.getSamplingRateChannel(), false)); - smplRate.setValue(c.getSamplingRate()); - smplRate.destroy(); - - - adcData = cservice.createChannel(new ChannelDescriptor<>(int[].class, configuration.getDataChannel(), true)); - adcCmd = cservice.createChannel(new ChannelDescriptor<>(Integer.class, configuration.getControlChannel(), false)); - - aqlogic = new CdumpAqLogic(adcData, adcCmd, eventbus); - - prlogic = new CdumpSerializer(c.getDatafile(), configuration.getNelements()); - eventbus.register(prlogic); - - logger.info("Start acquisition"); - aqlogic.acquire(); - - - } catch (InterruptedException | ChannelException | TimeoutException | ExecutionException e) { - e.printStackTrace(); - } - } - - /** - * Stop the data acquisition - */ - public void stopAcquisition(){ - logger.info("Stop acquisition"); - try { - aqlogic.stop(); - - // Cleanup channels - adcCmd.destroy(); - adcData.destroy(); - } catch (InterruptedException | ChannelException | ExecutionException e) { - e.printStackTrace(); - } - - } -} diff --git a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/RunConfiguration.java b/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/RunConfiguration.java deleted file mode 100644 index c8702e6..0000000 --- a/ch.psi.fda.cdump/src/main/java/ch/psi/fda/cdump/RunConfiguration.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.cdump; - -import java.io.File; - -/** - * @author ebner - * - */ -public class RunConfiguration { - - public final static String[] rates = new String[] {"1Hz","2Hz", "5Hz", "10Hz", "20Hz", "50Hz", "100Hz", "200Hz", "500Hz", - "1kHz", "2kHz", "5kHz", "10kHz", "20kHz", "50kHz", "100kHz"}; - - /** - * 0 = 1Hz - * 1 = 2Hz - * 2 = 5Hz - * 3 = 10Hz - * 4 = 20Hz - * 5 = 50Hz - * 6 = 100Hz - * 7 = 200Hz - * 8 = 500Hz - * 9 = 1000Hz - * 10 = 2000Hz - * 11 = 5000Hz - * 12 = 10000Hz - * 13 = 20000Hz - * 14 = 50000Hz - * 15 = 100000Hz - */ - private int samplingRate = 0; - - /** - * Data file - */ - private File datafile; - - /** - * Time to take data - */ - private Long executionTime = null ; - - /** - * @param samplingRate the samplingRate to set - */ - public void setSamplingRate(int samplingRate) { - this.samplingRate = samplingRate; - } - - /** - * Set sampling rate based on the passed rate string. - * If the string does not match any of the strings specified in the rates variable - * this function will set the rate to 1Hz - * @param rate - */ - public void setSamplingRate(String rate){ - // Default sampling rate 10kHz - setSamplingRate(12); - - for(int i=0;i. + * + */ +package ch.psi.fda.cdump; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import ch.psi.fda.messages.Message; + +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +/** + * + */ +public class CdumpListenerTest { + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + @Test + public void test() { + EventBus bus = new EventBus(); + + bus.register(new Object(){ + @Subscribe + public void onMessage(Message m){ + System.out.println(m); + } + }); + + CdumpListener l = new CdumpListener(bus, 4); + l.transform(new int[] {1,2,3,4,11,12,13,14}); + l.transform(new int[] {5,6,7,8,15,16,17,18}); + + + + } + +} diff --git a/ch.psi.fda.cdump/src/test/java/ch/psi/fda/cdump/CdumpPrLogicTest.java b/ch.psi.fda.cdump/src/test/java/ch/psi/fda/cdump/CdumpPrLogicTest.java deleted file mode 100644 index e3f5dd3..0000000 --- a/ch.psi.fda.cdump/src/test/java/ch/psi/fda/cdump/CdumpPrLogicTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * - * Copyright 2010 Paul Scherrer Institute. All rights reserved. - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This code 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - * - */ - -package ch.psi.fda.cdump; - -import java.io.File; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import ch.psi.fda.cdump.CdumpSerializer; - -import com.google.common.eventbus.EventBus; - -public class CdumpPrLogicTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - /** - * Testing serialization of waveforms. The resulting file should contain this: - * 1 11 - * 2 12 - * 3 13 - * 4 14 - * 5 15 - * 6 16 - * 7 17 - * 8 18 - */ - @Test - public void testRun() { - EventBus b = new EventBus(); - - CdumpSerializer logic = new CdumpSerializer(new File("target/test.txt"), 4); - b.register(logic); - - b.post(new int[] {1,2,3,4,11,12,13,14}); - b.post(new int[] {5,6,7,8,15,16,17,18}); - b.post(new int[]{}); - } - -}