Commit 10cddb0b authored by ahoms's avatar ahoms
Browse files

* added global Sleep() in Timestamp

* added Corner class based on X/YBorder; added Size::getCornerCoords
* added C_LIST_SIZE/END/ITERS to MiscUtils.h; used in Frelon tables
* implemented Frelon::Camera, SerNb, FrameTransferMode and InputChan;
  first implementation of Bin, Flip and Roi (including checkRoi)



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@80 45c4679d-1946-429d-baad-37912b19538b
parent a59d15c4
......@@ -4,6 +4,7 @@
#include "EspiaSerialLine.h"
#include <string>
#include <map>
#include <vector>
namespace lima
{
......@@ -12,7 +13,7 @@ namespace Frelon
{
enum Reg {
NrFrames, ExpTime, ShutCloseTime, LatencyTime,
NbFrames, ExpTime, ShutCloseTime, LatencyTime,
RoiLineBegin, RoiLineWidth, RoiPixelBegin, RoiPixelWidth,
ChanMode, TimeUnit, RoiEnable, RoiFast,
AntiBloom, BinVert, BinHorz, ConfigHD,
......@@ -22,23 +23,68 @@ enum Reg {
DarkPixelCalib, DarkPixelMode, ChanControl, Mire,
AoiLineBegin, AoiLineWidth, AoiPixelBegin, AoiPixelWidth,
AoiImageHeight, AoiImageWidth, ChanOnImage, ChanOnCcd,
Version, SerNr, Warn,
Version, CompSerNb, Warn,
};
extern std::map<Reg, std::string> RegStrMap;
typedef std::map<Reg, std::string> RegStrMapType;
extern RegStrMapType RegStrMap;
enum Cmd {
Reset, Start, Stop, Save,
};
extern std::map<Cmd, std::string> CmdStrMap;
typedef std::map<Cmd, std::string> CmdStrMapType;
extern CmdStrMapType CmdStrMap;
enum MultiLineCmd {
Help, Config, Dac, Volt,
Aoi,
};
extern std::map<MultiLineCmd, std::string> MultiLineCmdStrMap;
typedef std::map<MultiLineCmd, std::string> MultiLineCmdStrMapType;
extern MultiLineCmdStrMapType MultiLineCmdStrMap;
enum FrameTransferMode {
FFM = 0, FTM = 1,
};
enum InputChan {
Chan1 = (1 << 0),
Chan2 = (1 << 1),
Chan3 = (1 << 2),
Chan4 = (1 << 3),
Chan13 = Chan1 | Chan3,
Chan24 = Chan2 | Chan4,
Chan12 = Chan1 | Chan2,
Chan34 = Chan3 | Chan4,
Chan1234 = Chan12 | Chan34,
};
typedef std::pair<int, int> ChanRange;
typedef std::map<FrameTransferMode, ChanRange> FTMChanRangeMapType;
extern FTMChanRangeMapType FTMChanRangeMap;
typedef std::vector<InputChan> InputChanList;
typedef std::map<FrameTransferMode, InputChanList> FTMInputChanListMapType;
extern FTMInputChanListMapType FTMInputChanListMap;
enum SerNbParam {
SerNb = 0x00ff,
F4M = 0x2000,
F2k16 = 0x4000,
Taper = 0x8000,
};
enum RoiMode {
None, Slow, Fast, Kinetic,
};
extern const FrameDim MaxFrameDim;
} // namespace Frelon
......
......@@ -22,12 +22,87 @@ class Camera
void hardReset();
void getVersion(std::string& ver);
void getComplexSerialNb(int& complex_ser_nb);
void getCameraType(int& type);
void setInputChan(InputChan input_chan);
void getInputChan(InputChan& input_chan);
void setFrameTransferMode(FrameTransferMode ftm);
void getFrameTransferMode(FrameTransferMode& ftm);
void getFrameDim(FrameDim& frame_dim);
bool isChanActive(InputChan chan);
void setFlip(const Point& flip);
void getFlip(Point& flip);
void setBin(const Bin& bin);
void getBin(Bin& bin);
void setRoiMode(RoiMode roi_mode);
void getRoiMode(RoiMode& roi_mode);
void checkRoi(Roi& roi);
void setRoi(const Roi& roi);
void getRoi(Roi& roi);
void setTriggerMode(TrigMode trig_mode);
void getTriggerMode(TrigMode& trig_mode);
void setExpTime(double exp_time);
void getExpTime(double& exp_time);
void setLatTime(double lat_time);
void getLatTime(double& lat_time);
void setNbFrames(int nb_frames);
void getNbFrames(int& nb_frames);
private:
static const double HorzBinSleepTime;
void sendCmd(Cmd cmd);
void getSerialNbParam(SerNbParam param, int& val);
void setChanMode(int chan_mode);
void getChanMode(int& chan_mode);
void getBaseChanMode(FrameTransferMode ftm, int& base_chan_mode);
void getInputChanMode(FrameTransferMode ftm, InputChan input_chan,
int& chan_mode);
void setFlipMode(int flip_mode);
void getFlipMode(int& flip_mode);
void getMirror(Point& mirror);
void getNbChan(Point& nb_chan);
void getCcdSize(Size& ccd_size);
void getChanSize(Size& chan_size);
void xformChanCoords(const Point& point, Point& chan_point,
Corner& ref_corner);
void getImageRoi(const Roi& chan_roi, Roi& image_roi);
void getFinalRoi(const Roi& image_roi, const Point& roi_offset,
Roi& final_roi);
void getChanRoi(const Roi& image_roi, Roi& chan_roi);
void getImageRoiOffset(const Roi& req_roi, const Roi& image_roi,
Point& roi_offset);
void checkRoiMode(const Roi& roi);
void processRoiReq(Roi& roi, Roi& chan_roi, Point& roi_offset);
SerialLine m_ser_line;
Point m_roi_offset;
};
inline bool Camera::isChanActive(InputChan chan)
{
InputChan curr_chan;
getInputChan(curr_chan);
return (curr_chan & chan) == chan;
};
} // namespace Frelon
......
......@@ -24,6 +24,8 @@ class SerialLine : public HwSerialLine
MaxReadLen = 10000,
};
typedef std::map<MsgPart, std::string> MsgPartStrMapType;
static const double TimeoutSingle, TimeoutNormal, TimeoutMultiLine,
TimeoutReset;
......@@ -54,7 +56,7 @@ class SerialLine : public HwSerialLine
virtual void getTimeout(double& timeout) const;
void splitMsg(const std::string& msg,
std::map<MsgPart, std::string>& msg_parts) const;
MsgPartStrMapType& msg_parts) const;
void decodeFmtResp(const std::string& ans, std::string& fmt_resp);
void sendFmtCmd(const std::string& cmd, std::string& resp);
......
#include "Frelon.h"
#include "MiscUtils.h"
using namespace lima;
using namespace lima::Frelon;
using namespace std;
typedef pair<Reg, string> RegPair;
static const RegPair RegStrList[] = {
RegPair(NrFrames, "N"),
static const RegPair RegStrCList[] = {
RegPair(NbFrames, "N"),
RegPair(ExpTime, "I"),
RegPair(ShutCloseTime, "F"),
RegPair(LatencyTime, "T"),
......@@ -48,35 +50,56 @@ static const RegPair RegStrList[] = {
RegPair(ChanOnCcd, "COC"),
RegPair(Version, "VER"),
RegPair(SerNr, "SN"),
RegPair(CompSerNb, "SN"),
RegPair(Warn, "W"),
};
static int RegStrListLen = sizeof(RegStrList) / sizeof(RegStrList[0]);
map<Reg, string> lima::Frelon::RegStrMap(RegStrList, (RegStrList +
RegStrListLen));
RegStrMapType lima::Frelon::RegStrMap(C_LIST_ITERS(RegStrCList));
typedef pair<Cmd, string> CmdPair;
static const CmdPair CmdStrList[] = {
static const CmdPair CmdStrCList[] = {
CmdPair(Reset, "RST"),
CmdPair(Start, "S"),
CmdPair(Stop, "O"),
CmdPair(Save, "SAV"),
};
static int CmdStrListLen = sizeof(CmdStrList) / sizeof(CmdStrList[0]);
map<Cmd, string> lima::Frelon::CmdStrMap(CmdStrList, (CmdStrList +
CmdStrListLen));
CmdStrMapType lima::Frelon::CmdStrMap(C_LIST_ITERS(CmdStrCList));
typedef pair<MultiLineCmd, string> MLCmdPair;
static const MLCmdPair MLCmdStrList[] = {
static const MLCmdPair MLCmdStrCList[] = {
MLCmdPair(Help, "H"),
MLCmdPair(Config, "C"),
MLCmdPair(Dac, "D"),
MLCmdPair(Volt, "V"),
MLCmdPair(Aoi, "AOI"),
};
static int MLCmdStrListLen = sizeof(MLCmdStrList) / sizeof(MLCmdStrList[0]);
static const MLCmdPair *MLCmdStrEnd = MLCmdStrList + MLCmdStrListLen;
map<MultiLineCmd, string> lima::Frelon::MultiLineCmdStrMap(MLCmdStrList,
MLCmdStrEnd);
MultiLineCmdStrMapType
lima::Frelon::MultiLineCmdStrMap(C_LIST_ITERS(MLCmdStrCList));
typedef pair<FrameTransferMode, ChanRange> RangePair;
static const RangePair FTMChanRangeCList[] = {
RangePair(FFM, ChanRange(1, 10)),
RangePair(FTM, ChanRange(10, 13)),
};
FTMChanRangeMapType
lima::Frelon::FTMChanRangeMap(C_LIST_ITERS(FTMChanRangeCList));
static const InputChan FFMInputChanCList[] = {
Chan1, Chan2, Chan3, Chan4, Chan13, Chan24, Chan12, Chan34, Chan1234,
};
static const InputChan FTMInputChanCList[] = {
Chan1234, Chan34, Chan12,
};
typedef pair<FrameTransferMode, InputChanList> InputChanPair;
static const InputChanPair FTMInputChanListCList[] = {
InputChanPair(FFM, InputChanList(C_LIST_ITERS(FFMInputChanCList))),
InputChanPair(FTM, InputChanList(C_LIST_ITERS(FTMInputChanCList))),
};
FTMInputChanListMapType
lima::Frelon::FTMInputChanListMap(C_LIST_ITERS(FTMInputChanListCList));
const FrameDim lima::Frelon::MaxFrameDim(2048, 2048, Bpp16);
......@@ -5,6 +5,8 @@
using namespace lima::Frelon;
using namespace std;
const double Camera::HorzBinSleepTime = 2;
Camera::Camera(Espia::SerialLine& espia_ser_line)
: m_ser_line(espia_ser_line)
{
......@@ -48,3 +50,370 @@ void Camera::getVersion(string& ver)
string cmd = RegStrMap[Version] + "?";
m_ser_line.sendFmtCmd(cmd, ver);
}
void Camera::getComplexSerialNb(int& complex_ser_nb)
{
readRegister(CompSerNb, complex_ser_nb);
}
void Camera::getSerialNbParam(SerNbParam param, int& val)
{
int complex_ser_nb;
getComplexSerialNb(complex_ser_nb);
val = complex_ser_nb & int(param);
}
void Camera::getCameraType(int& type)
{
int frelon_2k16;
getSerialNbParam(F2k16, frelon_2k16);
type = frelon_2k16 ? 2016 : 2014;
}
void Camera::setChanMode(int chan_mode)
{
writeRegister(ChanMode, chan_mode);
}
void Camera::getChanMode(int& chan_mode)
{
readRegister(ChanMode, chan_mode);
}
void Camera::getBaseChanMode(FrameTransferMode ftm, int& base_chan_mode)
{
base_chan_mode = FTMChanRangeMap[ftm].first;
}
void Camera::getInputChanMode(FrameTransferMode ftm, InputChan input_chan,
int& chan_mode)
{
getBaseChanMode(ftm, chan_mode);
const InputChanList& chan_list = FTMInputChanListMap[ftm];
InputChanList::const_iterator it;
it = find(chan_list.begin(), chan_list.end(), input_chan);
if (it == chan_list.end())
throw LIMA_HW_EXC(InvalidValue, "Invalid input channel");
chan_mode += it - chan_list.begin();
}
void Camera::setInputChan(InputChan input_chan)
{
FrameTransferMode ftm;
getFrameTransferMode(ftm);
int chan_mode;
getInputChanMode(ftm, input_chan, chan_mode);
setChanMode(chan_mode);
}
void Camera::getInputChan(InputChan& input_chan)
{
FrameTransferMode ftm;
getFrameTransferMode(ftm);
int chan_mode, base_chan_mode;
getChanMode(chan_mode);
getBaseChanMode(ftm, base_chan_mode);
input_chan = FTMInputChanListMap[ftm][chan_mode - base_chan_mode];
}
void Camera::setFrameTransferMode(FrameTransferMode ftm)
{
InputChan input_chan;
getInputChan(input_chan);
int chan_mode;
getInputChanMode(ftm, input_chan, chan_mode);
setChanMode(chan_mode);
}
void Camera::getFrameTransferMode(FrameTransferMode& ftm)
{
int chan_mode;
getChanMode(chan_mode);
FTMChanRangeMapType::const_iterator it, end = FTMChanRangeMap.end();
for (it = FTMChanRangeMap.begin(); it != end; ++it) {
ftm = it->first;
const ChanRange& range = it->second;
if ((chan_mode >= range.first) && (chan_mode < range.second))
return;
}
throw LIMA_HW_EXC(Error, "Invalid chan mode");
}
void Camera::getFrameDim(FrameDim& frame_dim)
{
frame_dim = MaxFrameDim;
FrameTransferMode ftm;
getFrameTransferMode(ftm);
if (ftm == FTM)
frame_dim /= Point(1, 2);
}
void Camera::setFlipMode(int flip_mode)
{
writeRegister(Flip, flip_mode);
}
void Camera::getFlipMode(int& flip_mode)
{
readRegister(Flip, flip_mode);
}
void Camera::setFlip(const Point& flip)
{
int flip_mode = (bool(flip.x) << 1) | (bool(flip.y) << 0);
setFlipMode(flip_mode);
}
void Camera::getFlip(Point& flip)
{
int flip_mode;
getFlipMode(flip_mode);
flip.x = (flip_mode >> 1) & 1;
flip.y = (flip_mode >> 0) & 1;
}
void Camera::setBin(const Bin& bin)
{
Bin curr_bin;
getBin(curr_bin);
if (bin == curr_bin)
return;
writeRegister(BinHorz, bin.getX());
Sleep(HorzBinSleepTime);
writeRegister(BinVert, bin.getY());
}
void Camera::getBin(Bin& bin)
{
int bin_x, bin_y;
readRegister(BinHorz, bin_x);
readRegister(BinVert, bin_y);
bin = Bin(bin_x, bin_y);
}
void Camera::setRoiMode(RoiMode roi_mode)
{
bool roi_hw = (roi_mode == Slow) || (roi_mode == Fast);
bool roi_fast = (roi_mode == Fast) || (roi_mode == Kinetic);
bool roi_kin = (roi_mode == Kinetic);
writeRegister(RoiEnable, roi_hw);
writeRegister(RoiFast, roi_fast);
writeRegister(RoiKinetic, roi_kin);
}
void Camera::getRoiMode(RoiMode& roi_mode)
{
int roi_hw, roi_fast, roi_kin;
readRegister(RoiEnable, roi_hw);
readRegister(RoiFast, roi_fast);
readRegister(RoiKinetic, roi_kin);
if (roi_fast && roi_kin)
roi_mode = Kinetic;
else if (roi_fast && roi_hw)
roi_mode = Fast;
else if (roi_hw)
roi_mode = Slow;
else
roi_mode = None;
}
void Camera::getMirror(Point& mirror)
{
mirror.x = isChanActive(Chan12) || isChanActive(Chan34);
mirror.y = isChanActive(Chan13) || isChanActive(Chan24);
}
void Camera::getNbChan(Point& nb_chan)
{
getMirror(nb_chan);
nb_chan += 1;
}
void Camera::getCcdSize(Size& ccd_size)
{
FrameDim frame_dim;
getFrameDim(frame_dim);
ccd_size = frame_dim.getSize();
}
void Camera::getChanSize(Size& chan_size)
{
getCcdSize(chan_size);
Point nb_chan;
getNbChan(nb_chan);
chan_size /= nb_chan;
}
void Camera::xformChanCoords(const Point& point, Point& chan_point,
Corner& ref_corner)
{
Size chan_size;
getChanSize(chan_size);
bool good_xchan = isChanActive(Chan1) || isChanActive(Chan3);
bool good_ychan = isChanActive(Chan1) || isChanActive(Chan2);
Point flip;
getFlip(flip);
XBorder ref_xb = (bool(flip.x) == !good_xchan) ? Left : Right;
YBorder ref_yb = (bool(flip.y) == !good_ychan) ? Top : Bottom;
Point mirror;
getMirror(mirror);
if (mirror.x)
ref_xb = (point.x < chan_size.getWidth()) ? Left : Right;
if (mirror.y)
ref_yb = (point.y < chan_size.getHeight()) ? Top : Bottom;
ref_corner.set(ref_xb, ref_yb);
Size ccd_size;
getCcdSize(ccd_size);
chan_point = ccd_size.getCornerCoords(point, ref_corner);
}
void Camera::getImageRoi(const Roi& chan_roi, Roi& image_roi)
{
Point img_tl, chan_tl = chan_roi.getTopLeft();
Point img_br, chan_br = chan_roi.getBottomRight();
Corner c_tl, c_br;
xformChanCoords(chan_tl, img_tl, c_tl);
xformChanCoords(chan_br, img_br, c_br);
Roi unbinned_roi(img_tl, img_br);
Bin bin;
getBin(bin);
image_roi = unbinned_roi.getBinned(bin);
}
void Camera::getFinalRoi(const Roi& image_roi, const Point& roi_offset,
Roi& final_roi)
{
Point tl = image_roi.getTopLeft() + roi_offset;
Point nb_chan;
getNbChan(nb_chan);
Size size = image_roi.getSize() * nb_chan;
final_roi = Roi(tl, size);
}
void Camera::getChanRoi(const Roi& image_roi, Roi& chan_roi)
{
Bin bin;
getBin(bin);
Roi unbinned_roi = image_roi.getUnbinned(bin);
Point chan_tl, img_tl = unbinned_roi.getTopLeft();
Point chan_br, img_br = unbinned_roi.getBottomRight();
Corner c_tl, c_br;
xformChanCoords(img_tl, chan_tl, c_tl);
xformChanCoords(img_br, chan_br, c_br);
chan_roi.setCorners(chan_tl, chan_br);
chan_tl = chan_roi.getTopLeft();
chan_br = chan_roi.getBottomRight();
bool two_xchan = (c_tl.getX() != c_br.getX());
bool two_ychan = (c_tl.getY() != c_br.getY());
Size chan_size;
getChanSize(chan_size);
if (two_xchan)
chan_br.x = chan_size.getWidth() - 1;
if (two_ychan)
chan_br.y = chan_size.getHeight() - 1;
chan_roi.setCorners(chan_tl, chan_br);
}
void Camera::getImageRoiOffset(const Roi& req_roi, const Roi& image_roi,
Point& roi_offset)
{
Point virt_tl = image_roi.getTopLeft();
Size ccd_size, image_size;
getCcdSize(ccd_size);
image_size = image_roi.getSize();
Point image_br = image_roi.getBottomRight() + 1;
Point mirror_tl = ccd_size - image_br - image_size;
Point req_tl = req_roi.getTopLeft();
if (req_tl.x >= image_br.x)
virt_tl.x = mirror_tl.x;
if (req_tl.y >= image_br.y)
virt_tl.y = mirror_tl.y;
roi_offset = virt_tl - image_roi.getTopLeft();
}
void Camera::checkRoiMode(const Roi& roi)
{
RoiMode roi_mode;
getRoiMode(roi_mode);
if (!roi.isActive())
roi_mode = None;
else if (roi_mode == None)
roi_mode = Slow;
setRoiMode(roi_mode);
}
void Camera::checkRoi(Roi& roi)
{
if (!roi.isActive())
return;
Roi chan_roi;
Point roi_offset;
processRoiReq(roi, chan_roi, roi_offset);
}
void Camera::processRoiReq(Roi& roi, Roi& chan_roi, Point& roi_offset)
{