00001
00002
00003
00004
00005
00006
00007 package SctData;
00008
00009 import sctConf.*;
00010
00015 public class ChipOptions implements Sct.Streamable {
00016
00018 public ChipOptions(ABCDConfig data) {
00019 this.data = data;
00020 }
00021
00022 public String getClassName() {
00023 return "SctData.ChipOptions";
00024 }
00025
00026 public ABCDConfig getData() {
00027 return data;
00028 }
00029
00030 public byte getReadOutMode() {
00031 return getDoubleBit(0);
00032 }
00033
00034 public void setReadOutMode(byte readOut) {
00035 if (readOut > 3) throw new IllegalArgumentException("Readout mode must be below 4. Given: " + readOut);
00036 setDoubleBit(readOut, 0);
00037 }
00038
00039 public byte getCalibMode() {
00040 return getDoubleBit(2);
00041 }
00042
00043 public void setCalibMode(byte calib) {
00044 if (calib > 3) throw new IllegalArgumentException("Cali mode must be below 4. Given: " + calib);
00045 setDoubleBit(calib, 2);
00046 }
00047
00048 public byte getTrimRange() {
00049 return getDoubleBit(4);
00050 }
00051
00052 public void setTrimRange(byte trimRange) {
00053 if (trimRange > 3) throw new IllegalArgumentException("Trim Range must be below 4. Given: " + trimRange);
00054 setDoubleBit(trimRange, 4);
00055 }
00056
00057
00058 public boolean getEdgeDetect() {
00059 return getBit(6);
00060 }
00061
00062 public void setEdgeDetect(boolean edge) {
00063 setBit(edge, 6);
00064 }
00065
00066 public boolean getMaskFlag() {
00067 return getBit(7);
00068 }
00069
00070 public void setMaskFlag(boolean mask) {
00071 setBit(mask, 7);
00072 }
00073
00074 public boolean getAccumulate() {
00075 return getBit(8);
00076 }
00077
00078 public void setAccumulate(boolean mask) {
00079 setBit(mask, 8);
00080 }
00081
00082 public boolean getInputBypass() {
00083 return getBit(9);
00084 }
00085
00086 public void setInputBypass(boolean mask) {
00087 setBit(mask, 9);
00088 }
00089
00090 public boolean getOutputBypass() {
00091 return getBit(10);
00092 }
00093
00094 public void setOutputBypass(boolean mask) {
00095 setBit(mask, 10);
00096 }
00097
00098 public boolean getMaster() {
00099 return getBit(11);
00100 }
00101
00102 public void setMaster(boolean mask) {
00103 setBit(mask, 11);
00104 }
00105
00106 public boolean getEnd() {
00107 return getBit(12);
00108 }
00109
00110 public void setEnd(boolean mask) {
00111 setBit(mask, 12);
00112 }
00113
00114 public boolean getFeedThrough() {
00115 return getBit(13);
00116 }
00117
00118 public void setFeedThrough(boolean mask) {
00119 setBit(mask, 13);
00120 }
00121
00122
00123 public static Sct.Streamable read(Sct.IStream s, Sct.ObjectManager o) throws java.io.IOException {
00124 ChipOptions co = new ChipOptions(new ABCDConfig());
00125 co.readObject(s, o);
00126 return co;
00127 }
00128
00129 public void readObject(Sct.IStream s, Sct.ObjectManager o) throws java.io.IOException {
00130 setReadOutMode((byte)s.readShort("ReadoutMode"));
00131 setCalibMode((byte)s.readShort("CalibMode"));
00132 setTrimRange((byte)s.readShort("TrimRange"));
00133
00134 setEdgeDetect(s.readShort("EdgeDetect") == 0 ? false : true);
00135 setMaskFlag (s.readShort("SendMask") == 0 ? false : true);
00136 setAccumulate(s.readShort("Accumulate") == 0 ? false : true);
00137 setInputBypass(s.readShort("InputBypass") == 0 ? false : true);
00138 setOutputBypass(s.readShort("OutputBypass") == 0 ? false : true);
00139 setMaster(s.readShort("Master") == 0 ? false : true);
00140 setEnd(s.readShort("End") == 0 ? false : true);
00141 setFeedThrough(s.readShort("FeedThrough") == 0 ? false : true);
00142 }
00143
00144 public void write(Sct.OStream s, Sct.ObjectManager o) throws java.io.IOException {
00145 s.writeShort("ReadoutMode", getReadOutMode(), false);
00146 s.writeShort("CalibMode", getCalibMode(), false);
00147 s.writeShort("TrimRange", getTrimRange(), false);
00148
00149 s.writeShort("EdgeDetect", getEdgeDetect()?(short)1 :(short)0, false);
00150 s.writeShort("SendMask", getMaskFlag()?(short)1 :(short)0, false);
00151 s.writeShort("Accumulate", getAccumulate()?(short)1 :(short)0, false);
00152 s.writeShort("InputBypass", getInputBypass()?(short)1 :(short)0, false);
00153 s.writeShort("OutputBypass", getOutputBypass()?(short)1 :(short)0, false);
00154 s.writeShort("Master", getMaster()?(short)1 :(short)0, false);
00155 s.writeShort("End", getEnd()?(short)1 :(short)0, false);
00156 s.writeShort("FeedThrough", getFeedThrough()?(short)1 :(short)0, false);
00157 }
00158
00159 private void setDoubleBit(byte set, int startBit) {
00160 data.bitField = (short)((data.bitField & ~(3<<startBit)) | (set << startBit));
00161 }
00162
00163 private byte getDoubleBit(int startBit) {
00164 return (byte)((data.bitField >> startBit) & 3);
00165 }
00166
00167 private void setBit(boolean set, int bit) {
00168 if (set)
00169 data.bitField |= 1<<bit;
00170 else
00171 data.bitField &= ~(1<<bit);
00172 }
00173
00174 private boolean getBit(int bit) {
00175 return ((data.bitField & (1<<bit)) == (1<<bit));
00176 }
00177
00178 private ABCDConfig data;
00179 }