Commit 10f1f014 authored by Andrey Filippov's avatar Andrey Filippov

made focusing work for both 5Mpix and 14Mpix, provided config files in resources

parent b04837e7
...@@ -1691,7 +1691,7 @@ public class MatchSimulatedPattern { ...@@ -1691,7 +1691,7 @@ public class MatchSimulatedPattern {
floatPixels = (float[]) fht1.getPixels(); floatPixels = (float[]) fht1.getPixels();
for (i = 0; i < floatPixels.length; i++) for (i = 0; i < floatPixels.length; i++)
pixels[i] = floatPixels[i]; pixels[i] = floatPixels[i];
// show pixels here?
int[][] max2OnSpectrum = findFirst2MaxOnSpectrum(fft_complex, // complex, top half, starting from 0,0 int[][] max2OnSpectrum = findFirst2MaxOnSpectrum(fft_complex, // complex, top half, starting from 0,0
1, // skip +- from (0,0) and previous max - add parameter to dialog? 1, // skip +- from (0,0) and previous max - add parameter to dialog?
0.5); // 0.5 - 30deg. orthogonality of 2 vectors - 1.0 - perpendicular, 0.0 - parallel 0.5); // 0.5 - 30deg. orthogonality of 2 vectors - 1.0 - perpendicular, 0.0 - parallel
......
package com.elphel.imagej.calibration.hardware; package com.elphel.imagej.calibration.hardware;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
...@@ -15,8 +16,10 @@ import javax.xml.parsers.DocumentBuilder; ...@@ -15,8 +16,10 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
//import org.xml.sax.SAXParseException;
import com.elphel.imagej.calibration.MatchSimulatedPattern; import com.elphel.imagej.calibration.MatchSimulatedPattern;
import com.elphel.imagej.calibration.UVLEDandLasers; import com.elphel.imagej.calibration.UVLEDandLasers;
...@@ -98,6 +101,7 @@ public class CamerasInterface{ ...@@ -98,6 +101,7 @@ public class CamerasInterface{
public boolean reportTiming=false; public boolean reportTiming=false;
public int cameraBootTimeSeconds=100; public int cameraBootTimeSeconds=100;
public int connectionTimeoutMilliseconds=3000; public int connectionTimeoutMilliseconds=3000;
public boolean is_10398 = false;
private void printTiming(String title){ private void printTiming(String title){
if (this.reportTiming) { if (this.reportTiming) {
...@@ -169,6 +173,10 @@ public class CamerasInterface{ ...@@ -169,6 +173,10 @@ public class CamerasInterface{
return ((channelNumber>=0)&& (channelNumber<this.channelMap.length))?this.channelMap[channelNumber][2]:-1; return ((channelNumber>=0)&& (channelNumber<this.channelMap.length))?this.channelMap[channelNumber][2]:-1;
} }
public boolean is14Mpix() {
return this.is_10398;
}
// not used anywhere // not used anywhere
public int getChannel (int subCam, int subChn){ public int getChannel (int subCam, int subChn){
return getChannel (subCam, subChn, 0); // for compatibility with 353 return getChannel (subCam, subChn, 0); // for compatibility with 353
...@@ -621,18 +629,47 @@ public class CamerasInterface{ ...@@ -621,18 +629,47 @@ public class CamerasInterface{
} }
} }
public String getSerialNumber(int chn, int EEPROM_chn){ public String getSerialNumber(int chn, int EEPROM_chn){
String [] ser_mod = getSerialNumberModel(chn, EEPROM_chn);
if ((ser_mod==null) || (ser_mod.length < 1)) return null;
return ser_mod[0];
}
public String getModelNumber(int chn, int EEPROM_chn){
String [] ser_mod = getSerialNumberModel(chn, EEPROM_chn);
if ((ser_mod==null) || (ser_mod.length < 2)) return null;
return ser_mod[1];
}
public String [] getSerialNumberModel(int chn, int EEPROM_chn){
int colon_index = this.cameraIPs[chn].indexOf(":"); int colon_index = this.cameraIPs[chn].indexOf(":");
int sensor_port = Integer.parseInt(this.cameraIPs[chn].substring(colon_index+1)) - this.imgsrvPort; int sensor_port = Integer.parseInt(this.cameraIPs[chn].substring(colon_index+1)) - this.imgsrvPort;
String ip=this.cameraIPs[chn].substring(0, colon_index); String ip=this.cameraIPs[chn].substring(0, colon_index);
// String url="http://"+this.cameraIPs[chn]+"/i2c.php?cmd=fromEEPROM0&EEPROM_chn="+EEPROM_chn; // String url="http://"+this.cameraIPs[chn]+"/i2c.php?cmd=fromEEPROM0&EEPROM_chn="+EEPROM_chn;
// ip = "192.168.0.236";
String url="http://"+ip+"/i2c.php?cmd=fromEEPROM" + sensor_port+ "&EEPROM_chn="+EEPROM_chn; String url="http://"+ip+"/i2c.php?cmd=fromEEPROM" + sensor_port+ "&EEPROM_chn="+EEPROM_chn;
Document dom=null; Document dom=null;
String serial=null; String serial=null;
String model=null;
try { try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder(); DocumentBuilder db = dbf.newDocumentBuilder();
InputStream in = new URL( url ).openStream();
byte[] bytes = new byte[0];
try {
bytes = IOUtils.toByteArray(in);
} finally {
IOUtils.closeQuietly(in); // always gets here
}
for (byte b:bytes) {
if (b < 0) {
String msg="Sensor EEPROM is not initialized. Use bootblock393 to initialize it. Will throw now";
IJ.showMessage("Error",msg);
System.out.println(msg);
throw new IllegalArgumentException ("SAX error");
// return null;
}
}
dom = db.parse(url); dom = db.parse(url);
if (!dom.getDocumentElement().getNodeName().equals("board")) { if (!dom.getDocumentElement().getNodeName().equals("board")) {
String msg="Root element: expected 'board', got \"" + dom.getDocumentElement().getNodeName()+"\""; String msg="Root element: expected 'board', got \"" + dom.getDocumentElement().getNodeName()+"\"";
...@@ -651,6 +688,13 @@ public class CamerasInterface{ ...@@ -651,6 +688,13 @@ public class CamerasInterface{
if (serial.startsWith("\"")){ if (serial.startsWith("\"")){
serial=serial.substring(1, serial.length()-1); serial=serial.substring(1, serial.length()-1);
} }
model=(dom.getDocumentElement().getElementsByTagName("model").item(0).getChildNodes().item(0)).getNodeValue();
if (model !=null){
if (model.startsWith("\"")){
model=model.substring(1, model.length()-1);
}
}
} catch(MalformedURLException e){ } catch(MalformedURLException e){
String msg="Please check the URL:" + e.toString(); String msg="Please check the URL:" + e.toString();
IJ.showMessage("Error",msg); IJ.showMessage("Error",msg);
...@@ -666,8 +710,11 @@ public class CamerasInterface{ ...@@ -666,8 +710,11 @@ public class CamerasInterface{
}catch(SAXException se) { }catch(SAXException se) {
se.printStackTrace(); se.printStackTrace();
throw new IllegalArgumentException ("SAX error"); throw new IllegalArgumentException ("SAX error");
// }catch (SAXParseException spe) {
} }
return serial; this.is_10398 = "10398".equals(model);
return new String[] {serial, model};
} }
public double getSensorTemperature(int chn, int EEPROM_chn){ public double getSensorTemperature(int chn, int EEPROM_chn){
...@@ -899,7 +946,7 @@ public class CamerasInterface{ ...@@ -899,7 +946,7 @@ public class CamerasInterface{
return setupCameraAcquisition(Double.NaN); return setupCameraAcquisition(Double.NaN);
} }
public boolean setupCameraAcquisition(final double exposureScale){ public boolean setupCameraAcquisition(final double exposureScale){
final boolean mp14 = true;// FIXME: Modified for 14Mpix // final boolean mp14 = is14Mpix();
final int ipLength=this.resetURLs.length; final int ipLength=this.resetURLs.length;
final boolean [] results=new boolean[ipLength]; final boolean [] results=new boolean[ipLength];
for (int chn=0;chn<ipLength;chn++) results[chn]=(this.sensorPresent[chn]!=null); for (int chn=0;chn<ipLength;chn++) results[chn]=(this.sensorPresent[chn]!=null);
...@@ -918,23 +965,27 @@ public class CamerasInterface{ ...@@ -918,23 +965,27 @@ public class CamerasInterface{
} }
startAndJoin(threads); startAndJoin(threads);
if (Double.isNaN(exposureScale)){ // full init if (Double.isNaN(exposureScale)){ // full init
// int nRepeat=this.setupTriggerMode?4:1;
int nRepeat=this.setupTriggerMode?4:2; // FIXME: Modified for 14Mpix int nRepeat=this.setupTriggerMode?4:1;
int sleep_ms = 1000;
if (is14Mpix()) {
nRepeat=this.setupTriggerMode?4:2; // FIXME: Modified for 14Mpix
sleep_ms = 2000;
}
if (this.nc393) nRepeat++; // is it needed? if (this.nc393) nRepeat++; // is it needed?
for (int i=0;i<nRepeat;i++){ for (int i=0;i<nRepeat;i++){
if (this.debugLevel>0) System.out.println((i+1)+" of "+nRepeat+": Triggering cameras to give parameters a chance to propagate"); if (this.debugLevel>0) System.out.println((i+1)+" of "+nRepeat+": Triggering cameras to give parameters a chance to propagate");
trigger(); trigger();
try try
{ {
Thread.sleep( 2000 ); // ms // FIXME: Modified for 14Mpix Thread.sleep( sleep_ms ); // ms // FIXME: Modified for 14Mpix
} }
catch ( InterruptedException e ) catch ( InterruptedException e )
{ {
System.out.println( "awakened prematurely" ); System.out.println( "awakened prematurely" );
} }
} }
} else if (is14Mpix()) {
} else if (mp14) {
try try
{ {
Thread.sleep( 2000 ); // ms // FIXME: Modified for 14Mpix Thread.sleep( 2000 ); // ms // FIXME: Modified for 14Mpix
...@@ -1402,7 +1453,6 @@ public class CamerasInterface{ ...@@ -1402,7 +1453,6 @@ public class CamerasInterface{
public ImagePlus [] getImages(final boolean [] acquire, boolean resetAndTrigger, final boolean show){ public ImagePlus [] getImages(final boolean [] acquire, boolean resetAndTrigger, final boolean show){
final boolean dual_trig = false;
final boolean [] acquireIPs=selectIPs(acquire); final boolean [] acquireIPs=selectIPs(acquire);
if (this.debugLevel>2) { if (this.debugLevel>2) {
System.out.println("getImages(...) 2"); System.out.println("getImages(...) 2");
...@@ -1410,20 +1460,16 @@ public class CamerasInterface{ ...@@ -1410,20 +1460,16 @@ public class CamerasInterface{
} }
if (resetAndTrigger) { if (resetAndTrigger) {
if (is14Mpix()) {
try { // FIXME: Make conditional for 14MPix try { // FIXME: Make conditional for 14MPix
Thread.sleep(2000); Thread.sleep(2000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
}
resetCameras(); resetCameras();
trigger(); trigger();
if (dual_trig) {
timestampIPs(acquireIPs); // ignoring results, just wait
resetCameras();
// trigger();
jp4_Instances[0].readDummyURL("http://192.168.0.236/parsedit.php?immediate&TRIG_PERIOD=1*0");
}
} }
final double [] timestamps= timestampIPs(acquireIPs); final double [] timestamps= timestampIPs(acquireIPs);
if (this.debugLevel>2) System.out.println("getImages(): this.imagesIP.length=" + this.imagesIP.length); if (this.debugLevel>2) System.out.println("getImages(): this.imagesIP.length=" + this.imagesIP.length);
...@@ -1621,12 +1667,14 @@ public class CamerasInterface{ ...@@ -1621,12 +1667,14 @@ public class CamerasInterface{
if (debugLevel>2) System.out.println(String.format("this.laserPointers.setLasers (0x%x)", sequence[nSeqNum])); if (debugLevel>2) System.out.println(String.format("this.laserPointers.setLasers (0x%x)", sequence[nSeqNum]));
} }
resetIPs(selectIPs(lasersIPs)); // flush buffer resetIPs(selectIPs(lasersIPs)); // flush buffer
if (is14Mpix()) {
try { // FIXME: Make conditional for 14MPix try { // FIXME: Make conditional for 14MPix
Thread.sleep(2000); Thread.sleep(2000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
}
trigger(); // trigger cameras trigger(); // trigger cameras
ipIndexAtomic.set(0); ipIndexAtomic.set(0);
final int fnSeqNum=nSeqNum; final int fnSeqNum=nSeqNum;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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