Commit add903c1 authored by Roberto Arturo Homs-Regojo's avatar Roberto Arturo Homs-Regojo

Merge branch 'imgNr1' into 'master'

refactoring pco imgNr

See merge request !13
parents b0a98c2c d3839915
Pipeline #15079 passed with stages
in 20 minutes and 57 seconds
This diff is collapsed.
......@@ -260,10 +260,5 @@ DWORD WaitForMultipleObjects(DWORD, void **, bool, DWORD);
#endif
int _get_imageNr_from_imageTimestamp(void *buf, int shift);
#ifndef __linux__
int _get_time_from_imageTimestamp(void *buf, int shift, SYSTEMTIME *st);
#endif
#endif
......@@ -323,6 +323,7 @@ typedef struct
long msTotal, msRecord, msRecordLoop, msXfer, msTout;
long msStartAcqStart, msStartAcqEnd, msStartAcqNow;
int checkImgNrPco, checkImgNrPcoTimestamp, checkImgNrLima, checkImgNrOrder;
bool checkImgNr;
#define LEN_TRACEACQ_TRHEAD 11
// long msThreadBeforeXfer, msThreadAfterXfer, msThreadEnd;
......@@ -658,7 +659,11 @@ namespace lima
~CheckImgNr();
void init(STC_traceAcq *traceAcq);
void update(int iLimaFrame, void *ptrImage);
;
int _get_imageNr_from_imageTimestamp(void *buf, int shift);
#ifndef __linux__
int _get_time_from_imageTimestamp(void *buf, int shift, SYSTEMTIME *st);
#endif
private:
Camera *m_cam;
......@@ -668,6 +673,7 @@ namespace lima
int pcoImgNrOrder;
int pcoImgNrLast;
int alignmentShift;
bool bNoTimestamp;
}; // class CheckImgNr
//--------------------------------------- class Camera
......
......@@ -734,7 +734,7 @@ void Camera::_init_dimax()
{
DEB_CONSTRUCTOR();
char msg[MSG_SIZE + 1];
const char *pcoFn;
const char *pcoFn = "Camera::_init_dimax";
int error = 0;
DWORD _dwValidImageCnt, _dwMaxImageCnt;
......@@ -1729,7 +1729,7 @@ void Camera::_pco_set_shutter_rolling_edge(int &error)
{
DEB_MEMBER_FUNCT();
DEF_FNID;
char *msg;
char *msg="none";
const char *cmsg;
char msgBuff[MSG_SIZE + 1];
......
......@@ -163,7 +163,7 @@ void Camera::_AcqThread::threadFunction_Dimax()
DEB_MEMBER_FUNCT();
DEF_FNID;
const char *_msgAbort;
const char *_msgAbort = "notSet";
TIME_USEC tStart;
long long usStart, usStartTot;
......@@ -223,6 +223,8 @@ void Camera::_AcqThread::threadFunction_Dimax()
Camera::Status _statusReturn = Camera::Ready;
bool continueAcq = true;
m_cam.m_checkImgNr->init(& m_cam.m_pcoData->traceAcq);
bool bNoTimestamp;
WORD wTimestampMode;
m_cam._pco_GetTimestampMode(wTimestampMode, err);
......@@ -419,19 +421,13 @@ void Camera::_AcqThread::threadFunction_Dimax()
break;
}
pcoFrameNrTimestamp =
image_nr_from_timestamp(limaBuffPtr, 0, bNoTimestamp);
m_cam.m_pcoData->traceAcq.usTicks[traceAcq_pcoSdk].value +=
usElapsedTime(usStart);
usElapsedTimeSet(usStart);
m_cam.m_pcoData->traceAcq.checkImgNrPcoTimestamp =
pcoFrameNrTimestamp;
m_cam.m_pcoData->traceAcq.checkImgNrPco = pcoFrameNr;
m_cam.m_pcoData->traceAcq.checkImgNrLima = limaFrameNr;
m_cam.m_pcoData->traceAcq.checkImgNrLima = limaFrameNr;
m_cam.m_pcoData->traceAcq.msStartAcqNow = msElapsedTime(tStart);
// check PCO ImgNr with the limaFrame
m_cam.m_checkImgNr->update(limaFrameNr, limaBuffPtr);
pcoFrameNrTimestamp = m_cam.m_pcoData->traceAcq.checkImgNrPcoTimestamp;
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = limaFrameNr;
......@@ -557,7 +553,7 @@ void Camera::_AcqThread::threadFunction_Edge()
DEB_MEMBER_FUNCT();
DEF_FNID;
const char *_msgAbort;
const char *_msgAbort = "notSet";
TIME_USEC tStart;
long long usStart, usStartTot;
......@@ -607,6 +603,8 @@ void Camera::_AcqThread::threadFunction_Edge()
if (m_cam.m_quit)
return;
m_cam.m_checkImgNr->init(& m_cam.m_pcoData->traceAcq);
Camera::Status _statusReturn = Camera::Ready;
bool continueAcq = true;
......@@ -802,21 +800,15 @@ void Camera::_AcqThread::threadFunction_Edge()
{
m_cam.grabber->Extract_Image(limaBuffPtr, pcoBuffPtr, width,
height);
// pcoFrameNrTimestamp=image_nr_from_timestamp(limaBuffPtr,0);
pcoFrameNrTimestamp =
image_nr_from_timestamp(limaBuffPtr, 0, bNoTimestamp);
m_cam.m_pcoData->traceAcq.usTicks[traceAcq_pcoSdk].value +=
usElapsedTime(usStart);
usElapsedTimeSet(usStart);
m_cam.m_pcoData->traceAcq.checkImgNrPcoTimestamp =
pcoFrameNrTimestamp;
m_cam.m_pcoData->traceAcq.checkImgNrPco = pcoFrameNr;
m_cam.m_pcoData->traceAcq.checkImgNrLima = limaFrameNr;
m_cam.m_pcoData->traceAcq.checkImgNrLima = limaFrameNr;
m_cam.m_pcoData->traceAcq.msStartAcqNow = msElapsedTime(tStart);
// check PCO ImgNr with the limaFrame
m_cam.m_checkImgNr->update(limaFrameNr, limaBuffPtr);
pcoFrameNrTimestamp = m_cam.m_pcoData->traceAcq.checkImgNrPcoTimestamp;
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = limaFrameNr;
continueAcq =
......@@ -941,7 +933,9 @@ Camera::Camera(const std::string &camPar)
DEB_CONSTRUCTOR();
DEB_ALWAYS() << "... ::Camera [entry]";
m_pco_buffer_nrevents = 0;
m_cam_connected = false;
m_acq_frame_nb = 1;
m_sync = NULL;
......@@ -1143,7 +1137,8 @@ void Camera::_waitForRecording(int nrFrames, DWORD &_dwValidImageCnt,
msElapsedTimeSet(tStart);
tStart0 = tStart;
long timeout, timeout0, msNowRecordLoop, msRecord, msXfer, msTotal;
long timeout, timeout0, msNowRecordLoop, msXfer, msTotal;
long msRecord=0;
int nb_acq_frames;
int requestStop = stopNone;
......@@ -1328,27 +1323,6 @@ void Camera::_waitForRecording(int nrFrames, DWORD &_dwValidImageCnt,
// 2018/03/18
//=========================================================================================================
//=========================================================================================================
//=========================================================================================================
int image_nr_from_timestamp(void *buf, int shift, bool bDisable)
{
unsigned short *b;
int y;
int image_nr = 0;
if (bDisable)
return -1;
b = (unsigned short *)(buf);
y = 100 * 100 * 100;
for (; y > 0; y /= 100)
{
*b >>= shift;
image_nr += (((*b & 0x00F0) >> 4) * 10 + (*b & 0x000F)) * y;
b++;
}
return image_nr;
}
//=================================================================================================
//=================================================================================================
......@@ -1624,7 +1598,8 @@ void Camera::_AcqThread::threadFunction_SwitchEdge()
DEB_MEMBER_FUNCT();
DEF_FNID;
const char *_msgAbort, *msg;
const char *_msgAbort = "notSet";
const char *msg;
TIME_USEC tStart;
long long usStart, usStartTot;
......
......@@ -87,6 +87,222 @@ void _pco_time2dwbase(double exp_time, DWORD &dwExp, WORD &wBase)
return;
}
//====================================================================
//====================================================================
// extract image number and time from the image
// timeStampMode must be enabled
//====================================================================
//====================================================================
CheckImgNr::CheckImgNr(Camera *cam)
{
DEF_FNID;
//printf("--- %s> [ENTRY]\n", fnId);
m_cam = cam;
}
CheckImgNr::~CheckImgNr()
{
DEF_FNID;
//printf("--- %s> [ENTRY]\n", fnId);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void CheckImgNr::update(int iLimaFrame, void *ptrImage)
{
DEF_FNID;
//printf("--- %s> [ENTRY]\n", fnId);
int pcoImgNr, diff;
if (!checkImgNr)
return;
pcoImgNr = _get_imageNr_from_imageTimestamp(ptrImage, alignmentShift);
if (pcoImgNr <= pcoImgNrLast)
pcoImgNrOrder++;
diff = pcoImgNr - iLimaFrame;
m_traceAcq->checkImgNrLima = iLimaFrame + 1;
m_traceAcq->checkImgNrPco = pcoImgNr;
m_traceAcq->checkImgNrOrder = pcoImgNrOrder;
if (diff > pcoImgNrDiff)
{
pcoImgNrDiff = diff;
}
pcoImgNrLast = pcoImgNr;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void CheckImgNr::init(STC_traceAcq *traceAcq)
{
DEF_FNID;
m_traceAcq = traceAcq;
pcoImgNrDiff = 1;
alignmentShift = 0;
int err;
WORD wTimeStampMode;
m_cam->_pco_GetTimestampMode(wTimeStampMode, err);
bNoTimestamp = err || !wTimeStampMode;
checkImgNr = !bNoTimestamp;
m_traceAcq->checkImgNr = checkImgNr;
//printf("--- %s> checkImgNr[%d], err[%d], wTimeStampMode[%d]\n", fnId, checkImgNr, err, wTimeStampMode);
pcoImgNrLast = -1;
pcoImgNrOrder = 0;
int alignment;
m_cam->_pco_GetBitAlignment(alignment);
if (alignment == 0)
alignmentShift = (16 - m_cam->m_pcoData->stcPcoDescription.wDynResDESC);
else
alignmentShift = 0;
return;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//*************************************************************************
//#define TIMESTAMP_MODE_BINARY 1
//#define TIMESTAMP_MODE_BINARYANDASCII 2
//
//SYSTEMTIME st;
//int act_timestamp;
//int shift;
//
//if(camval.strImage.wBitAlignment==0)
// shift = (16-camval.strSensor.strDescription.wDynResDESC);
//else
// shift = 0;
//
//err=PCO_SetTimestampMode(hdriver,TIMESTAMP_MODE_BINARY); //Binary+ASCII
//
//grab image to adr
//
//time_from_timestamp(adr,shift,&st);
//act_timestamp=image_nr_from_timestamp(adr,shift);
//*************************************************************************
int CheckImgNr::_get_imageNr_from_imageTimestamp(void *buf, int shift)
{
DEF_FNID;
//printf("--- %s> [ENTRY]\n", fnId);
unsigned short *b;
unsigned short c;
int y;
int image_nr = 0;
if (bNoTimestamp) return -1;
b = (unsigned short *)(buf);
y = 100 * 100 * 100;
for (; y > 0; y /= 100)
{
c = *b >> shift;
image_nr += (((c & 0x00F0) >> 4) * 10 + (c & 0x000F)) * y;
b++;
}
return image_nr;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
#ifndef __linux__
int CheckImgNr::_get_time_from_imageTimestamp(void *buf, int shift, SYSTEMTIME *st)
{
unsigned short *b;
unsigned short c;
int x, us;
memset(st, 0, sizeof(SYSTEMTIME));
b = (unsigned short *)buf;
// counter
for (x = 0; x < 4; x++)
{
c = *(b + x) >> shift;
}
x = 4;
// year
c = *(b + x) >> shift;
st->wYear += (c >> 4) * 1000;
st->wYear += (c & 0x0F) * 100;
x++;
c = *(b + x) >> shift;
st->wYear += (c >> 4) * 10;
st->wYear += (c & 0x0F);
x++;
// month
c = *(b + x) >> shift;
st->wMonth += (c >> 4) * 10;
st->wMonth += (c & 0x0F);
x++;
// day
c = *(b + x) >> shift;
st->wDay += (c >> 4) * 10;
st->wDay += (c & 0x0F);
x++;
// hour
c = *(b + x) >> shift;
st->wHour += (c >> 4) * 10;
st->wHour += (c & 0x0F);
x++;
// min
c = *(b + x) >> shift;
st->wMinute += (c >> 4) * 10;
st->wMinute += (c & 0x0F);
x++;
// sec
c = *(b + x) >> shift;
st->wSecond += (c >> 4) * 10;
st->wSecond += (c & 0x0F);
x++;
// us
us = 0;
c = *(b + x) >> shift;
us += (c >> 4) * 100000;
us += (c & 0x0F) * 10000;
x++;
c = *(b + x) >> shift;
us += (c >> 4) * 1000;
us += (c & 0x0F) * 100;
x++;
c = *(b + x) >> shift;
us += (c >> 4) * 10;
us += (c & 0x0F);
x++;
st->wMilliseconds = us / 100;
return 0;
}
#endif
//=================================================================================================
//=================================================================================================
void Camera::_pco_GetAcqEnblSignalStatus(WORD &wAcquEnableState, int &error)
......@@ -537,7 +753,7 @@ int Camera::_pco_GetADCOperation(int &adc_working, int &adc_max)
DEB_MEMBER_FUNCT();
DEF_FNID;
int error;
int error = 0;
WORD wADCOperation;
adc_max =
......
......@@ -366,8 +366,10 @@ void Camera::getTraceAcq(std::string &o_sn)
ptr += __sprintfSExt(
ptr, ptrMax - ptr,
"* ... checkImgNr pco[%d] lima[%d] diff[%d] order[%d]\n",
m_pcoData->traceAcq.checkImgNrPco, m_pcoData->traceAcq.checkImgNrLima,
"* ... checkImgNr[%s] pco[%d] lima[%d] diff[%d] order[%d]\n",
m_pcoData->traceAcq.checkImgNr ? "true" : "false",
m_pcoData->traceAcq.checkImgNrPco,
m_pcoData->traceAcq.checkImgNrLima,
m_pcoData->traceAcq.checkImgNrPco - m_pcoData->traceAcq.checkImgNrLima,
m_pcoData->traceAcq.checkImgNrOrder);
......
This diff is collapsed.
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