212 lines
4.3 KiB
Java
212 lines
4.3 KiB
Java
|
package org.hwo.pulscounter;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.nio.ByteBuffer;
|
||
|
import java.text.SimpleDateFormat;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.Date;
|
||
|
|
||
|
import org.hwo.csv.CSVRecord;
|
||
|
import org.hwo.servicelink.ServiceLink;
|
||
|
import org.hwo.servicelink.ServiceLinkException;
|
||
|
|
||
|
public class SnapShot {
|
||
|
Integer timestamp;
|
||
|
Integer field0;
|
||
|
|
||
|
Integer[] values;
|
||
|
Integer[] analog;
|
||
|
|
||
|
Integer inputmask,
|
||
|
outputmask,
|
||
|
pullupmask,
|
||
|
invertmask,
|
||
|
triggermask;
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
public void setField0(Integer field0) {
|
||
|
this.field0 = field0;
|
||
|
}
|
||
|
public Integer getField0() {
|
||
|
return field0;
|
||
|
}
|
||
|
public void setTimestamp(Integer timestamp) {
|
||
|
this.timestamp = timestamp;
|
||
|
}
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
public Integer getValue(Integer ch){
|
||
|
if ((ch >= 0) && (ch<32)){
|
||
|
return this.values[ch];
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
|
||
|
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);
|
||
|
|
||
|
SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
|
||
|
|
||
|
record.appendValue(df.format(new Date(((long)timestamp)*1000)));
|
||
|
|
||
|
if (extended){
|
||
|
record.appendValue("TRIGGER");
|
||
|
record.appendValue("QUELLE");
|
||
|
}
|
||
|
|
||
|
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() {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
|
||
|
sb.append("SnapShot(");
|
||
|
sb.append(this.timestamp);
|
||
|
sb.append(":");
|
||
|
for (int i=0;i<32;i++){
|
||
|
if (i>0)
|
||
|
sb.append(",");
|
||
|
sb.append(this.values[i]);
|
||
|
}
|
||
|
|
||
|
sb.append(")");
|
||
|
|
||
|
return sb.toString();
|
||
|
}
|
||
|
|
||
|
}
|