removed snmp and status functions
added hearts and breath display added extra control window made the main window for external display w/o borders
This commit is contained in:
parent
065006acdb
commit
e9830ca276
|
@ -119,16 +119,18 @@
|
||||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
</item>
|
</item>
|
||||||
<item class="main.java.de.psychose.ActorDisplay" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
|
||||||
</item>
|
|
||||||
<item class="de.psychose.StatsDisplay" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
<item class="de.psychose.StatsDisplay" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
||||||
</item>
|
</item>
|
||||||
<item class="de.psychose.PulseControl" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
<item class="de.psychose.PulseControl" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
||||||
</item>
|
</item>
|
||||||
|
<item class="de.psychose.ActorHeart" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
||||||
|
</item>
|
||||||
|
<item class="de.psychose.ActorDisplay" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
||||||
|
</item>
|
||||||
</group>
|
</group>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,19 @@
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="clibwrapper_jiio" level="project" />
|
||||||
|
<orderEntry type="library" name="jai_imageio" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.illposed.osc:javaosc-core:0.2" level="project" />
|
<orderEntry type="library" name="Maven: com.illposed.osc:javaosc-core:0.2" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.jboss.netty:netty:3.2.7.Final" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.intellij:forms_rt:7.0.3" level="project" />
|
<orderEntry type="library" name="Maven: com.intellij:forms_rt:7.0.3" level="project" />
|
||||||
<orderEntry type="library" name="Maven: asm:asm-commons:3.0" level="project" />
|
<orderEntry type="library" name="Maven: asm:asm-commons:3.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: asm:asm-tree:3.0" level="project" />
|
<orderEntry type="library" name="Maven: asm:asm-tree:3.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: asm:asm:3.0" level="project" />
|
<orderEntry type="library" name="Maven: asm:asm:3.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.jgoodies:forms:1.1-preview" level="project" />
|
<orderEntry type="library" name="Maven: com.jgoodies:forms:1.1-preview" level="project" />
|
||||||
<orderEntry type="library" name="Maven: jdom:jdom:1.0" level="project" />
|
<orderEntry type="library" name="Maven: jdom:jdom:1.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.snmp4j:snmp4j:1.9.1f" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: log4j:log4j:1.2.9" level="project" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|
|
@ -15,21 +15,22 @@
|
||||||
<version>0.2</version>
|
<version>0.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<!--<dependency>-->
|
||||||
<groupId>org.jboss.netty</groupId>
|
<!--<groupId>org.jboss.netty</groupId>-->
|
||||||
<artifactId>netty</artifactId>
|
<!--<artifactId>netty</artifactId>-->
|
||||||
<version>3.2.7.Final</version>
|
<!--<version>3.2.7.Final</version>-->
|
||||||
</dependency>
|
<!--</dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.intellij</groupId>
|
<groupId>com.intellij</groupId>
|
||||||
<artifactId>forms_rt</artifactId>
|
<artifactId>forms_rt</artifactId>
|
||||||
<version>7.0.3</version>
|
<version>7.0.3</version>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!--<dependency>-->
|
||||||
<groupId>org.snmp4j</groupId>
|
<!--<groupId>org.snmp4j</groupId>-->
|
||||||
<artifactId>snmp4j</artifactId>
|
<!--<artifactId>snmp4j</artifactId>-->
|
||||||
<version>1.9.1f</version>
|
<!--<version>1.9.1f</version>-->
|
||||||
</dependency>
|
<!--</dependency>-->
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
package de.psychose;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lucas
|
||||||
|
* @date: 17.11.14 21:07
|
||||||
|
*/
|
||||||
|
public class ActorData {
|
||||||
|
|
||||||
|
private PulseData pulseData = new PulseData();
|
||||||
|
private int airflow;
|
||||||
|
private int ekg;
|
||||||
|
private int emg;
|
||||||
|
private float temperature;
|
||||||
|
private boolean tommyHeartbeat;
|
||||||
|
|
||||||
|
private long timestampPulse = 0;
|
||||||
|
private long timestampTommyPulse = 0;
|
||||||
|
private long timestampEkg = 0;
|
||||||
|
private long timestampEmg = 0;
|
||||||
|
private long timestampTemperature = 0;
|
||||||
|
private long timestampBreath = 0;
|
||||||
|
|
||||||
|
// TODO: hier die timestamps setzen wann letztes mal geändert,
|
||||||
|
// dann kann ich in ActorDisplay im Timer einfach prüfen ob differenz > timeout, dann rot setzen
|
||||||
|
|
||||||
|
|
||||||
|
public void setTimestampPulse() {
|
||||||
|
this.timestampPulse = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
public PulseData getPulseData() {
|
||||||
|
return pulseData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPulseData(PulseData pulseData) {
|
||||||
|
this.pulseData = pulseData;
|
||||||
|
this.timestampPulse = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAirflow() {
|
||||||
|
return airflow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAirflow(int airflow) {
|
||||||
|
this.airflow = airflow;
|
||||||
|
this.timestampBreath = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEkg() {
|
||||||
|
return ekg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEkg(int ekg) {
|
||||||
|
this.ekg = ekg;
|
||||||
|
this.timestampEkg = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEmg() {
|
||||||
|
return emg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmg(int emg) {
|
||||||
|
this.emg = emg;
|
||||||
|
this.timestampEmg = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemperature(float temperature) {
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.timestampTemperature = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getTommyHeartbeat() {
|
||||||
|
return tommyHeartbeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTommyHeartbeat(boolean tommyHeartbeat) {
|
||||||
|
this.tommyHeartbeat = tommyHeartbeat;
|
||||||
|
this.timestampTommyPulse = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestampPulse() {
|
||||||
|
return timestampPulse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestampEkg() {
|
||||||
|
return timestampEkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestampEmg() {
|
||||||
|
return timestampEmg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestampTemperature() {
|
||||||
|
return timestampTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestampBreath() {
|
||||||
|
return timestampBreath;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package de.psychose;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: lucas
|
* @author: lucas
|
||||||
|
@ -14,7 +15,6 @@ public class ActorDisplay {
|
||||||
private final static Color offColor = Color.RED;
|
private final static Color offColor = Color.RED;
|
||||||
private final static String offText = "no data";
|
private final static String offText = "no data";
|
||||||
|
|
||||||
private JPanel actorPanel;
|
|
||||||
private JLabel lblCaption;
|
private JLabel lblCaption;
|
||||||
private JLabel lblHeartbeat;
|
private JLabel lblHeartbeat;
|
||||||
private JLabel lblPulse;
|
private JLabel lblPulse;
|
||||||
|
@ -23,54 +23,32 @@ public class ActorDisplay {
|
||||||
private JLabel lblEmg;
|
private JLabel lblEmg;
|
||||||
private JLabel lblTemperature;
|
private JLabel lblTemperature;
|
||||||
private JLabel lblBreath;
|
private JLabel lblBreath;
|
||||||
|
private JPanel actorPanel;
|
||||||
|
private ActorData actorData;
|
||||||
|
private boolean showErrors = false;
|
||||||
|
private DecimalFormat df = new DecimalFormat("#.0");
|
||||||
|
|
||||||
private int counterHeartbeat = 0;
|
//TODO: die einzelnen Setter wegmachen, dafür eine setData() bauen die die daten en bloc nimmt
|
||||||
private int counterPulse = 0;
|
// die darin enthaltenen timestamps dann für rotfärbung nehmen
|
||||||
private int counterOxy = 0;
|
|
||||||
private int counterEkg = 0;
|
|
||||||
private int counterEmg = 0;
|
|
||||||
private int counterTemperature = 0;
|
|
||||||
private int counterBreath = 0;
|
|
||||||
|
|
||||||
private int timeout = 20; // 20 * 100ms
|
public void setActorData(ActorData actorData) {
|
||||||
|
this.actorData = actorData;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCaption(String caption) {
|
public void setCaption(String caption) {
|
||||||
lblCaption.setText(caption);
|
lblCaption.setText(caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBreath(String breath) {
|
public void update() {
|
||||||
lblBreath.setText(breath);
|
lblBreath.setText(String.valueOf(actorData.getAirflow()));
|
||||||
counterBreath = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemperature(String temperature) {
|
lblTemperature.setText(df.format(actorData.getTemperature()));
|
||||||
lblTemperature.setText(temperature);
|
lblEkg.setText(String.valueOf(actorData.getEkg()));
|
||||||
counterTemperature = 0;
|
lblPulse.setText(actorData.getPulseData().getHeartbeat() == 0 ? "systole" : "diastole");
|
||||||
}
|
lblEmg.setText(String.valueOf(actorData.getEmg()));
|
||||||
|
lblOxy.setText(String.valueOf(actorData.getPulseData().getOxygen()));
|
||||||
|
lblHeartbeat.setText(String.valueOf(actorData.getPulseData().getPulse()));
|
||||||
|
|
||||||
public void setEkg(String value) {
|
|
||||||
lblEkg.setText(value);
|
|
||||||
counterEkg = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPulse(String pulse) {
|
|
||||||
lblPulse.setText(pulse);
|
|
||||||
counterPulse = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmg(String emg) {
|
|
||||||
lblEmg.setText(emg);
|
|
||||||
counterEmg = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOxy(String oxy) {
|
|
||||||
lblOxy.setText(oxy);
|
|
||||||
counterOxy = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHeartbeat(String heartbeat) {
|
|
||||||
lblHeartbeat.setText(heartbeat);
|
|
||||||
counterHeartbeat = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActorDisplay() {
|
public ActorDisplay() {
|
||||||
|
@ -78,62 +56,65 @@ public class ActorDisplay {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
if (++counterTemperature > timeout) {
|
if (actorData == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
|
if (showErrors) {
|
||||||
|
|
||||||
|
long timeout = System.currentTimeMillis() - 1000;
|
||||||
|
|
||||||
|
if (actorData.getTimestampTemperature() < timeout) {
|
||||||
lblTemperature.setForeground(offColor);
|
lblTemperature.setForeground(offColor);
|
||||||
lblTemperature.setText(offText);
|
lblTemperature.setText(offText);
|
||||||
} else {
|
} else {
|
||||||
lblTemperature.setForeground(onColor);
|
lblTemperature.setForeground(onColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++counterPulse > timeout) {
|
if (actorData.getTimestampPulse() < timeout) {
|
||||||
lblPulse.setForeground(offColor);
|
lblPulse.setForeground(offColor);
|
||||||
lblPulse.setText(offText);
|
lblPulse.setText(offText);
|
||||||
} else {
|
|
||||||
lblPulse.setForeground(onColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (++counterOxy > timeout) {
|
|
||||||
lblOxy.setForeground(offColor);
|
lblOxy.setForeground(offColor);
|
||||||
lblOxy.setText(offText);
|
lblOxy.setText(offText);
|
||||||
|
lblHeartbeat.setForeground(offColor);
|
||||||
|
lblHeartbeat.setText(offText);
|
||||||
} else {
|
} else {
|
||||||
|
lblPulse.setForeground(onColor);
|
||||||
lblOxy.setForeground(onColor);
|
lblOxy.setForeground(onColor);
|
||||||
|
lblHeartbeat.setForeground(onColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++counterEkg > timeout) {
|
if (actorData.getTimestampEkg() < timeout) {
|
||||||
lblEkg.setForeground(offColor);
|
lblEkg.setForeground(offColor);
|
||||||
lblEkg.setText(offText);
|
lblEkg.setText(offText);
|
||||||
} else {
|
} else {
|
||||||
lblEkg.setForeground(onColor);
|
lblEkg.setForeground(onColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++counterEmg > timeout) {
|
if (actorData.getTimestampEmg() < timeout) {
|
||||||
lblEmg.setForeground(offColor);
|
lblEmg.setForeground(offColor);
|
||||||
lblEmg.setText(offText);
|
lblEmg.setText(offText);
|
||||||
} else {
|
} else {
|
||||||
lblEmg.setForeground(onColor);
|
lblEmg.setForeground(onColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++counterHeartbeat > timeout) {
|
if (actorData.getTimestampBreath() < timeout) {
|
||||||
lblHeartbeat.setForeground(offColor);
|
|
||||||
lblHeartbeat.setText(offText);
|
|
||||||
} else {
|
|
||||||
lblHeartbeat.setForeground(onColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (++counterBreath > timeout) {
|
|
||||||
lblBreath.setForeground(offColor);
|
lblBreath.setForeground(offColor);
|
||||||
lblBreath.setText(offText);
|
lblBreath.setText(offText);
|
||||||
} else {
|
} else {
|
||||||
lblBreath.setForeground(onColor);
|
lblBreath.setForeground(onColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.timer.setRepeats(true);
|
|
||||||
}
|
timer.setRepeats(true);
|
||||||
|
timer.start();
|
||||||
public void startErrorTimer() {
|
|
||||||
this.timer.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setShowErrors(boolean showErrors) {
|
||||||
|
this.showErrors = showErrors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.ActorHeart">
|
||||||
|
<grid id="27dc6" binding="heartPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="789" height="299"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<background color="-16777216"/>
|
||||||
|
<enabled value="true"/>
|
||||||
|
<focusable value="false"/>
|
||||||
|
<maximumSize width="789" height="299"/>
|
||||||
|
<minimumSize width="789" height="299"/>
|
||||||
|
<preferredSize width="789" height="299"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
</form>
|
|
@ -0,0 +1,67 @@
|
||||||
|
package de.psychose;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lucas
|
||||||
|
* @date: 15.11.14 21:36
|
||||||
|
*/
|
||||||
|
public class ActorHeart {
|
||||||
|
private JPanel heartPanel;
|
||||||
|
private ActorData actorData1;
|
||||||
|
private ActorData actorData2;
|
||||||
|
private ActorData actorData3;
|
||||||
|
private ImagePanel imagePanel;
|
||||||
|
private Timer timer;
|
||||||
|
|
||||||
|
public ActorHeart() {
|
||||||
|
imagePanel = new ImagePanel("/de/psychose/heart1_klein_inv.jpg", "/de/psychose/heart2_klein_inv.jpg");
|
||||||
|
heartPanel.add(imagePanel);
|
||||||
|
|
||||||
|
timer = new Timer(100, new AbstractAction() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(actorData1 != null && actorData2 != null && actorData3 != null) {
|
||||||
|
imagePanel.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer.setRepeats(true);
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActorData(final ActorData actorData1, final ActorData actorData2, final ActorData actorData3) {
|
||||||
|
this.actorData1 = actorData1;
|
||||||
|
this.actorData2 = actorData2;
|
||||||
|
this.actorData3 = actorData3;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ImagePanel extends JPanel {
|
||||||
|
private BufferedImage image1;
|
||||||
|
private BufferedImage image2;
|
||||||
|
|
||||||
|
public ImagePanel(String imageA, String imageB) {
|
||||||
|
try {
|
||||||
|
image1 = ImageIO.read(getClass().getResourceAsStream(imageA));
|
||||||
|
image2 = ImageIO.read(getClass().getResourceAsStream(imageB));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
if(actorData1 != null && actorData2 != null && actorData3 != null) {
|
||||||
|
g.drawImage(ActorHeart.this.actorData1.getTommyHeartbeat() ? image1 : image2, 0, 0, null, null);
|
||||||
|
g.drawImage(ActorHeart.this.actorData2.getTommyHeartbeat() ? image1 : image2, 263, 0, null, null);
|
||||||
|
g.drawImage(ActorHeart.this.actorData3.getTommyHeartbeat() ? image1 : image2, 526, 0, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,7 +23,12 @@ public class ChaOSCclient {
|
||||||
|
|
||||||
public ChaOSCclient(String host, int port) throws UnknownHostException, SocketException {
|
public ChaOSCclient(String host, int port) throws UnknownHostException, SocketException {
|
||||||
portOut = new OSCPortOut(InetAddress.getByName(host), port);
|
portOut = new OSCPortOut(InetAddress.getByName(host), port);
|
||||||
|
try {
|
||||||
portIn = new OSCPortIn(OSC_CLIENT_PORT);
|
portIn = new OSCPortIn(OSC_CLIENT_PORT);
|
||||||
|
} catch (SocketException se) {
|
||||||
|
System.out.println("Port " + OSC_CLIENT_PORT + " already in use. Trying " + OSC_CLIENT_PORT + 1);
|
||||||
|
portIn = new OSCPortIn(OSC_CLIENT_PORT + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(String address, OSCListener listener) {
|
public void addListener(String address, OSCListener listener) {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.ControlForm">
|
||||||
|
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="704" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<nested-form id="680ad" form-file="de/psychose/PulseControl.form" binding="pulse1">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</nested-form>
|
||||||
|
<nested-form id="8c36a" form-file="de/psychose/PulseControl.form" binding="pulse2">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</nested-form>
|
||||||
|
<nested-form id="94992" form-file="de/psychose/PulseControl.form" binding="pulse3">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</nested-form>
|
||||||
|
<nested-form id="c060f" form-file="de/psychose/ActorDisplay.form" binding="actor1">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</nested-form>
|
||||||
|
<nested-form id="abfde" form-file="de/psychose/ActorDisplay.form" binding="actor2">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</nested-form>
|
||||||
|
<nested-form id="97d21" form-file="de/psychose/ActorDisplay.form" binding="actor3">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</nested-form>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
|
@ -0,0 +1,54 @@
|
||||||
|
package de.psychose;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.Observer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: lucas
|
||||||
|
* @date: 15.11.14 22:23
|
||||||
|
*/
|
||||||
|
public class ControlForm {
|
||||||
|
private PulseControl pulse1;
|
||||||
|
private PulseControl pulse2;
|
||||||
|
private PulseControl pulse3;
|
||||||
|
private JPanel mainPanel;
|
||||||
|
private ActorDisplay actor1;
|
||||||
|
private ActorDisplay actor2;
|
||||||
|
private ActorDisplay actor3;
|
||||||
|
|
||||||
|
private final ChaOSCclient osCclient;
|
||||||
|
|
||||||
|
public JPanel getMainPanel() {
|
||||||
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ControlForm(ChaOSCclient chaOSCclient, final ActorData actorData1, final ActorData actorData2, final ActorData actorData3) {
|
||||||
|
this.osCclient = chaOSCclient;
|
||||||
|
|
||||||
|
addActor("merle", pulse1, actor1, actorData1);
|
||||||
|
addActor("uwe", pulse2, actor2, actorData2);
|
||||||
|
addActor("bjoern", pulse3, actor3, actorData3);
|
||||||
|
|
||||||
|
actor1.setShowErrors(true);
|
||||||
|
actor2.setShowErrors(true);
|
||||||
|
actor3.setShowErrors(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addActor(final String actor, PulseControl pulse, ActorDisplay display, ActorData actorData) {
|
||||||
|
pulse.addObserver(new Observer() {
|
||||||
|
@Override
|
||||||
|
public void update(Observable o, Object arg) {
|
||||||
|
if(arg instanceof PulseData) {
|
||||||
|
final PulseData data = (PulseData)arg;
|
||||||
|
osCclient.sendPulse(actor, data.getHeartbeat(), data.getPulse(), data.getOxygen());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
display.setCaption(actor);
|
||||||
|
display.setActorData(actorData);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,60 +1,192 @@
|
||||||
package de.psychose;
|
package de.psychose;
|
||||||
|
|
||||||
|
import com.illposed.osc.OSCListener;
|
||||||
|
import com.illposed.osc.OSCMessage;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: lucas
|
* @author: lucas
|
||||||
* @date: 25.04.14 00:23
|
* @date: 25.04.14 00:23
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
private ChaOSCclient chaOSCclient;
|
||||||
|
private ControlForm controlForm;
|
||||||
|
private MainForm mainForm;
|
||||||
|
|
||||||
|
private int totalMessageCount = 0;
|
||||||
|
private int messagesTempCounter = 0;
|
||||||
|
|
||||||
|
private long totalTraffic = 0;
|
||||||
|
private long lastTraffic = 0;
|
||||||
|
|
||||||
|
private final ActorData actorData1 = new ActorData();
|
||||||
|
private final ActorData actorData2 = new ActorData();
|
||||||
|
private final ActorData actorData3 = new ActorData();
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new Main();
|
||||||
final boolean showErrors = args.length > 0;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
|
|
||||||
UIManager.setLookAndFeel( "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" );
|
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
|
||||||
{
|
public Main() {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final ChaOSCclient chaOSCclient = new ChaOSCclient("chaosc", 7110);
|
this.chaOSCclient = new ChaOSCclient("chaosc", 7110);
|
||||||
final SnmpStatClient snmp = new SnmpStatClient("switch/161");
|
this.controlForm = new ControlForm(chaOSCclient, actorData1, actorData2, actorData3);
|
||||||
final MainForm mainForm = new MainForm(showErrors, chaOSCclient, snmp);
|
|
||||||
final JFrame frame = new JFrame("MainForm");
|
final JFrame cframe = new JFrame("HD Control");
|
||||||
|
cframe.setContentPane(controlForm.getMainPanel());
|
||||||
|
cframe.setResizable(false);
|
||||||
|
cframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
cframe.pack();
|
||||||
|
|
||||||
|
|
||||||
|
this.mainForm = new MainForm(actorData1, actorData2, actorData3);
|
||||||
|
final JFrame frame = new JFrame("HD Main");
|
||||||
frame.setContentPane(mainForm.getMainPanel());
|
frame.setContentPane(mainForm.getMainPanel());
|
||||||
frame.setResizable(false);
|
frame.setResizable(false);
|
||||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
// frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||||
|
frame.setUndecorated(true);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
|
|
||||||
frame.addWindowListener(new WindowAdapter() {
|
frame.addWindowListener(new WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
chaOSCclient.stopReceiver();
|
chaOSCclient.stopReceiver();
|
||||||
snmp.stopRunning();
|
// snmp.stopRunning();
|
||||||
super.windowClosing(e);
|
super.windowClosing(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frame.setVisible(true);
|
|
||||||
|
|
||||||
new Streamer(8888, mainForm.getMainPanel()).run();
|
addActor("merle", actorData1);
|
||||||
|
addActor("uwe", actorData2);
|
||||||
|
addActor("bjoern", actorData3);
|
||||||
|
|
||||||
|
cframe.setVisible(true);
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
chaOSCclient.startReceiver();
|
chaOSCclient.startReceiver();
|
||||||
|
|
||||||
} catch (UnknownHostException | SocketException e) {
|
} catch (UnknownHostException | SocketException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addActor(final String actor, final ActorData actorData) {
|
||||||
|
|
||||||
|
chaOSCclient.addListener("/" + actor.toLowerCase() + "/heartbeat", new OSCListener() {
|
||||||
|
@Override
|
||||||
|
public void acceptMessage(Date time, OSCMessage message) {
|
||||||
|
if (message.getArguments().length == 3) {
|
||||||
|
totalMessageCount++;
|
||||||
|
|
||||||
|
if (message.getArguments()[1] instanceof Integer) {
|
||||||
|
int pulse = (int) (message.getArguments()[1]);
|
||||||
|
|
||||||
|
if (pulse > 60) { // try to skip the invalid pulserate from device
|
||||||
|
|
||||||
|
// set the heartrate
|
||||||
|
actorData.getPulseData().setPulse((int) (message.getArguments()[1]));
|
||||||
|
|
||||||
|
// set the beat ( 0 or 1 )
|
||||||
|
if (message.getArguments()[0] instanceof Integer) {
|
||||||
|
actorData.getPulseData().setHeartbeat((int) (message.getArguments()[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: remove this, its for testing without tommy only
|
||||||
|
actorData.setTommyHeartbeat(((int) message.getArguments()[0]) == 1);
|
||||||
|
|
||||||
|
// set the oxy level
|
||||||
|
if (message.getArguments()[2] instanceof Integer) {
|
||||||
|
actorData.getPulseData().setOxygen((int) (message.getArguments()[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
actorData.setTimestampPulse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chaOSCclient.addListener("/" + actor.toLowerCase() + "/ekg", new OSCListener() {
|
||||||
|
@Override
|
||||||
|
public void acceptMessage(Date time, OSCMessage message) {
|
||||||
|
if (message.getArguments().length == 1) {
|
||||||
|
totalMessageCount++;
|
||||||
|
|
||||||
|
if (message.getArguments()[0] instanceof Integer) {
|
||||||
|
actorData.setEkg((int) (message.getArguments()[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chaOSCclient.addListener("/" + actor.toLowerCase() + "/emg", new OSCListener() {
|
||||||
|
@Override
|
||||||
|
public void acceptMessage(Date time, OSCMessage message) {
|
||||||
|
if (message.getArguments().length == 1) {
|
||||||
|
totalMessageCount++;
|
||||||
|
|
||||||
|
if (message.getArguments()[0] instanceof Integer) {
|
||||||
|
actorData.setEmg((int) (message.getArguments()[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chaOSCclient.addListener("/" + actor.toLowerCase() + "/temperatur", new OSCListener() {
|
||||||
|
@Override
|
||||||
|
public void acceptMessage(Date time, OSCMessage message) {
|
||||||
|
if (message.getArguments().length == 1) {
|
||||||
|
totalMessageCount++;
|
||||||
|
|
||||||
|
if (message.getArguments()[0] instanceof Float) {
|
||||||
|
actorData.setTemperature((float) (message.getArguments()[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chaOSCclient.addListener("/" + actor.toLowerCase() + "/airFlow", new OSCListener() {
|
||||||
|
@Override
|
||||||
|
public void acceptMessage(Date time, OSCMessage message) {
|
||||||
|
if (message.getArguments().length == 1) {
|
||||||
|
totalMessageCount++;
|
||||||
|
|
||||||
|
if (message.getArguments()[0] instanceof Integer) {
|
||||||
|
actorData.setAirflow((int) (message.getArguments()[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chaOSCclient.addListener("/" + actor.toLowerCase() + "/tommypuls", new OSCListener() {
|
||||||
|
@Override
|
||||||
|
public void acceptMessage(Date time, OSCMessage message) {
|
||||||
|
if (message.getArguments().length == 1) {
|
||||||
|
totalMessageCount++;
|
||||||
|
|
||||||
|
if (message.getArguments()[0] instanceof Integer) {
|
||||||
|
actorData.setTommyHeartbeat((boolean) (message.getArguments()[0]));
|
||||||
|
}
|
||||||
|
//TODO: evtl muss das oben hier noch anders
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,74 +1,52 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.MainForm">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.MainForm">
|
||||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="5" left="5" bottom="5" right="5"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="20" y="20" width="720" height="576"/>
|
<xy x="0" y="0" width="810" height="670"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<background color="-16777216"/>
|
<background color="-16777216"/>
|
||||||
<foreground color="-1"/>
|
<foreground color="-1"/>
|
||||||
<maximumSize width="720" height="576"/>
|
<maximumSize width="1000" height="1000"/>
|
||||||
<minimumSize width="720" height="576"/>
|
<minimumSize width="810" height="670"/>
|
||||||
<preferredSize width="720" height="576"/>
|
<preferredSize width="810" height="670"/>
|
||||||
</properties>
|
</properties>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<hspacer id="f912c">
|
<nested-form id="7ac3d" form-file="de/psychose/ActorDisplay.form" binding="actor1">
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="5" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<hspacer id="6a2b8">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="1" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<hspacer id="67192">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="3" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<nested-form id="5519b" form-file="de/psychose/StatsDisplay.form" binding="statDisplay">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</nested-form>
|
|
||||||
<vspacer id="ad2ab">
|
|
||||||
<constraints>
|
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
<nested-form id="736bf" form-file="de/psychose/ActorDisplay.form" binding="actor2">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</nested-form>
|
|
||||||
<nested-form id="7fe82" form-file="de/psychose/ActorDisplay.form" binding="actor3">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</nested-form>
|
|
||||||
<nested-form id="bd9b" form-file="de/psychose/ActorDisplay.form" binding="actor1">
|
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</nested-form>
|
</nested-form>
|
||||||
<nested-form id="5b53" form-file="de/psychose/PulseControl.form" binding="pulse1">
|
<nested-form id="e6dc4" form-file="de/psychose/ActorHeart.form" binding="heart1">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</nested-form>
|
</nested-form>
|
||||||
<nested-form id="4c934" form-file="de/psychose/PulseControl.form" binding="pulse2">
|
<nested-form id="18353" form-file="de/psychose/ActorDisplay.form" binding="actor2">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</nested-form>
|
</nested-form>
|
||||||
<nested-form id="f9eb3" form-file="de/psychose/PulseControl.form" binding="pulse3">
|
<nested-form id="d8afa" form-file="de/psychose/ActorDisplay.form" binding="actor3">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</nested-form>
|
</nested-form>
|
||||||
|
<component id="fe39c" class="javax.swing.JLabel" binding="breath">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<enabled value="true"/>
|
||||||
|
<font name="Serif" size="72"/>
|
||||||
|
<foreground color="-1"/>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="123"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,153 +1,49 @@
|
||||||
package de.psychose;
|
package de.psychose;
|
||||||
|
|
||||||
import com.illposed.osc.OSCListener;
|
|
||||||
import com.illposed.osc.OSCMessage;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.util.Date;
|
import java.text.DecimalFormat;
|
||||||
import java.util.Observable;
|
|
||||||
import java.util.Observer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: lucas
|
* @author: lucas
|
||||||
* @date: 14.04.14 21:43
|
* @date: 14.04.14 21:43
|
||||||
*/
|
*/
|
||||||
public class MainForm {
|
public class MainForm {
|
||||||
private final ChaOSCclient osCclient;
|
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
|
private ActorHeart heart1;
|
||||||
private ActorDisplay actor1;
|
private ActorDisplay actor1;
|
||||||
private ActorDisplay actor2;
|
private ActorDisplay actor2;
|
||||||
private ActorDisplay actor3;
|
private ActorDisplay actor3;
|
||||||
private StatsDisplay statDisplay;
|
private JLabel breath;
|
||||||
private PulseControl pulse1;
|
private final DecimalFormat df = new DecimalFormat("#.0");
|
||||||
private PulseControl pulse2;
|
|
||||||
private PulseControl pulse3;
|
|
||||||
|
|
||||||
private int totalMessageCount = 0;
|
|
||||||
private int messagesTempCounter = 0;
|
|
||||||
|
|
||||||
private long totalTraffic = 0;
|
|
||||||
private long lastTraffic = 0;
|
|
||||||
|
|
||||||
public JPanel getMainPanel() {
|
public JPanel getMainPanel() {
|
||||||
return mainPanel;
|
return mainPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainForm(final boolean showErrors, final ChaOSCclient chaOSCclient, final SnmpStatClient snmpStatClient) {
|
public MainForm(final ActorData actorData1, final ActorData actorData2, final ActorData actorData3) {
|
||||||
this.osCclient = chaOSCclient;
|
|
||||||
|
|
||||||
addActor("merle", "Körper 1", actor1, pulse1);
|
actor1.setCaption("Körper 1");
|
||||||
addActor("uwe", "Körper 2", actor2, pulse2);
|
actor2.setCaption("Körper 2");
|
||||||
addActor("bjoern", "Körper 3", actor3, pulse3);
|
actor3.setCaption("Körper 3");
|
||||||
|
actor1.setActorData(actorData1);
|
||||||
|
actor2.setActorData(actorData2);
|
||||||
|
actor3.setActorData(actorData3);
|
||||||
|
heart1.setActorData(actorData1, actorData2, actorData3);
|
||||||
|
|
||||||
|
final Timer timer = new Timer(100, new AbstractAction() {
|
||||||
final Timer timer = new Timer(1000, new AbstractAction() {
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
statDisplay.setMessagesPerSec(String.valueOf(totalMessageCount - messagesTempCounter));
|
breath.setText(String.valueOf(actorData1.getAirflow()));
|
||||||
statDisplay.setMessageCount(String.valueOf(totalMessageCount));
|
|
||||||
messagesTempCounter = totalMessageCount;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
timer.setRepeats(true);
|
timer.setRepeats(true);
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
final Timer snmpTimer = new Timer(5000, new AbstractAction() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
totalTraffic = snmpStatClient.getTrafficSum(); // in kB
|
|
||||||
statDisplay.setTotalTraffic(String.valueOf(totalTraffic));
|
|
||||||
statDisplay.setBandwidth(String.valueOf((totalTraffic - lastTraffic) / 5));
|
|
||||||
lastTraffic = totalTraffic;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
snmpTimer.setRepeats(true);
|
|
||||||
snmpStatClient.start();
|
|
||||||
|
|
||||||
|
|
||||||
if(showErrors) {
|
|
||||||
actor1.startErrorTimer();
|
|
||||||
actor2.startErrorTimer();
|
|
||||||
actor3.startErrorTimer();
|
|
||||||
snmpTimer.start();
|
|
||||||
} else {
|
|
||||||
pulse1.hide();
|
|
||||||
pulse2.hide();
|
|
||||||
pulse3.hide();
|
|
||||||
statDisplay.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void addActor(final String actor, final String label, final ActorDisplay actorDisplay, final PulseControl pulse) {
|
|
||||||
actorDisplay.setCaption(label);
|
|
||||||
osCclient.addListener("/" + actor.toLowerCase() + "/heartbeat", new OSCListener() {
|
|
||||||
@Override
|
|
||||||
public void acceptMessage(Date time, OSCMessage message) {
|
|
||||||
if (message.getArguments().length == 3) {
|
|
||||||
totalMessageCount++;
|
|
||||||
actorDisplay.setHeartbeat(message.getArguments()[0].toString().equals("0") ? "Systole" : "Diastole");
|
|
||||||
actorDisplay.setPulse(message.getArguments()[1].toString());
|
|
||||||
actorDisplay.setOxy(message.getArguments()[2].toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
osCclient.addListener("/" + actor.toLowerCase() + "/ekg", new OSCListener() {
|
|
||||||
@Override
|
|
||||||
public void acceptMessage(Date time, OSCMessage message) {
|
|
||||||
if (message.getArguments().length == 1) {
|
|
||||||
totalMessageCount++;
|
|
||||||
actorDisplay.setEkg(message.getArguments()[0].toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
osCclient.addListener("/" + actor.toLowerCase() + "/emg", new OSCListener() {
|
|
||||||
@Override
|
|
||||||
public void acceptMessage(Date time, OSCMessage message) {
|
|
||||||
if (message.getArguments().length == 1) {
|
|
||||||
totalMessageCount++;
|
|
||||||
actorDisplay.setEmg(message.getArguments()[0].toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
osCclient.addListener("/" + actor.toLowerCase() + "/temperatur", new OSCListener() {
|
|
||||||
@Override
|
|
||||||
public void acceptMessage(Date time, OSCMessage message) {
|
|
||||||
if (message.getArguments().length == 1) {
|
|
||||||
totalMessageCount++;
|
|
||||||
actorDisplay.setTemperature(message.getArguments()[0].toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
osCclient.addListener("/" + actor.toLowerCase() + "/airFlow", new OSCListener() {
|
|
||||||
@Override
|
|
||||||
public void acceptMessage(Date time, OSCMessage message) {
|
|
||||||
if (message.getArguments().length == 1) {
|
|
||||||
totalMessageCount++;
|
|
||||||
actorDisplay.setBreath(message.getArguments()[0].toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
pulse.addObserver(new Observer() {
|
|
||||||
@Override
|
|
||||||
public void update(Observable o, Object arg) {
|
|
||||||
if(arg instanceof PulseData) {
|
|
||||||
final PulseData data = (PulseData)arg;
|
|
||||||
osCclient.sendPulse(actor, data.getHeartbeat(), data.getPulse(), data.getOxygen());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
<xy x="20" y="20" width="261" height="38"/>
|
<xy x="20" y="20" width="261" height="38"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<background color="-16777216"/>
|
|
||||||
<foreground color="-1"/>
|
<foreground color="-1"/>
|
||||||
</properties>
|
</properties>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
|
@ -16,7 +15,6 @@
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<foreground color="-1"/>
|
|
||||||
<selected value="false"/>
|
<selected value="false"/>
|
||||||
<text value="Enable"/>
|
<text value="Enable"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class PulseControl extends Observable {
|
||||||
int pulse = pulseWobbleCenter - PULSE_WOBBLE_WIDTH / 2 + random.nextInt(PULSE_WOBBLE_WIDTH);
|
int pulse = pulseWobbleCenter - PULSE_WOBBLE_WIDTH / 2 + random.nextInt(PULSE_WOBBLE_WIDTH);
|
||||||
|
|
||||||
if(pulse < 60) pulse = 60;
|
if(pulse < 60) pulse = 60;
|
||||||
if(pulse > 180) pulse = 180;
|
if(pulse > 230) pulse = 230;
|
||||||
|
|
||||||
final PulseData data = new PulseData(heartbeat, pulse, 95 + random.nextInt(4));
|
final PulseData data = new PulseData(heartbeat, pulse, 95 + random.nextInt(4));
|
||||||
setChanged();
|
setChanged();
|
||||||
|
@ -51,7 +51,6 @@ public class PulseControl extends Observable {
|
||||||
enableCheckBox.addItemListener(new ItemListener() {
|
enableCheckBox.addItemListener(new ItemListener() {
|
||||||
@Override
|
@Override
|
||||||
public void itemStateChanged(ItemEvent e) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
System.out.println("item state changed");
|
|
||||||
JCheckBox checkBox = (JCheckBox)e.getSource();
|
JCheckBox checkBox = (JCheckBox)e.getSource();
|
||||||
if(checkBox.isSelected()) {
|
if(checkBox.isSelected()) {
|
||||||
if(!timer.isRunning()) {
|
if(!timer.isRunning()) {
|
||||||
|
@ -69,8 +68,4 @@ public class PulseControl extends Observable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide() {
|
|
||||||
this.pulsePanel.setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,129 +0,0 @@
|
||||||
package de.psychose;
|
|
||||||
|
|
||||||
import org.snmp4j.CommunityTarget;
|
|
||||||
import org.snmp4j.Snmp;
|
|
||||||
import org.snmp4j.TransportMapping;
|
|
||||||
import org.snmp4j.mp.SnmpConstants;
|
|
||||||
import org.snmp4j.smi.OID;
|
|
||||||
import org.snmp4j.smi.OctetString;
|
|
||||||
import org.snmp4j.smi.UdpAddress;
|
|
||||||
import org.snmp4j.smi.VariableBinding;
|
|
||||||
import org.snmp4j.transport.DefaultUdpTransportMapping;
|
|
||||||
import org.snmp4j.util.DefaultPDUFactory;
|
|
||||||
import org.snmp4j.util.TreeEvent;
|
|
||||||
import org.snmp4j.util.TreeUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 18.04.14 12:10
|
|
||||||
*/
|
|
||||||
public class SnmpStatClient extends Thread {
|
|
||||||
private final int napTime = 5000;
|
|
||||||
public static final String OID_COUNTER = "1.3.6.1.2.1.2.2.1.10";
|
|
||||||
private HashMap<Integer, Long> lastPorts = new HashMap<>();
|
|
||||||
private HashMap<Integer, Long> sumPorts = new HashMap<>();
|
|
||||||
private Snmp snmp;
|
|
||||||
private CommunityTarget communityTarget;
|
|
||||||
private long currentTrafficSum = 0;
|
|
||||||
private Boolean doRun = true;
|
|
||||||
|
|
||||||
private CommunityTarget getCommunityTarget(String host) {
|
|
||||||
CommunityTarget communityTarget = new CommunityTarget();
|
|
||||||
communityTarget.setCommunity(new OctetString("public"));
|
|
||||||
communityTarget.setVersion(SnmpConstants.version2c);
|
|
||||||
communityTarget.setAddress(new UdpAddress(host));
|
|
||||||
communityTarget.setTimeout(300);
|
|
||||||
return communityTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SnmpStatClient(String host) {
|
|
||||||
try {
|
|
||||||
final TransportMapping transportMapping = new DefaultUdpTransportMapping();
|
|
||||||
transportMapping.listen();
|
|
||||||
|
|
||||||
this.communityTarget = getCommunityTarget(host);
|
|
||||||
this.snmp = new Snmp(transportMapping);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
System.out.println("error: cannot get traffic from snmp target");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRunning() {
|
|
||||||
doRun = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (snmp == null || this.communityTarget == null) {
|
|
||||||
System.out.println("snmp error");
|
|
||||||
doRun = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (doRun && !Thread.interrupted()) {
|
|
||||||
long sleepTill = System.currentTimeMillis() + napTime;
|
|
||||||
|
|
||||||
getSNMPValues();
|
|
||||||
|
|
||||||
try {
|
|
||||||
long remainingTime = sleepTill - System.currentTimeMillis();
|
|
||||||
if (remainingTime > 0)
|
|
||||||
Thread.sleep(remainingTime);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getSNMPValues() {
|
|
||||||
if (snmp == null || this.communityTarget == null) {
|
|
||||||
System.out.println("snmp error");
|
|
||||||
doRun = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
long sum = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
final TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory());
|
|
||||||
final List<TreeEvent> treeEventList = treeUtils.getSubtree(this.communityTarget, new OID(OID_COUNTER));
|
|
||||||
|
|
||||||
for (TreeEvent treeEvent : treeEventList) {
|
|
||||||
if (treeEvent.getStatus() == TreeEvent.STATUS_OK) {
|
|
||||||
for (VariableBinding binding : treeEvent.getVariableBindings()) {
|
|
||||||
int oid = binding.getOid().last();
|
|
||||||
long value = binding.getVariable().toLong() / 1024; // convert bytes down to kilobytes
|
|
||||||
long lastValue = 0;
|
|
||||||
if (lastPorts.containsKey(oid)) lastValue = lastPorts.get(oid);
|
|
||||||
long diff = value - lastValue;
|
|
||||||
|
|
||||||
if (diff > 0) {
|
|
||||||
sumPorts.put(oid, lastValue + diff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
System.out.println("error: could not resolve address from snmp target");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (long port : sumPorts.values()) {
|
|
||||||
sum += port;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentTrafficSum = sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTrafficSum() {
|
|
||||||
return currentTrafficSum;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,112 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.StatsDisplay">
|
|
||||||
<grid id="27dc6" binding="statPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<xy x="20" y="20" width="248" height="180"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-16777216"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<minimumSize width="220" height="180"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<component id="69530" class="javax.swing.JLabel" binding="lblCaption">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="28" style="1"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="Statistik"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<vspacer id="9a59f">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
<component id="1d950" class="javax.swing.JLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="20"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="Events"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="442f5" class="javax.swing.JLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="20"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="Ev/Sek"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="54c59" class="javax.swing.JLabel" binding="lblMessageCount">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="20"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="-"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="eaaf9" class="javax.swing.JLabel" binding="lblMessagesPerSec">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="20"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="-"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="95ca8" class="javax.swing.JLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="20"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="kb"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="b1b4b" class="javax.swing.JLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="20"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="kb/Sek"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="af868" class="javax.swing.JLabel" binding="lblTraffic">
|
|
||||||
<constraints>
|
|
||||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="20"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="-"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="88e99" class="javax.swing.JLabel" binding="lblBandwidth">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<font name="Droid Sans Mono" size="20"/>
|
|
||||||
<foreground color="-1"/>
|
|
||||||
<text value="-"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
|
@ -1,37 +0,0 @@
|
||||||
package de.psychose;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: lucas
|
|
||||||
* @date: 18.04.14 02:19
|
|
||||||
*/
|
|
||||||
public class StatsDisplay {
|
|
||||||
private JLabel lblCaption;
|
|
||||||
private JLabel lblMessageCount;
|
|
||||||
private JLabel lblMessagesPerSec;
|
|
||||||
private JPanel statPanel;
|
|
||||||
private JLabel lblTraffic;
|
|
||||||
private JLabel lblBandwidth;
|
|
||||||
|
|
||||||
public void setMessageCount(String count) {
|
|
||||||
lblMessageCount.setText(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessagesPerSec(String messagesPerSec) {
|
|
||||||
lblMessagesPerSec.setText(messagesPerSec);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalTraffic(String totalTraffic) {
|
|
||||||
lblTraffic.setText(totalTraffic);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBandwidth(String bandwidth) {
|
|
||||||
lblBandwidth.setText(bandwidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hide() {
|
|
||||||
this.statPanel.setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,256 +0,0 @@
|
||||||
package de.psychose;
|
|
||||||
|
|
||||||
import org.jboss.netty.bootstrap.ServerBootstrap;
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffers;
|
|
||||||
import org.jboss.netty.channel.*;
|
|
||||||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
|
||||||
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
|
|
||||||
import org.jboss.netty.handler.codec.http.*;
|
|
||||||
import org.jboss.netty.handler.stream.ChunkedInput;
|
|
||||||
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
|
|
||||||
import org.jboss.netty.util.CharsetUtil;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.nio.channels.ClosedChannelException;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
|
|
||||||
import static org.jboss.netty.handler.codec.http.HttpMethod.GET;
|
|
||||||
import static org.jboss.netty.handler.codec.http.HttpResponseStatus.*;
|
|
||||||
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Maurus Cuelenaere <mcuelenaere@gmail.com>
|
|
||||||
* taken from http://blog.maurus.be/2012/05/09/netty-mjpeg-streamer/
|
|
||||||
*/
|
|
||||||
public class Streamer {
|
|
||||||
private final int port;
|
|
||||||
private final Component view;
|
|
||||||
private final ViewRenderer renderer;
|
|
||||||
|
|
||||||
private class ViewRenderer implements Runnable {
|
|
||||||
private final BufferedImage image;
|
|
||||||
private final AtomicReference<byte[]> currentBuffer;
|
|
||||||
private final AtomicInteger listenerCount;
|
|
||||||
private final int napTime;
|
|
||||||
private final ByteArrayOutputStream outputStream;
|
|
||||||
|
|
||||||
public ViewRenderer() {
|
|
||||||
this(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ViewRenderer(int fps) {
|
|
||||||
this.napTime = 1000 / fps;
|
|
||||||
this.listenerCount = new AtomicInteger();
|
|
||||||
this.currentBuffer = new AtomicReference<byte[]>();
|
|
||||||
this.image = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
||||||
this.outputStream = new ByteArrayOutputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (!Thread.interrupted()) {
|
|
||||||
long sleepTill = System.currentTimeMillis() + napTime;
|
|
||||||
|
|
||||||
if (listenerCount.get() > 0) {
|
|
||||||
Graphics g = image.createGraphics();
|
|
||||||
view.paint(g);
|
|
||||||
g.dispose();
|
|
||||||
|
|
||||||
byte[] newData = null;
|
|
||||||
try {
|
|
||||||
ImageIO.write(image, "jpg", outputStream);
|
|
||||||
newData = outputStream.toByteArray();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
outputStream.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newData != null) {
|
|
||||||
currentBuffer.set(newData);
|
|
||||||
synchronized (currentBuffer) {
|
|
||||||
currentBuffer.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
long remainingTime = sleepTill - System.currentTimeMillis();
|
|
||||||
if (remainingTime > 0)
|
|
||||||
Thread.sleep(remainingTime);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerListener() {
|
|
||||||
listenerCount.incrementAndGet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unregisterListener() {
|
|
||||||
listenerCount.decrementAndGet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void waitForData() throws InterruptedException {
|
|
||||||
synchronized (currentBuffer) {
|
|
||||||
currentBuffer.wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getData() {
|
|
||||||
return currentBuffer.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class HttpMultipartReplaceStream implements ChunkedInput {
|
|
||||||
private final byte[] header;
|
|
||||||
private boolean closed;
|
|
||||||
|
|
||||||
public HttpMultipartReplaceStream(String boundary) {
|
|
||||||
this.header = ("--" + boundary + "\r\nContent-Type: image/jpeg\r\n\r\n").getBytes();
|
|
||||||
|
|
||||||
renderer.registerListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws Exception {
|
|
||||||
if (closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
closed = true;
|
|
||||||
renderer.unregisterListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNextChunk() throws Exception {
|
|
||||||
return !closed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEndOfInput() throws Exception {
|
|
||||||
return closed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object nextChunk() throws Exception {
|
|
||||||
if (closed)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
renderer.waitForData();
|
|
||||||
byte[] body = renderer.getData();
|
|
||||||
|
|
||||||
return ChannelBuffers.wrappedBuffer(header, body);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class HttpStreamerHandler extends SimpleChannelUpstreamHandler {
|
|
||||||
@Override
|
|
||||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
|
||||||
HttpRequest request = (HttpRequest) e.getMessage();
|
|
||||||
if (request.getMethod() != GET) {
|
|
||||||
sendError(ctx, METHOD_NOT_ALLOWED);
|
|
||||||
return;
|
|
||||||
} else if (!"/stream".equals(request.getUri())) {
|
|
||||||
sendError(ctx, NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String boundary = "thisisourmagicboundary";
|
|
||||||
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
|
|
||||||
HttpHeaders.setHeader(response, "Connection", "close");
|
|
||||||
HttpHeaders.setHeader(response, "Content-Type", "multipart/x-mixed-replace;boundary=" + boundary);
|
|
||||||
HttpHeaders.setHeader(response, "Cache-control", "no-cache");
|
|
||||||
HttpHeaders.setHeader(response, "Pragma", "no-cache");
|
|
||||||
HttpHeaders.setHeader(response, "Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
|
|
||||||
|
|
||||||
Channel ch = e.getChannel();
|
|
||||||
|
|
||||||
final HttpMultipartReplaceStream replaceStream = new HttpMultipartReplaceStream(boundary);
|
|
||||||
ch.getCloseFuture().addListener(new ChannelFutureListener() {
|
|
||||||
@Override
|
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
|
||||||
// Stop the stream when the channel is closed
|
|
||||||
replaceStream.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Write the initial line and the headers
|
|
||||||
ch.write(response);
|
|
||||||
|
|
||||||
// Write the content
|
|
||||||
ChannelFuture writeFuture = ch.write(replaceStream);
|
|
||||||
|
|
||||||
// Close the connection when the whole content is written out
|
|
||||||
writeFuture.addListener(ChannelFutureListener.CLOSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
|
|
||||||
Channel ch = e.getChannel();
|
|
||||||
Throwable cause = e.getCause();
|
|
||||||
if (cause instanceof TooLongFrameException) {
|
|
||||||
sendError(ctx, BAD_REQUEST);
|
|
||||||
return;
|
|
||||||
} else if (cause instanceof ClosedChannelException) {
|
|
||||||
ch.close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cause.printStackTrace();
|
|
||||||
if (ch.isConnected())
|
|
||||||
sendError(ctx, INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
|
|
||||||
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
|
|
||||||
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
|
|
||||||
response.setContent(ChannelBuffers.copiedBuffer("Failure: " + status.toString() + "\r\n", CharsetUtil.UTF_8));
|
|
||||||
|
|
||||||
// Close the connection as soon as the error message is sent.
|
|
||||||
ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Streamer(int port, Component view) {
|
|
||||||
this.port = port;
|
|
||||||
this.view = view;
|
|
||||||
this.renderer = new ViewRenderer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
// Configure the server.
|
|
||||||
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
|
|
||||||
|
|
||||||
// Set up the event pipeline factory.
|
|
||||||
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
|
|
||||||
@Override
|
|
||||||
public ChannelPipeline getPipeline() throws Exception {
|
|
||||||
// Create a default pipeline implementation.
|
|
||||||
ChannelPipeline pipeline = Channels.pipeline();
|
|
||||||
|
|
||||||
pipeline.addLast("decoder", new HttpRequestDecoder());
|
|
||||||
pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
|
|
||||||
pipeline.addLast("encoder", new HttpResponseEncoder());
|
|
||||||
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
|
|
||||||
pipeline.addLast("handler", new HttpStreamerHandler());
|
|
||||||
|
|
||||||
return pipeline;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Bind and start to accept incoming connections.
|
|
||||||
bootstrap.bind(new InetSocketAddress(port));
|
|
||||||
|
|
||||||
// Start the renderer
|
|
||||||
new Thread(renderer, "Image renderer").start();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
package de.psychose;
|
|
||||||
|
|
||||||
import javax.sound.midi.*;
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
public static final int NOTE_ON = 0x90;
|
|
||||||
public static final int NOTE_OFF = 0x80;
|
|
||||||
public static final String[] NOTE_NAMES = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "H"};
|
|
||||||
|
|
||||||
private static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
|
|
||||||
System.out.printf("Display name: %s%n", netint.getDisplayName());
|
|
||||||
System.out.printf("Name: %s%n", netint.getName());
|
|
||||||
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
|
|
||||||
|
|
||||||
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
|
|
||||||
System.out.printf("InetAddress: %s%n", inetAddress);
|
|
||||||
}
|
|
||||||
System.out.printf("%n");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
|
|
||||||
SnmpStatClient snmpStatClient = new SnmpStatClient("switch/161");
|
|
||||||
|
|
||||||
System.out.println(snmpStatClient.getTrafficSum() / 1024 / 1024 + "MB");
|
|
||||||
|
|
||||||
|
|
||||||
if(true) return;
|
|
||||||
|
|
||||||
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
|
|
||||||
for (NetworkInterface netint : Collections.list(nets)) {
|
|
||||||
displayInterfaceInformation(netint);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(true) return;
|
|
||||||
|
|
||||||
Sequence sequence = MidiSystem.getSequence(new File("/home/lucas/jake-avril_14th.mid"));
|
|
||||||
|
|
||||||
HashSet<String> notes = new HashSet<String>();
|
|
||||||
|
|
||||||
int trackNumber = 0;
|
|
||||||
for (Track track : sequence.getTracks()) {
|
|
||||||
trackNumber++;
|
|
||||||
System.out.println("Track " + trackNumber + ": size = " + track.size());
|
|
||||||
System.out.println();
|
|
||||||
for (int i = 0; i < track.size(); i++) {
|
|
||||||
MidiEvent event = track.get(i);
|
|
||||||
System.out.print("@" + event.getTick() + " ");
|
|
||||||
MidiMessage message = event.getMessage();
|
|
||||||
if (message instanceof ShortMessage) {
|
|
||||||
ShortMessage sm = (ShortMessage) message;
|
|
||||||
System.out.print("Channel: " + sm.getChannel() + " ");
|
|
||||||
if (sm.getCommand() == NOTE_ON) {
|
|
||||||
int key = sm.getData1();
|
|
||||||
int octave = (key / 12) - 1;
|
|
||||||
int note = key % 12;
|
|
||||||
String noteName = NOTE_NAMES[note];
|
|
||||||
int velocity = sm.getData2();
|
|
||||||
System.out.println("Note on, " + noteName + octave + " key=" + key + " velocity: " + velocity);
|
|
||||||
|
|
||||||
notes.add(noteName + octave);
|
|
||||||
|
|
||||||
} else if (sm.getCommand() == NOTE_OFF) {
|
|
||||||
int key = sm.getData1();
|
|
||||||
int octave = (key / 12) - 1;
|
|
||||||
int note = key % 12;
|
|
||||||
String noteName = NOTE_NAMES[note];
|
|
||||||
int velocity = sm.getData2();
|
|
||||||
System.out.println("Note off, " + noteName + octave + " key=" + key + " velocity: " + velocity);
|
|
||||||
} else {
|
|
||||||
System.out.println("Command:" + sm.getCommand());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("Other message: " + message.getClass());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(notes);
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
Binary file not shown.
After Width: | Height: | Size: 51 KiB |
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
Loading…
Reference in New Issue