Commit 67fc93ad authored by ahoms's avatar ahoms

* added Espia::AcqEndCallback, used in Frelon::SyncCtrlObj to

  stop the camera when the NbHwFrames > MaxRegVal (16 bits)
* added Frelon::SerialLine::isRegCacheable, using NonCacheableRegList
* implemented multi-threaded testfrelonserialline.py
* added Frelon LastWarn and timming registers (v2.1b), 
  corrected MultiLineCmd enum
* added Frelon::E2V ChipType
* added svn:ignore *.P in several directories 


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@163 45c4679d-1946-429d-baad-37912b19538b
parent c89281b3
......@@ -23,12 +23,19 @@ enum Reg {
DarkPixelCalib, DarkPixelMode, ChanControl, Mire,
AoiLineBegin, AoiLineWidth, AoiPixelBegin, AoiPixelWidth,
AoiImageHeight, AoiImageWidth, ChanOnImage, ChanOnCcd,
Version, CompSerNb, Warn,
Version, CompSerNb, Warn, LastWarn,
LineClockPer, PixelClockPer, FirstPHIVLen, PHIHSetupLen,
SingleVertXfer, SingleHorzXfer, AllVertXfer, AllHorzXfer,
ReadoutTime, TransferTime, CcdModesAvail,
};
typedef std::map<Reg, std::string> RegStrMapType;
extern RegStrMapType RegStrMap;
typedef std::vector<Reg> RegListType;
extern RegListType NonCacheableRegList;
extern const int MaxRegVal;
enum Cmd {
Reset, Start, Stop, Save,
......@@ -40,7 +47,7 @@ extern CmdStrMapType CmdStrMap;
enum MultiLineCmd {
Help, Config, Dac, Volt,
Aoi,
Aoi, PLL, Timing,
};
typedef std::map<MultiLineCmd, std::string> MultiLineCmdStrMapType;
......@@ -96,6 +103,7 @@ extern const FrameDim MaxFrameDim;
enum ChipType {
Atmel,
Kodak,
E2V,
};
typedef std::map<ChipType, double> ChipPixelSizeMapType;
......
......@@ -109,8 +109,24 @@ class SyncCtrlObj : public HwSyncCtrlObj
virtual void getValidRanges(ValidRangesType& valid_ranges);
private:
class AcqEndCallback : public Espia::AcqEndCallback
{
public:
AcqEndCallback(Camera& cam) : m_cam(cam) {}
protected:
virtual void acqFinished(const HwFrameInfoType& frame_info)
{
m_cam.stop();
}
private:
Camera& m_cam;
};
Espia::Acq& m_acq;
Camera& m_cam;
AcqEndCallback m_acq_end_cb;
};
......
......@@ -85,6 +85,8 @@ class SerialLine : public HwSerialLine
int max_len = MaxReadLen,
double timeout = TimeoutDefault);
bool isRegCacheable(Reg reg);
Espia::SerialLine& m_espia_ser_line;
Cond m_cond;
int m_last_warn;
......
......@@ -18,13 +18,21 @@ enum Reg {
DarkPixelCalib, DarkPixelMode, ChanControl, Mire,
AoiLineBegin, AoiLineWidth, AoiPixelBegin, AoiPixelWidth,
AoiImageHeight, AoiImageWidth, ChanOnImage, ChanOnCcd,
Version, CompSerNb, Warn,
Version, CompSerNb, Warn, LastWarn,
LineClockPer, PixelClockPer, FirstPHIVLen, PHIHSetupLen,
SingleVertXfer, SingleHorzXfer, AllVertXfer, AllHorzXfer,
ReadoutTime, TransferTime, CcdModesAvail,
};
/*
typedef std::map<Reg, std::string> RegStrMapType;
extern RegStrMapType RegStrMap;
typedef std::vector<Reg> RegListType;
extern RegListType NonCacheableRegList;
*/
const int MaxRegVal;
enum Cmd {
Reset, Start, Stop, Save,
};
......@@ -35,7 +43,7 @@ extern CmdStrMapType CmdStrMap;
enum MultiLineCmd {
Help, Config, Dac, Volt,
Aoi,
Aoi, PLL, Timing,
};
/*
typedef std::map<MultiLineCmd, std::string> MultiLineCmdStrMapType;
......@@ -91,6 +99,7 @@ extern const FrameDim MaxFrameDim;
enum ChipType {
Atmel,
Kodak,
E2V,
};
/*
typedef std::map<ChipType, double> ChipPixelSizeMapType;
......
......@@ -52,9 +52,32 @@ static const RegPair RegStrCList[] = {
RegPair(Version, "VER"),
RegPair(CompSerNb, "SN"),
RegPair(Warn, "W"),
RegPair(LastWarn, "LW"),
RegPair(LineClockPer, "TLC"),
RegPair(PixelClockPer, "TPC"),
RegPair(FirstPHIVLen, "TFV"),
RegPair(PHIHSetupLen, "THS"),
RegPair(SingleVertXfer, "TOV"),
RegPair(SingleHorzXfer, "TOH"),
RegPair(AllVertXfer, "TAV"),
RegPair(AllHorzXfer, "TAH"),
RegPair(ReadoutTime, "TRD"),
RegPair(TransferTime, "TTR"),
RegPair(CcdModesAvail, "CMA"),
};
RegStrMapType lima::Frelon::RegStrMap(C_LIST_ITERS(RegStrCList));
static Reg NonCacheableRegCList[] = {
Warn,
AoiLineBegin, AoiLineWidth, AoiPixelBegin, AoiPixelWidth,
AoiImageHeight, AoiImageWidth, ChanOnImage, ChanOnCcd,
};
RegListType
lima::Frelon::NonCacheableRegList(C_LIST_ITERS(NonCacheableRegCList));
const int lima::Frelon::MaxRegVal = (1 << 16) - 1;
typedef pair<Cmd, string> CmdPair;
static const CmdPair CmdStrCList[] = {
......@@ -73,8 +96,8 @@ static const MLCmdPair MLCmdStrCList[] = {
MLCmdPair(Dac, "D"),
MLCmdPair(Volt, "V"),
MLCmdPair(Aoi, "AOI"),
MLCmdPair(Aoi, "PLL"),
MLCmdPair(Aoi, "TIM"),
MLCmdPair(PLL, "PLL"),
MLCmdPair(Timing, "TIM"),
};
MultiLineCmdStrMapType
lima::Frelon::MultiLineCmdStrMap(C_LIST_ITERS(MLCmdStrCList));
......@@ -120,6 +143,7 @@ typedef pair<ChipType, double> ChipSizePair;
static const ChipSizePair ChipPixelSizeCList[] = {
ChipSizePair(Atmel, 14e-6),
ChipSizePair(Kodak, 24e-6),
ChipSizePair(E2V, 15e-6),
};
ChipPixelSizeMapType
lima::Frelon::ChipPixelSizeMap(C_LIST_ITERS(ChipPixelSizeCList));
......@@ -499,8 +499,6 @@ void Camera::getTimeUnitFactor(TimeUnitFactor& time_unit_factor)
void Camera::setExpTime(double exp_time)
{
const int MaxVal = (1 << 16) - 1;
bool ok = false;
int exp_val;
TimeUnitFactor seq_clist[] = { Microseconds, Milliseconds };
......@@ -508,7 +506,7 @@ void Camera::setExpTime(double exp_time)
for (it = seq_clist; it != end; ++it) {
double factor = TimeUnitFactorMap[*it];
exp_val = int(exp_time / factor + 0.1);
ok = (exp_val <= MaxVal);
ok = (exp_val <= MaxRegVal);
if (ok)
break;
}
......
......@@ -182,7 +182,7 @@ void BufferCtrlObj::unregisterFrameCallback(HwFrameCallback& frame_cb)
*******************************************************************/
SyncCtrlObj::SyncCtrlObj(Acq& acq, Camera& cam, BufferCtrlObj& buffer_ctrl)
: HwSyncCtrlObj(buffer_ctrl), m_acq(acq), m_cam(cam)
: HwSyncCtrlObj(buffer_ctrl), m_acq(acq), m_cam(cam), m_acq_end_cb(cam)
{
}
......@@ -223,7 +223,16 @@ void SyncCtrlObj::getLatTime(double& lat_time)
void SyncCtrlObj::setNbHwFrames(int nb_frames)
{
m_acq.setNbFrames(nb_frames);
m_cam.setNbFrames(nb_frames);
int cam_nb_frames = nb_frames;
if (cam_nb_frames > MaxRegVal) {
cam_nb_frames = 0;
if (!m_acq_end_cb.getAcq())
m_acq.registerAcqEndCallback(m_acq_end_cb);
} else if (m_acq_end_cb.getAcq())
m_acq.unregisterAcqEndCallback(m_acq_end_cb);
m_cam.setNbFrames(cam_nb_frames);
}
void SyncCtrlObj::getNbHwFrames(int& nb_frames)
......
......@@ -72,7 +72,7 @@ void SerialLine::writeCmd(const string& buffer, bool no_wait)
}
m_curr_cache = false;
if (m_cache_act && reg_found && (m_curr_reg != Warn)) {
if (reg_found && isRegCacheable(m_curr_reg)) {
bool is_req = !msg_parts[MsgReq].empty();
m_curr_op = is_req ? ReadReg : WriteReg;
const string& cache_val = m_reg_cache[m_curr_reg];
......@@ -150,7 +150,7 @@ void SerialLine::readSingleLine(string& buffer, int max_len, double timeout)
decodeFmtResp(buffer, m_curr_fmt_resp);
bool reg_op = ((m_curr_op == WriteReg) || (m_curr_op == ReadReg));
if (!m_cache_act || !reg_op || (m_curr_reg == Warn))
if (!reg_op || !isRegCacheable(m_curr_reg))
return;
string& cache_val = m_reg_cache[m_curr_reg];
......@@ -179,6 +179,15 @@ void SerialLine::readMultiLine(string& buffer, int max_len)
throw LIMA_HW_EXC(Error, "Timeout reading Frelon multi line");
}
bool SerialLine::isRegCacheable(Reg reg)
{
if (!m_cache_act)
return false;
const RegListType& list = NonCacheableRegList;
return (find(list.begin(), list.end(), reg) == list.end());
}
void SerialLine::flush()
{
m_espia_ser_line.flush();
......
......@@ -6,8 +6,8 @@ frelon-objs = ../src/Frelon.o ../../common/espia/src/Espia.o \
include ../../common/espia/include/espia.inc
LDFLAGS = -pthread -L$(ESPIA_DRV_LIB)
LDLIBS = -lespia
LDFLAGS = -pthread -L$(ESPIA_DRV_LIB) -L../../../third-party/Processlib/build
LDLIBS = -lespia -lprocesslib
CXXFLAGS = -I../include -I../../common/espia/include \
-I../../../hardware/include -I../../../common/include \
......@@ -17,13 +17,16 @@ CXXFLAGS = -I../include -I../../common/espia/include \
-I../../../third-party/Processlib/tasks/include \
-I$(ESPIA_DRV_INCL) -Wall -pthread
all: testfrelon testfreloninterface
all: testfrelon testfreloninterface testfrelonspectroscopy
testfrelon: testfrelon.o $(frelon-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(LDLIBS)
testfreloninterface: testfreloninterface.o $(frelon-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(LDLIBS) ../../../control/src/Ct.o -L../../../third-party/Processlib/build -lprocesslib
$(CXX) $(LDFLAGS) -o $@ $+ $(LDLIBS) ../../../control/src/Ct.o
testfrelonspectroscopy: testfrelonspectroscopy.o $(frelon-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(LDLIBS) ../../../control/src/Ct.o
clean:
rm -f *.o testfrelon testfreloninterface
......@@ -35,4 +38,4 @@ clean:
-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
rm -f $*.d
-include $(SRCS:.cpp=.P)
\ No newline at end of file
-include $(SRCS:.cpp=.P)
import sys, os, thread, time, random
import lima
class FrelonData:
def __init__(self, edev_nr=0):
self.edev = lima.Espia.Dev(edev_nr)
self.eser_line = lima.Espia.SerialLine(self.edev)
self.frelon = lima.Frelon.Camera(self.eser_line)
self.fser_line = self.frelon.getSerialLine()
self.finish_cond = lima.Cond()
self.finish_req = False
self.log_cond = lima.Cond()
def getFrelonCamera(self):
return self.frelon
def getFrelonSerialLine(self):
return self.fser_line
def getFinishReq(self):
self.finish_cond.acquire()
finish_req = self.finish_req
self.finish_cond.release()
return finish_req
def setFinishReq(self, finish_req):
self.finish_cond.acquire()
self.finish_req = finish_req
self.finish_cond.release()
def logMsg(self, msg):
self.log_cond.acquire()
print msg
self.log_cond.release()
def logMsgTime(self, msg, dt):
self.logMsg('%s [%10.6f sec]' %(msg, dt))
def change_cache_mode(frelon_data):
fser_line = frelon_data.getFrelonSerialLine()
while not frelon_data.getFinishReq():
cache_act = not fser_line.getCacheActive()
t0 = time.time()
fser_line.setCacheActive(cache_act)
dt = time.time() - t0
frelon_data.logMsgTime('Setting cache active: %d' % cache_act, dt)
time.sleep(60)
def read_multi_line(frelon_data):
fser_line = frelon_data.getFrelonSerialLine()
multi_line_cmds = ['H', 'V', 'D', 'AOI', 'C', 'PLL']
while not frelon_data.getFinishReq():
for cmd in multi_line_cmds:
t0 = time.time()
fser_line.write(cmd)
dt = time.time() - t0
frelon_data.logMsgTime('Sending multi-line cmd: "%s"' % cmd, dt)
t0 = time.time()
ans = fser_line.readLine()
dt = time.time() - t0
frelon_data.logMsgTime('Received "%s" resp:\n"%s"' % (cmd, ans),
dt)
def change_exp_time(frelon_data):
frelon = frelon_data.getFrelonCamera()
while not frelon_data.getFinishReq():
exp_time = random.random() * 65.535
t0 = time.time()
frelon.setExpTime(exp_time)
dt = time.time() - t0
frelon_data.logMsgTime('Setting exp_time to: %s' % exp_time, dt)
t0 = time.time()
new_exp_time = frelon.getExpTime()
dt = time.time() - t0
frelon_data.logMsgTime('New exp_time: %s' % new_exp_time, dt)
def main(argv):
frelon_data = FrelonData()
thread_fn = {
'cache_mode': change_cache_mode,
'multi_line': read_multi_line,
'exp_time': change_exp_time,
}
thread_id = {}
for name, fn in thread_fn.items():
thread_id[name] = thread.start_new_thread(fn, (frelon_data,))
raw_input()
frelon_data.setFinishReq(True)
if __name__ == '__main__':
main(sys.argv)
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