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

Started work on Clone tool

parent 079364c3
nl.nikhef.sfp.MultiSFPProvider
nl.nikhef.sfp.SimSFPProvider
nl.nikhef.sfp.VirtualSFPProvider
package nl.nikhef.sfp;
import java.io.IOException;
import nl.nikhef.sfp.i2c.I2CLink;
import nl.nikhef.sfp.i2c.SimI2CLink;
import nl.nikhef.sfp.i2c.VirtualI2CLink;
public class VirtualSFPDevice extends SFPDeviceBase {
private final String _serial;
private final int _bays;
private I2CLink[] _links;
public VirtualSFPDevice(String serial, int bays) {
_serial = serial;
_bays = bays;
_links = new I2CLink[_bays];
}
@Override
public String getSerial() {
return _serial;
}
@Override
public int getBayCount() {
return _bays;
}
@Override
public I2CLink getLink(int bay) throws IOException {
if (!isModulePresent(bay)) return null;
return _links[bay];
}
@Override
public boolean isModulePresent(int bay) {
if (bay < 0 || bay > getBayCount()) return false;
return _links[bay] != null;
}
@Override
public void shutdown() {
}
@Override
public void updateModules()
{
if (_links[0] != null) return;
for (int bay = 0; bay < _links.length; bay++)
{
_links[bay] = new VirtualI2CLink(String.format("Virtual_%d", bay));
sdlMgr.getProxy().sfpModuleStateChanged(this, bay);
}
}
}
package nl.nikhef.sfp;
public class VirtualSFPProvider extends SFPProviderBase {
private boolean _firstRun = true;
private VirtualSFPDevice _device = new VirtualSFPDevice("Virtual", 4);
public void scanForNewDevices()
{
if (!_firstRun) return;
addDevice(_device);
_firstRun = false;
}
@Override
public void updateDevices() {
super.updateDevices();
}
@Override
public String getName() {
return "VirtualSFPProvider";
}
}
package nl.nikhef.sfp;
public class VirtualSFPProviderFactory implements SFPProviderFactory {
public SFPProvider[] getProviders() {
return new SFPProvider[] { new SimSFPProvider() };
}
}
package nl.nikhef.sfp.i2c;
import java.io.IOException;
import nl.nikhef.sfp.ddmi.SFPUtils;
public class VirtualI2CLink implements I2CLink {
private int _eepromPtr = 0;
private int _diagPtr = 0;
private byte[] _eeprom = new byte[] {
0x03, 0x04,
0x00, // Connector values, SFF-8024
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, // Encoding, SFF-8024
0x64, // 10 GB
0x0E, // Rate ID
0x0D, 0x00, 0x00, 0x00, 0x00, 0x64, // Lengths
(byte)'N',(byte)'I',(byte)'K',(byte)'H', // Vendor name
(byte)'E',(byte)'F',(byte)' ',(byte)' ',
(byte)' ',(byte)' ',(byte)' ',(byte)' ',
(byte)' ',(byte)' ',(byte)' ',(byte)' ',
0x00, // Transciever (B)
0x00, 0x00, 0x00, // Vendor OUD
(byte)'0',(byte)'1',(byte)'2',(byte)'3', // Vendor part number
(byte)'4',(byte)'5',(byte)'S',(byte)'F',
(byte)'P',(byte)' ',(byte)' ',(byte)' ',
(byte)' ',(byte)' ',(byte)' ',(byte)' ',
(byte)'1',(byte)'.',(byte)'0',(byte)'1', // Revision
0x00, 0x00, // Wavelength
0x00, // reserved\
0x00, // CHECKSUM
0x00, 0x00, // Optional transceiver values
0x00, 0x00, // BR-max, BR-min
(byte)'0',(byte)'0',(byte)'1',(byte)'1', // Vendor serial number
(byte)'2',(byte)'2',(byte)'3',(byte)'3',
(byte)'A',(byte)'B',(byte)'C',(byte)'D',
(byte)'B',(byte)'A',(byte)'D',(byte)'D',
(byte)'1',(byte)'6',(byte)'0',(byte)'1', // Vendor date code
(byte)'1',(byte)'4',(byte)'0',(byte)'0',
0x40, // Diagnostic monitoring type
0x00, // Enhanced options
0x08, // SFF-8472 compliance
0x00, // CHECKSUM // 96
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 112
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 128
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 144
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 160
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 176
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 192
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 208
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 224
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 240
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // 256
};
private byte[] _diag = new byte[] {
// Thresholds
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Temperature
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Voltage
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Bias
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TX Power
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // RX Power
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Laser temp
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TEC current
// RX Power poly (32 bit fp)
0x00, 0x00, 0x00, 0x00, // arg 0
0x00, 0x00, 0x00, 0x00, // arg 1
0x00, 0x00, 0x00, 0x00, // arg 2
0x00, 0x00, 0x00, 0x00, // arg 3
0x00, 0x00, 0x00, 0x00, // arg 4
0x00, 0x00, 0x00, 0x00, // TX bias current line, slope & offset
0x00, 0x00, 0x00, 0x00, // TX power line, slope & offset
0x00, 0x00, 0x00, 0x00, // Temperature line, slope & offset
0x00, 0x00, 0x00, 0x00, // Voltage line, slope & offset
0x00, 0x00, 0x00, 0x00, // 3x reserved, 1x checksum
// ADC values
0x00, 0x00, // Temperature ADC value
0x00, 0x00, // Vcc ADC value
0x00, 0x00, // TX Bias ADC value
0x00, 0x00, // TX Power ADC value
0x00, 0x00, // RX Power ADC value
0x00, 0x00, // Laser temp/wavelength ADC value
0x00, 0x00, // TEC current
0x00, 0x00, // Optional status /control
// Misc.
0x00, 0x00, // Reserved warning/alarm flags
0x00, 0x00, // Input equalization, output emphasis
0x00, 0x00, // more warning/alarm flags
0x00, 0x00, // extended module control/status
// Vendor specific
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
// page select
0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 128
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 144
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 160
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 176
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 192
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 208
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 224
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 240
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // 256
};
public VirtualI2CLink(String serial) {
byte[] serialBytes = serial.getBytes();
for (int i = 0; i < 16; i++) {
_eeprom[i + 68] = i < serialBytes.length ? serialBytes[i] : 0x20;
}
_eeprom[63] = SFPUtils.checkSum(_eeprom, 0, 63);
_eeprom[95] = SFPUtils.checkSum(_eeprom, 64, 31);
_diag[95] = SFPUtils.checkSum(_diag, 0, 95);
}
@Override
public void open() throws IOException {
}
@Override
public void close() throws IOException {
}
@Override
public void i2cWrite(int addr, byte[] data) throws IOException
{
if (addr != 0x50 && addr != 0x51) throw new IOException("I2C No Ack");
/*
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
*/
if (addr == 0x50) {
_eepromPtr = 0xFF & data[0];
for (int i = 1; i < data.length; i++)
{
_eeprom[_eepromPtr++] = data[i];
}
}
if (addr == 0x51)
{
_diagPtr = 0xFF & data[0];
for (int i = 1; i < data.length; i++)
{
_diag[_diagPtr++] = data[i];
}
}
}
@Override
public byte[] i2cRead(int addr, int len) throws IOException {
if (addr != 0x50 && addr != 0x51) throw new IOException("I2C No Ack");
/*
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
*/
byte[] d = new byte[len];
for (int i = 0; i < len; i++)
{
if (addr == 0x50) d[i] = _eeprom[_eepromPtr++];
if (addr == 0x51) d[i] = _diag[_diagPtr++];
}
return d;
}
@Override
public byte[] i2cWrRd(int addr, byte[] dataWr, boolean contRd, int rdLen)
throws IOException {
i2cWrite(addr, dataWr);
return i2cRead(addr, rdLen);
}
@Override
public void shutdown() throws IOException {
}
}
......@@ -41,6 +41,7 @@ import org.codejargon.feather.Provides;
import nl.nikhef.safaripark.devmgr.BaySelectionListener;
import nl.nikhef.safaripark.devmgr.DeviceManager;
import nl.nikhef.safaripark.dolly.DollyPanel;
import nl.nikhef.safaripark.editpane.EditPane;
import nl.nikhef.safaripark.extra.GuiUtils;
import nl.nikhef.safaripark.monitor.Monitor;
......@@ -69,6 +70,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
private ContextCache _ctxCache;
private OverlayManager _ovlMgr;
private ModuleManager _modMgr;
private DollyPanel _dp;
private Properties buildProps;
private Action _selectOverlays = new ExtendedAbstractAction("Select overlays", Resources.getIcon("books"), "Select which SFP+ overlays to load") {
......@@ -124,9 +126,15 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
_status = new StatusBar();
_modMgr = new ModuleManager(_saveBinary, _loader, _ctxCache);
_devMgr.addDeviceSelectedListener(_modMgr);
_dp = new DollyPanel(_loader);
makeToolbar();
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
split.setLeftComponent(_devMgr);
JSplitPane split3 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
split3.setTopComponent(_devMgr);
split3.setBottomComponent(_dp);
split.setLeftComponent(split3);
JSplitPane split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
split.setRightComponent(split2);
split2.setTopComponent(_tabEdit);
......
package nl.nikhef.safaripark.dolly;
import nl.nikhef.safaripark.devmgr.BaySelectionListener;
import nl.nikhef.sfp.SFPDevice;
import nl.nikhef.sfp.SFPDeviceListener;
public class DollyModel implements SFPDeviceListener, BaySelectionListener {
public DollyModel()
{
}
@Override
public void sfpModuleStateChanged(SFPDevice dev, int bay)
{
if (dev.isModulePresent(bay))
{
} else {
}
}
@Override
public void baySelected(SFPDevice dev, int bay) {
}
@Override
public boolean canSelectBay(SFPDevice dev, int bay) {
return true;
}
}
package nl.nikhef.safaripark.dolly;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import nl.nikhef.safaripark.Title;
import nl.nikhef.safaripark.vsp.ValueSelectionPane;
import nl.nikhef.sfp.ddmi.DDMIElement;
import nl.nikhef.sfp.ddmi.DDMILoader;
import nl.nikhef.sfp.ddmi.DDMIValue;
import nl.nikhef.tools.Filter;
public class DollyPanel extends JPanel {
private ValueSelectionPane _vsp;
public DollyPanel(DDMILoader loader) {
setLayout(new BorderLayout());
add(new Title("Clone Tool"), BorderLayout.NORTH);
_vsp = new ValueSelectionPane(loader);
JPanel core = new JPanel();
core.add(_vsp, BorderLayout.CENTER);
_vsp.init(new Filter<DDMIElement>() {
@Override
public boolean match(DDMIElement other) {
if (!(other instanceof DDMIValue)) {
return false;
}
DDMIValue v = DDMIValue.class.cast(other);
return v.isWritable();
}
@Override
public Class<DDMIElement> getFilterClass() {
return DDMIElement.class;
}
}, "dolly");
add(core, BorderLayout.CENTER);
}
}
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