2016-09-06 16:49:11 +02:00
|
|
|
package org.hwo.pulscounter;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.ByteBuffer;
|
2016-09-15 16:52:11 +02:00
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2016-09-06 16:49:11 +02:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Date;
|
2016-11-21 16:08:15 +01:00
|
|
|
import java.util.UUID;
|
2016-09-06 16:49:11 +02:00
|
|
|
|
|
|
|
import org.hwo.csv.CSVRecord;
|
2016-11-17 16:37:45 +01:00
|
|
|
import org.hwo.models.TableMapper.TableColumn;
|
2016-09-06 16:49:11 +02:00
|
|
|
import org.hwo.servicelink.ServiceLink;
|
2017-03-10 15:11:01 +01:00
|
|
|
import org.hwo.servicelink.exceptions.ServiceLinkException;
|
2016-11-21 16:08:15 +01:00
|
|
|
import org.hwo.ui.diagram.annotation.Plot;
|
2016-09-06 16:49:11 +02:00
|
|
|
|
|
|
|
public class SnapShot {
|
2016-11-21 16:08:15 +01:00
|
|
|
UUID uuid;
|
|
|
|
|
2016-09-13 10:53:46 +02:00
|
|
|
Integer deviceSerial;
|
|
|
|
|
2016-09-15 16:52:11 +02:00
|
|
|
Integer index;
|
2016-09-06 16:49:11 +02:00
|
|
|
Integer timestamp;
|
|
|
|
Integer field0;
|
|
|
|
|
|
|
|
Integer[] values;
|
|
|
|
Integer[] analog;
|
2016-11-17 16:37:45 +01:00
|
|
|
Integer[] merker;
|
2016-09-06 16:49:11 +02:00
|
|
|
|
|
|
|
Integer inputmask,
|
|
|
|
outputmask,
|
|
|
|
pullupmask,
|
|
|
|
invertmask,
|
|
|
|
triggermask;
|
2016-11-17 16:37:45 +01:00
|
|
|
|
|
|
|
static SimpleDateFormat
|
|
|
|
df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
|
|
|
|
|
2016-09-13 10:53:46 +02:00
|
|
|
|
|
|
|
public SnapShot(int deviceSerial){
|
|
|
|
this.deviceSerial = deviceSerial;
|
|
|
|
|
|
|
|
this.values = new Integer[32];
|
|
|
|
this.analog = new Integer[8];
|
2016-11-17 16:37:45 +01:00
|
|
|
this.merker = new Integer[24];
|
2016-09-13 10:53:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-06 16:49:11 +02:00
|
|
|
public SnapShot(){
|
|
|
|
this.values = new Integer[32];
|
|
|
|
this.analog = new Integer[8];
|
|
|
|
}
|
|
|
|
|
|
|
|
public SnapShot(byte[] bytes){
|
|
|
|
this.values = new Integer[32];
|
|
|
|
this.analog = new Integer[8];
|
|
|
|
|
|
|
|
fromBytes(bytes);
|
|
|
|
}
|
|
|
|
|
2016-09-15 16:52:11 +02:00
|
|
|
public SnapShot(ResultSet rs) throws SQLException {
|
|
|
|
this.values = new Integer[32];
|
|
|
|
this.analog = new Integer[8];
|
|
|
|
|
|
|
|
this.deviceSerial = rs.getInt("device");
|
|
|
|
this.index = rs.getInt("snap_id");
|
|
|
|
this.timestamp = rs.getInt("timestamp");
|
|
|
|
this.inputmask = rs.getInt("inputs");
|
|
|
|
this.outputmask = rs.getInt("outputs");
|
|
|
|
this.invertmask = rs.getInt("inverts");
|
|
|
|
this.triggermask = 0;
|
|
|
|
this.pullupmask = rs.getInt("pullups");
|
|
|
|
this.field0 = rs.getInt("field0");
|
|
|
|
|
|
|
|
Object[] va = (Object[])rs.getArray("counters").getArray();
|
|
|
|
for (int i=0;i<32;i++){
|
|
|
|
this.values[i] = (Integer)va[i];
|
|
|
|
}
|
|
|
|
va = (Object[])rs.getArray("analogs").getArray();
|
|
|
|
for (int i=0;i<8;i++){
|
|
|
|
this.analog[i] = (Integer)va[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-17 16:37:45 +01:00
|
|
|
@TableColumn(label="Gerät",order=5,width=80)
|
2016-09-13 10:53:46 +02:00
|
|
|
public Integer getDeviceSerial() {
|
|
|
|
return deviceSerial;
|
|
|
|
}
|
|
|
|
public void setDeviceSerial(Integer deviceSerial) {
|
|
|
|
this.deviceSerial = deviceSerial;
|
|
|
|
}
|
|
|
|
|
2016-11-17 16:37:45 +01:00
|
|
|
@TableColumn(label="HW-Index",order=0,width=80)
|
2016-09-15 16:52:11 +02:00
|
|
|
public Integer getIndex() {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
public void setIndex(Integer index) {
|
|
|
|
this.index = index;
|
|
|
|
}
|
|
|
|
|
2016-09-06 16:49:11 +02:00
|
|
|
public void setField0(Integer field0) {
|
|
|
|
this.field0 = field0;
|
|
|
|
}
|
|
|
|
public Integer getField0() {
|
|
|
|
return field0;
|
|
|
|
}
|
|
|
|
public void setTimestamp(Integer timestamp) {
|
|
|
|
this.timestamp = timestamp;
|
|
|
|
}
|
2016-11-17 16:37:45 +01:00
|
|
|
|
2016-09-06 16:49:11 +02:00
|
|
|
public Integer getTimestamp() {
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
public Integer getInputmask() {
|
|
|
|
return inputmask;
|
|
|
|
}
|
|
|
|
public void setInputmask(Integer inputmask) {
|
|
|
|
this.inputmask = inputmask;
|
|
|
|
}
|
|
|
|
public Integer getOutputmask() {
|
|
|
|
return outputmask;
|
|
|
|
}
|
|
|
|
public void setOutputmask(Integer outputmask) {
|
|
|
|
this.outputmask = outputmask;
|
|
|
|
}
|
|
|
|
public Integer getPullupmask() {
|
|
|
|
return pullupmask;
|
|
|
|
}
|
|
|
|
public void setPullupmask(Integer pullupmask) {
|
|
|
|
this.pullupmask = pullupmask;
|
|
|
|
}
|
|
|
|
public Integer getInvertmask() {
|
|
|
|
return invertmask;
|
|
|
|
}
|
|
|
|
public void setInvertmask(Integer invertmask) {
|
|
|
|
this.invertmask = invertmask;
|
|
|
|
}
|
|
|
|
public Integer getTriggermask() {
|
|
|
|
return triggermask;
|
|
|
|
}
|
|
|
|
public void setTriggermask(Integer triggermask) {
|
|
|
|
this.triggermask = triggermask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValue(Integer ch,Integer value){
|
|
|
|
if ((ch >= 0) && (ch<32)){
|
|
|
|
this.values[ch] = value;
|
|
|
|
}
|
|
|
|
}
|
2016-11-21 16:08:15 +01:00
|
|
|
@Plot(label="Zähler %d",instances=32)
|
2016-09-06 16:49:11 +02:00
|
|
|
public Integer getValue(Integer ch){
|
|
|
|
if ((ch >= 0) && (ch<32)){
|
|
|
|
return this.values[ch];
|
|
|
|
}
|
|
|
|
return null;
|
2016-11-17 16:37:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@TableColumn(label="Zähler #%d",order=50,fieldlength=32, width=80)
|
2016-09-06 16:49:11 +02:00
|
|
|
public Integer[] getValues(){
|
|
|
|
return Arrays.copyOf(this.values, this.values.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAnalog(Integer ch,Integer value){
|
|
|
|
if ((ch >= 0) && (ch<8)){
|
|
|
|
this.analog[ch] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public Integer getAnalog(Integer ch){
|
|
|
|
if ((ch >= 0) && (ch<8)){
|
|
|
|
return this.analog[ch];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
public Integer[] getAnalog(){
|
|
|
|
return Arrays.copyOf(this.analog, this.analog.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getHashCode(){
|
|
|
|
return ((long)timestamp << 32) | field0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TriggerType getTriggerType(){
|
|
|
|
return TriggerType.get(this.field0 & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getSource(){
|
|
|
|
return (field0 >> 8) & 0xff;
|
|
|
|
}
|
2016-11-17 16:37:45 +01:00
|
|
|
|
2016-09-06 16:49:11 +02:00
|
|
|
|
2016-11-17 16:37:45 +01:00
|
|
|
@TableColumn(label="Zeitstempel",order=10,width=100)
|
|
|
|
public String getTimeStampFormated(){
|
|
|
|
return df.format(new Date(((long)timestamp)*1000));
|
|
|
|
}
|
2016-09-06 16:49:11 +02:00
|
|
|
|
|
|
|
public byte[] toBytes(){
|
|
|
|
byte[] buffer = new byte[256];
|
|
|
|
ByteBuffer bb = ByteBuffer.wrap(buffer);
|
|
|
|
|
|
|
|
Arrays.fill(buffer, (byte)0);
|
|
|
|
|
|
|
|
bb.putInt(0, timestamp);
|
|
|
|
bb.putInt(4, field0);
|
|
|
|
bb.putInt(8, inputmask);
|
|
|
|
bb.putInt(12, outputmask);
|
|
|
|
bb.putInt(16, pullupmask);
|
|
|
|
bb.putInt(20, invertmask);
|
|
|
|
bb.putInt(24, triggermask);
|
|
|
|
|
|
|
|
for (int i=0;i<32;i++){
|
|
|
|
bb.putInt(32 + (i<<2), values[i]);
|
|
|
|
}
|
|
|
|
for (int i=0;i<8;i++){
|
|
|
|
bb.putInt(160 + (i<<2), analog[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fromBytes(byte[] bytes){
|
|
|
|
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
|
|
|
|
|
|
|
timestamp = bb.getInt(0);
|
|
|
|
field0 = bb.getInt(4);
|
|
|
|
inputmask = bb.getInt(8);
|
|
|
|
outputmask = bb.getInt(12);
|
|
|
|
pullupmask = bb.getInt(16);
|
|
|
|
invertmask = bb.getInt(20);
|
|
|
|
triggermask = bb.getInt(24);
|
|
|
|
|
|
|
|
for (int i=0;i<32;i++){
|
|
|
|
values[i] = bb.getInt(32 + (i<<2));
|
|
|
|
}
|
|
|
|
for (int i=0;i<8;i++){
|
|
|
|
analog[i] = bb.getInt(160 + (i<<2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public CSVRecord getCSVRecord(){
|
|
|
|
return getCSVRecord(false);
|
|
|
|
}
|
|
|
|
public CSVRecord getCSVRecord(Boolean extended){
|
|
|
|
CSVRecord record = new CSVRecord();
|
|
|
|
|
|
|
|
if (extended)
|
|
|
|
record.appendValue(timestamp);
|
|
|
|
|
|
|
|
|
|
|
|
record.appendValue(df.format(new Date(((long)timestamp)*1000)));
|
|
|
|
|
|
|
|
if (extended){
|
2016-10-06 10:57:31 +02:00
|
|
|
record.appendValue(field0 & 0x000000FF);
|
|
|
|
record.appendValue((field0 >> 8) & 0xff);
|
2016-09-06 16:49:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int n=0;n<32;n++)
|
|
|
|
record.appendValue( values[n]);
|
|
|
|
for (int n=0;n<8;n++)
|
|
|
|
record.appendValue( analog[n]);
|
|
|
|
|
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2016-09-13 12:07:01 +02:00
|
|
|
return String.format("SnapShot [ Device: %d Timestamp: %d ]",this.deviceSerial,this.timestamp);
|
2016-09-06 16:49:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|