Initial Commit
parent
283e9ef902
commit
c3544130a5
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.hwo.pulscounter</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
@ -0,0 +1,29 @@
|
||||
package org.hwo.pulscounter;
|
||||
|
||||
import org.hwo.models.TableMapper.TableColumn;
|
||||
|
||||
public class CounterChannel {
|
||||
|
||||
@TableColumn(label="Kanal",firstColumn=true)
|
||||
private Integer channel;
|
||||
@TableColumn(label="ZŠhlerstand",after="Kanal")
|
||||
public Integer value;
|
||||
@TableColumn(label="Korrekturwert",after="ZŠhlerstand")
|
||||
public Integer correct;
|
||||
|
||||
@TableColumn(label="Ergebnis",after="Korrekturwert")
|
||||
private Integer correctedValue()
|
||||
{
|
||||
return value + correct;
|
||||
}
|
||||
|
||||
public CounterChannel(int ch)
|
||||
{
|
||||
channel = ch;
|
||||
value = 0;
|
||||
correct = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.hwo.pulscounter;
|
||||
|
||||
public class PulsCounter {
|
||||
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
|
||||
PulsCounterWindow window = new PulsCounterWindow();
|
||||
window.setVisible(true);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package org.hwo.pulscounter;
|
||||
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.io.SerialPort;
|
||||
|
||||
public class PulsCounterInterface {
|
||||
|
||||
SerialPort port;
|
||||
|
||||
public PulsCounterInterface(String portName)
|
||||
{
|
||||
port = new SerialPort(portName);
|
||||
}
|
||||
|
||||
public List<Integer> readCounter()
|
||||
{
|
||||
ArrayList<Integer> counter = new ArrayList<Integer>();
|
||||
|
||||
/*
|
||||
if (port.open())
|
||||
{
|
||||
port.close();
|
||||
}
|
||||
*/
|
||||
for (int i=0;i<32;i++)
|
||||
counter.add( i * i);
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,229 @@
|
||||
package org.hwo.pulscounter;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
import org.hwo.csv.CSV;
|
||||
import org.hwo.io.SerialPort;
|
||||
import org.hwo.models.TableMapper.TableMapper;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class PulsCounterWindow extends JFrame{
|
||||
private JComboBox cbInterfaces;
|
||||
private JTable tCounter;
|
||||
|
||||
private TableMapper tmCounter;
|
||||
private Preferences prefs;
|
||||
private List<CounterChannel> counterChannels;
|
||||
|
||||
List<TimeBarrier> timeBarriers;
|
||||
|
||||
|
||||
public PulsCounterWindow() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 732, 350);
|
||||
setTitle("PulsCounter");
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
getContentPane().setLayout(gridBagLayout);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 0;
|
||||
getContentPane().add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0, 0};
|
||||
gbl_panel.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Schnittstelle:");
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
panel.add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
cbInterfaces = new JComboBox();
|
||||
cbInterfaces.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
System.err.println("Save Pref PORT");
|
||||
|
||||
prefs.put("io.port", cbInterfaces.getSelectedItem().toString());
|
||||
try
|
||||
{
|
||||
prefs.sync();
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.err.println("Exception: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_cbInterfaces = new GridBagConstraints();
|
||||
gbc_cbInterfaces.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_cbInterfaces.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_cbInterfaces.gridx = 1;
|
||||
gbc_cbInterfaces.gridy = 0;
|
||||
panel.add(cbInterfaces, gbc_cbInterfaces);
|
||||
|
||||
JButton btnNewButton = new JButton("Jetzt aktualisieren...");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
updateCounter();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
|
||||
gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_btnNewButton.gridx = 2;
|
||||
gbc_btnNewButton.gridy = 0;
|
||||
panel.add(btnNewButton, gbc_btnNewButton);
|
||||
|
||||
JButton btnTagesdateiSchreiben = new JButton("Tagesdatei schreiben...");
|
||||
btnTagesdateiSchreiben.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
writeDayFile();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnTagesdateiSchreiben = new GridBagConstraints();
|
||||
gbc_btnTagesdateiSchreiben.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_btnTagesdateiSchreiben.gridx = 3;
|
||||
gbc_btnTagesdateiSchreiben.gridy = 0;
|
||||
panel.add(btnTagesdateiSchreiben, gbc_btnTagesdateiSchreiben);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("New button");
|
||||
GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
|
||||
gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnNewButton_1.gridx = 4;
|
||||
gbc_btnNewButton_1.gridy = 0;
|
||||
panel.add(btnNewButton_1, gbc_btnNewButton_1);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 1;
|
||||
getContentPane().add(scrollPane, gbc_scrollPane);
|
||||
|
||||
tCounter = new JTable();
|
||||
scrollPane.setViewportView(tCounter);
|
||||
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
|
||||
prefs = Preferences.userRoot();
|
||||
|
||||
String defaultPort = prefs.get("io.port", "COM1");
|
||||
|
||||
for (String portName:SerialPort.getPortNames())
|
||||
cbInterfaces.addItem(portName);
|
||||
|
||||
System.err.println("Default Port: " + defaultPort);
|
||||
|
||||
for (int i=0;i < cbInterfaces.getItemCount();i++)
|
||||
{
|
||||
if (cbInterfaces.getItemAt(i).equals(defaultPort))
|
||||
cbInterfaces.setSelectedIndex(i);
|
||||
}
|
||||
|
||||
counterChannels = new ArrayList<CounterChannel>();
|
||||
for (int i=0;i<32;i++)
|
||||
counterChannels.add(new CounterChannel( i + 1) );
|
||||
|
||||
tmCounter = new TableMapper(CounterChannel.class, tCounter);
|
||||
tmCounter.setRows(counterChannels);
|
||||
tmCounter.getColumnInfo().get(0).setReadOnly(true);
|
||||
tmCounter.getColumnInfo().get(1).setReadOnly(true);
|
||||
tmCounter.getColumnInfo().get(3).setReadOnly(true);
|
||||
|
||||
timeBarriers = new ArrayList<TimeBarrier>();
|
||||
|
||||
timeBarriers.add(new TimeBarrier(01,00));
|
||||
timeBarriers.add(new TimeBarrier(03,00));
|
||||
timeBarriers.add(new TimeBarrier(06,00));
|
||||
|
||||
}
|
||||
|
||||
private void updateCounter()
|
||||
{
|
||||
PulsCounterInterface intf = new PulsCounterInterface(cbInterfaces.getSelectedItem().toString());
|
||||
|
||||
List<Integer> values = intf.readCounter();
|
||||
for (int i=0;i<values.size();i++)
|
||||
{
|
||||
counterChannels.get(i).value = values.get(i);
|
||||
values.set(i, values.get(i) + counterChannels.get(i).correct);
|
||||
}
|
||||
|
||||
tCounter.repaint();
|
||||
|
||||
for (TimeBarrier tb:timeBarriers)
|
||||
{
|
||||
tb.update(values);
|
||||
tb.save();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDayFile()
|
||||
{
|
||||
CSV csv = new CSV();
|
||||
Date date = new Date();
|
||||
|
||||
String[] row = new String[this.timeBarriers.size() + 1];
|
||||
|
||||
row[0] = "";
|
||||
for (int n=1;n<row.length;n++)
|
||||
{
|
||||
row[n] = String.format("%02d:%02d", (timeBarriers.get(n-1).timeOfDay / 60),(timeBarriers.get(n-1).timeOfDay % 60));
|
||||
}
|
||||
csv.getCells().add(row);
|
||||
|
||||
for (int i=0;i<this.counterChannels.size();i++)
|
||||
{
|
||||
row = new String[this.timeBarriers.size() + 1];
|
||||
row[0] = new Integer(i + 1).toString();
|
||||
for (int n=1;n<row.length;n++)
|
||||
row[n] = timeBarriers.get(n-1).values.get(i).toString();
|
||||
csv.getCells().add(row);
|
||||
}
|
||||
|
||||
csv.saveToFile(String.format("daily-%d-%d-%d.csv",(date.getYear()+1900),date.getMonth()+1,date.getDate()+1));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.hwo.pulscounter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.csv.CSV;
|
||||
|
||||
public class TimeBarrier {
|
||||
|
||||
Integer timeOfDay;
|
||||
List<Integer> values;
|
||||
|
||||
public TimeBarrier(Integer timeOfDay)
|
||||
{
|
||||
this.timeOfDay = timeOfDay;
|
||||
values = new ArrayList<Integer>();
|
||||
load();
|
||||
}
|
||||
|
||||
public TimeBarrier(Integer HourOfDay,Integer MinuteOfDay)
|
||||
{
|
||||
this.timeOfDay = (HourOfDay * 60) + MinuteOfDay;
|
||||
values = new ArrayList<Integer>();
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void update(List<Integer> values)
|
||||
{
|
||||
Date date = new Date();
|
||||
int now = (date.getHours() * 60) + date.getMinutes();
|
||||
|
||||
if (now < timeOfDay)
|
||||
{
|
||||
this.values.clear();
|
||||
for (Integer v: values)
|
||||
this.values.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
CSV csv = new CSV();
|
||||
for (Integer i:values)
|
||||
csv.getCells().add(new String[]{i.toString()});
|
||||
|
||||
|
||||
csv.saveToFile(String.format("day-%d.csv", timeOfDay));
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
CSV csv = new CSV();
|
||||
csv.readFromFile(String.format("day-%d.csv", timeOfDay));
|
||||
|
||||
for (String[] row: csv.getCells())
|
||||
this.values.add(Integer.parseInt(row[0]));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue