Commit fd822bf9 authored by Vincent van Beveren's avatar Vincent van Beveren

completed password feature

parent d45faa9c
......@@ -81,6 +81,7 @@ public class DDMILoader {
private static class DDMIConstMetaProxy extends XOLProxyBase<Void> {
private DDMIValue _value;
@Override
public boolean setAttribute(String name, String obj) {
......@@ -89,11 +90,12 @@ public class DDMILoader {
@Override
public void setParent(XOLProxy<?> obj) {
//_value = DDMIValue.class.cast(obj.getInstance());
_value = DDMIValue.class.cast(obj.getInstance());
}
@Override
public boolean setContent(String data) {
_value.setMeta(DDMIMeta.CONST, data);
return true;
}
......@@ -216,8 +218,8 @@ public class DDMILoader {
public DDMIValueFactory(DDMIValue.DDMIType typ)
{
_typ = typ;
}
}
@Override
public XOLProxy<? extends DDMIValue> newProxy() {
......@@ -423,7 +425,7 @@ public class DDMILoader {
_xol.setMapping("int", new DDMIValueFactory(DDMIValue.DDMIType.INT_TYPE));
_xol.setMapping("uint", new DDMIValueFactory(DDMIValue.DDMIType.UINT_TYPE));
_xol.setMapping("bitmap", new DDMIValueFactory(DDMIValue.DDMIType.BITMAP_TYPE));
_xol.setMapping("password", new DDMIValueFactory(DDMIValue.DDMIType.BITMAP_TYPE));
_xol.setMapping("password", new DDMIValueFactory(DDMIValue.DDMIType.PASSWORD_TYPE));
_xol.setMapping("text", new DDMIValueFactory(DDMIValue.DDMIType.TEXT_TYPE));
_xol.setMapping("float", new DDMIValueFactory(DDMIValue.DDMIType.DECIMAL_TYPE_FLOAT));
_xol.setMapping("sfix", new DDMIValueFactory(DDMIValue.DDMIType.DECIMAL_TYPE_SFIXED));
......
......@@ -17,8 +17,10 @@
******************************************************************************/
package nl.nikhef.sfp.ddmi;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import nl.nikhef.sfp.ddmi.DDMIMeta.BitFieldValue;
import nl.nikhef.tools.Utils;
......@@ -38,11 +40,16 @@ public class DDMIValue extends DDMIElement {
BITMAP_TYPE,
/** Integer type, max 4 bytes, always signed */
INT_TYPE,
/** Integer type, max 4 bytes, always unsigned */
UINT_TYPE,
/** Decimal type, interpretation depends on formatting */
/** Unsigned fixed point */
DECIMAL_TYPE_UFIXED,
/** Signed fixed point */
DECIMAL_TYPE_SFIXED,
/** 32 bit floating point */
DECIMAL_TYPE_FLOAT,
/** Same as bitmap, but usually not visible */
PASSWORD_TYPE
}
private int _offset;
......@@ -162,21 +169,56 @@ public class DDMIValue extends DDMIElement {
private void lockUnlockField(DDMIContext ctx, boolean unlock) {
if (getPasswordId() == null) return; // there is no password
DDMIValue el = DDMIValue.class.cast(ctx.getDDMI().getElementById(getPasswordId()));
if (el == null) throw new RuntimeException("Password field with ID " + getPasswordId() + " not found");
if (!DDMIMeta.CONST.partOf(el)) throw new RuntimeException("For now passowords must always have a constant");
String s = DDMIMeta.CONST.of(el);
byte[] password = Utils.hexStringToBytes(s);
if (!unlock) Arrays.fill(password, (byte)0xFF);
el.writeRaw(ctx, password);
}
public byte[] readRaw(DDMIContext ctx) {
lockUnlockField(ctx, true);
DataSource acc = ctx.getDDMI().getSourceById(getSourceId());
if (acc != null) {
return acc.read(ctx, _offset, _length);
try {
DataSource acc = ctx.getDDMI().getSourceById(getSourceId());
if (acc != null) {
return acc.read(ctx, _offset, _length);
}
throw new RuntimeException("Datasource with ID " + getSourceId() + " not found");
} finally {
lockUnlockField(ctx, false);
}
return new byte[_length];
// return new byte[_length];
}
public void writeRaw(DDMIContext ctx, byte[] dta) {
if (!_writable) throw new AccessException("Field is not wriable");
if (!_writable) throw new AccessException("Field is not writable");
assert(dta.length == _length);
DataSource acc = ctx.getDDMI().getSourceById(getSourceId());
acc.write(ctx, _offset, dta);
lockUnlockField(ctx, true);
try {
DataSource acc = ctx.getDDMI().getSourceById(getSourceId());
acc.write(ctx, _offset, dta);
} finally {
lockUnlockField(ctx, false);
}
}
......
......@@ -57,6 +57,7 @@ public abstract class DataSource {
public void update(DDMIContext ctx)
{
byte[] area = readMedia(ctx, start, ( end - start ) + 1);
if (area == null) return;
write(ctx, offset, new byte[] { SFPUtils.checkSum(area, 0, ( end - start ) + 1) } );
}
......
......@@ -37,6 +37,7 @@
<source page="1" parent-id="diag" id="diag_p1" start="128" end="255" />
<source page="2" parent-id="diag" id="diag_p2" start="128" end="255" />
<source page="3" parent-id="diag" id="diag_p3" start="128" end="255" />
<source page="4" parent-id="diag" id="diag_p4" start="128" end="255" />
<group source-id="eeprom">
<group label="Base ID fields" source-id="eeprom" name="base_id">
......@@ -210,38 +211,52 @@
<group label="A/W Thresholds" name="aw_thresholds">
<group label="Temperature" name="temperature">
<int label="Temperature Low alert" short="Low alert" offset="0" length="2" writable="true" name="low_alert"/>
<int label="Temperature High alert" short="High alert" offset="2" length="2" writable="true" name="high_alert"/>
<int label="Temperature Low warning" short="Low warning" offset="4" length="2" writable="true" name="low_warning"/>
<int label="Temperature High warning" short="High warning" offset="6" length="2" writable="true" name="high_warning"/>
<int label="Temperature High alarm" short="High alarm" offset="0" length="2" writable="true" name="high_alarm"/>
<int label="Temperature Low alarm" short="Low alarm" offset="2" length="2" writable="true" name="low_alarm"/>
<int label="Temperature High warning" short="High warning" offset="4" length="2" writable="true" name="high_warn"/>
<int label="Temperature Low warning" short="Low warning" offset="6" length="2" writable="true" name="low_warn"/>
</group>
<group label="Voltage" name="voltage">
<int label="Voltage Low alert" short="Low alert" offset="8" length="2" writable="true" name="low_alert"/>
<int label="Voltage High alert" short="High alert" offset="10" length="2" writable="true" name="high_alert"/>
<int label="Voltage Low warning" short="Low warning" offset="12" length="2" writable="true" name="low_warning"/>
<int label="Voltage High warning" short="High warning" offset="14" length="2" writable="true" name="high_warning"/>
<uint label="Voltage High alarm" short="High alarm" offset="8" length="2" writable="true" name="high_alarm"/>
<uint label="Voltage Low alarm" short="Low alarm" offset="10" length="2" writable="true" name="low_alarm"/>
<uint label="Voltage High warning" short="High warning" offset="12" length="2" writable="true" name="high_warn"/>
<uint label="Voltage Low warning" short="Low warning" offset="14" length="2" writable="true" name="low_warn"/>
</group>
<group label="Bias" name="bias">
<int label="Bias Low alert" short="Low alert" offset="16" length="2" writable="true" name="low_alert"/>
<int label="Bias High alert" short="High alert" offset="18" length="2" writable="true" name="high_alert"/>
<int label="Bias Low warning" short="Low warning" offset="20" length="2" writable="true" name="low_warning"/>
<int label="Bias High warning" short="High warning" offset="22" length="2" writable="true" name="high_warning"/>
<uint label="Bias High alarm" short="High alarm" offset="16" length="2" writable="true" name="high_alarm"/>
<uint label="Bias Low alarm" short="Low alarm" offset="18" length="2" writable="true" name="low_alarm"/>
<uint label="Bias High warning" short="High warning" offset="20" length="2" writable="true" name="high_warn"/>
<uint label="Bias Low warning" short="Low warning" offset="22" length="2" writable="true" name="low_warn"/>
</group>
<group label="TX Power" name="tx_power">
<int label="TX Power Low alert" short="Low alert" offset="24" length="2" writable="true" name="low_alert"/>
<int label="TX Power High alert" short="High alert" offset="26" length="2" writable="true" name="high_alert"/>
<int label="TX Power Low warning" short="Low warning" offset="28" length="2" writable="true" name="low_warning"/>
<int label="TX Power High warning" short="High warning" offset="30" length="2" writable="true" name="high_warning"/>
<uint label="TX Power High alarm" short="High alarm" offset="24" length="2" writable="true" name="high_alarm"/>
<uint label="TX Power Low alarm" short="Low alarm" offset="26" length="2" writable="true" name="low_alarm"/>
<uint label="TX Power High warning" short="High warning" offset="28" length="2" writable="true" name="high_warn"/>
<uint label="TX Power Low warning" short="Low warning" offset="30" length="2" writable="true" name="low_warn"/>
</group>
<group label="RX Power" name="rx_powesr">
<int label="RX Power Low alert" short="Low alert" offset="32" length="2" writable="true" name="low_alert"/>
<int label="RX Power High alert" short="High alert" offset="34" length="2" writable="true" name="high_alert"/>
<int label="RX Power Low warning" short="Low warning" offset="36" length="2" writable="true" name="low_warning"/>
<int label="RX Power High warning" short="High warning" offset="38" length="2" writable="true" name="high_warning"/>
<group label="RX Power" name="rx_power">
<uint label="RX Power High alarm" short="High alarm" offset="32" length="2" writable="true" name="high_alarm"/>
<uint label="RX Power Low alarm" short="Low alarm" offset="34" length="2" writable="true" name="low_alarm"/>
<uint label="RX Power High warning" short="High warning" offset="36" length="2" writable="true" name="high_warn"/>
<uint label="RX Power Low warning" short="Low warning" offset="38" length="2" writable="true" name="low_warn"/>
</group>
<group label="Laser Temp" name="laser_temp">
<uint label="Laser Temp High alarm" short="High alarm" offset="40" length="2" writable="true" name="high_alarm"/>
<uint label="Laser Temp Low alarm" short="Low alarm" offset="42" length="2" writable="true" name="low_alarm"/>
<uint label="Laser Temp High warning" short="High warning" offset="44" length="2" writable="true" name="high_warn"/>
<uint label="Laser Temp Low warning" short="Low warning" offset="46" length="2" writable="true" name="low_warn"/>
</group>
<group label="TEC Current" name="tec_current">
<uint label="TEC Current High alarm" short="High alarm" offset="48" length="2" writable="true" name="high_alarm"/>
<uint label="TEC Current Low alarm" short="Low alarm" offset="50" length="2" writable="true" name="low_alarm"/>
<uint label="TEC Current High warning" short="High warning" offset="52" length="2" writable="true" name="high_warn"/>
<uint label="TEC Current Low warning" short="Low warning" offset="54" length="2" writable="true" name="low_warn"/>
</group>
</group>
<group label="Calibration Constants">
<float label="RX Power 4"
......
......@@ -28,8 +28,9 @@
<group source-id="diag" showIf="isset(id.montype, 6)">
<!-- implicit hard-coded password -->
<password id="oe-password" offset="x7b" length="4">
<const>4F 45 53 50</const>
<password id="oe-password" offset="x7b" length="4" writable="true">
<!-- for now constants must be binary hex strings. Sorry. -->
<const>4F455350</const>
</password>
</group>
<group source-id="diag_p4" showIf="isset(id.montype, 6)">
......
......@@ -30,6 +30,7 @@ import nl.nikhef.sfp.ddmi.DDMIElement;
import nl.nikhef.sfp.ddmi.DDMIGroup;
import nl.nikhef.sfp.ddmi.DDMIMeta;
import nl.nikhef.sfp.ddmi.DDMIValue;
import nl.nikhef.sfp.ddmi.DDMIValue.DDMIType;
@SuppressWarnings("serial")
public class FormEditPane extends JPanel {
......@@ -64,6 +65,8 @@ public class FormEditPane extends JPanel {
addGroup(ctx, DDMIGroup.class.cast(el), level);
}
} else if (el instanceof DDMIValue){
if (DDMIValue.class.cast(el).getType() == DDMIType.PASSWORD_TYPE) continue;
addField(ctx, DDMIValue.class.cast(el), level);
}
......@@ -94,6 +97,7 @@ public class FormEditPane extends JPanel {
switch (val.getType())
{
case INT_TYPE:
case UINT_TYPE:
if (DDMIMeta.LOOKUP.partOf(val)) {
comp = new EnumEditor(ctx, val, label);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment