Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LimaGroup
Lima-camera-eiger
Commits
39fb4b84
Commit
39fb4b84
authored
Feb 11, 2020
by
Alejandro Homs Puron
Browse files
Improve formalization of CameraRequets for better error handling
parent
074418c8
Changes
5
Hide whitespace changes
Inline
Side-by-side
include/EigerCamera.h
View file @
39fb4b84
...
...
@@ -97,8 +97,8 @@ class LIBEIGER Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGe
void
setLatTime
(
double
lat_time
);
void
getLatTime
(
double
&
lat_time
);
void
getExposureTimeRange
(
double
&
min_expo
,
double
&
max_expo
)
const
;
void
getLatTimeRange
(
double
&
min_lat
,
double
&
max_lat
)
const
;
void
getExposureTimeRange
(
double
&
min_expo
,
double
&
max_expo
);
void
getLatTimeRange
(
double
&
min_lat
,
double
&
max_lat
);
void
setNbFrames
(
int
nb_frames
);
void
getNbFrames
(
int
&
nb_frames
);
...
...
@@ -161,6 +161,7 @@ class LIBEIGER Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGe
friend
class
SavingCtrlObj
;
friend
class
Stream
;
friend
class
MultiParamRequest
;
friend
class
CameraRequest
;
enum
InternalStatus
{
IDLE
,
RUNNING
,
ERROR
};
class
TriggerCallback
;
...
...
@@ -181,16 +182,6 @@ class LIBEIGER Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGe
void
newFrameAcquired
();
bool
allFramesAcquired
();
template
<
typename
C
>
void
_sendCommand
(
C
cmd
,
DebObj
*
deb_ptr
);
template
<
typename
P
,
typename
T
>
void
_setParam
(
P
param
,
T
value
,
DebObj
*
deb_ptr
);
template
<
typename
P
,
typename
T
>
void
_getParam
(
P
param
,
T
&
value
,
DebObj
*
deb_ptr
);
template
<
typename
R
>
void
_startTransfer
(
std
::
string
src_file_name
,
std
::
string
dest_path
,
AutoMutex
&
lock
,
R
&
req
,
DebObj
*
deb_ptr
);
template
<
typename
T
>
struct
Cache
{
...
...
sip/EigerCamera.sip
View file @
39fb4b84
...
...
@@ -62,8 +62,8 @@ namespace Eiger
void setLatTime(double lat_time);
void getLatTime(double& lat_time /Out/);
void getExposureTimeRange(double& min_expo /Out/, double& max_expo /Out/)
const
;
void getLatTimeRange(double& min_lat /Out/, double& max_lat /Out/)
const
;
void getExposureTimeRange(double& min_expo /Out/, double& max_expo /Out/);
void getLatTimeRange(double& min_lat /Out/, double& max_lat /Out/);
void setNbFrames(int nb_frames);
void getNbFrames(int& nb_frames /Out/);
...
...
src/EigerCamera.cpp
View file @
39fb4b84
...
...
@@ -38,6 +38,9 @@ using namespace eigerapi;
#define sendCommand(cmd) \
sendEigerCommand(*this, cmd)
#define sendCommandTimeout(cmd, timeout) \
sendEigerCommandTimeout(*this, cmd, timeout)
#define setParam(param, value) \
setEigerParam(*this, param, value)
...
...
@@ -110,18 +113,15 @@ Camera::Camera(const std::string& detector_ip, ///< [in] Ip address of the dete
DEB_CONSTRUCTOR
();
DEB_PARAM
()
<<
DEB_VAR1
(
detector_ip
);
// Init EigerAPI
try
{
_synchronize
();
}
catch
(
Exception
&
e
)
{
DEB_ALWAYS
()
<<
"Could not get configuration parameters, try to initialize"
;
initialize
();
AutoMutex
lock
(
m_cond
.
mutex
());
while
(
m_initialize_state
==
RUNNING
)
m_cond
.
wait
();
}
try
{
_synchronize
();
}
catch
(
Exception
&
e
)
{
DEB_ALWAYS
()
<<
"Could not get configuration parameters, try to initialize"
;
initialize
();
AutoMutex
lock
(
m_cond
.
mutex
());
while
(
m_initialize_state
==
RUNNING
)
m_cond
.
wait
();
}
// Display max image size
DEB_TRACE
()
<<
"Detector max width: "
<<
m_maxImageWidth
;
...
...
@@ -175,7 +175,7 @@ void Camera::_initialization_finished(bool ok)
DEB_ALWAYS
()
<<
"Synchronizing with detector ..."
;
_synchronize
();
DEB_ALWAYS
()
<<
"Done!"
;
}
catch
(
const
lima
::
Exception
&
e
)
{
}
catch
(
const
Exception
&
e
)
{
ok
=
false
;
}
}
...
...
@@ -231,19 +231,14 @@ void Camera::prepareAcq()
DEB_TRACE
()
<<
"Arm start"
;
double
timeout
=
5
*
60.
;
// 5 min timeout
CommandReq
arm_cmd
=
m_requests
->
get_command
(
Requests
::
ARM
);
try
{
arm_cmd
->
wait
(
timeout
);
DEB_TRACE
()
<<
"Arm end"
;
m_serie_id
=
arm_cmd
->
get_serie_id
();
m_armed
=
true
;
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
m_requests
->
cancel
(
arm_cmd
);
HANDLE_EIGERERROR
(
arm_cmd
,
e
);
}
CommandReq
arm_cmd
=
sendCommandTimeout
(
Requests
::
ARM
,
timeout
);
DEB_TRACE
()
<<
"Arm end"
;
m_armed
=
true
;
try
{
m_serie_id
=
arm_cmd
->
get_serie_id
();
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
HANDLE_EIGERERROR
(
arm_cmd
,
e
);
}
m_frames_triggered
=
m_frames_acquired
=
0
;
}
...
...
@@ -306,14 +301,12 @@ void Camera::getDetectorImageSize(Size& size) ///< [out] image dimensions
{
DEB_MEMBER_FUNCT
();
ParamReq
width_request
=
m_requests
->
get_param
(
Requests
::
DETECTOR_WITDH
);
ParamReq
height_request
=
m_requests
->
get_param
(
Requests
::
DETECTOR_HEIGHT
);
Requests
::
Param
::
Value
width
=
width_request
->
get
();
Requests
::
Param
::
Value
height
=
height_request
->
get
();
size
=
Size
(
width
.
data
.
int_val
,
height
.
data
.
int_val
);
MultiParamRequest
synchro
(
*
this
);
unsigned
int
width
,
height
;
synchro
.
addGet
(
Requests
::
DETECTOR_WITDH
,
width
);
synchro
.
addGet
(
Requests
::
DETECTOR_HEIGHT
,
height
);
synchro
.
wait
();
size
=
Size
(
width
,
height
);
}
...
...
@@ -483,30 +476,19 @@ void Camera::getLatTime(double& lat_time) ///< [out] current latency time
//-----------------------------------------------------------------------------
void
Camera
::
getExposureTimeRange
(
double
&
min_expo
,
///< [out] minimum exposure time
double
&
max_expo
)
///< [out] maximum exposure time
const
{
DEB_MEMBER_FUNCT
();
ParamReq
exp_time
=
m_requests
->
get_param
(
Requests
::
EXPOSURE
);
try
{
exp_time
->
wait
();
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
m_requests
->
cancel
(
exp_time
);
HANDLE_EIGERERROR
(
exp_time
,
e
);
}
Requests
::
Param
::
Value
min_val
=
exp_time
->
get_min
();
Requests
::
Param
::
Value
max_val
;
if
(
m_api
==
Eiger1
)
max_val
=
exp_time
->
get_max
();
else
max_val
.
data
.
double_val
=
1800
;
min_expo
=
min_val
.
data
.
double_val
;
max_expo
=
max_val
.
data
.
double_val
;
double
curr_expo
;
ParamReq
exp_time
=
getParam
(
Requests
::
EXPOSURE
,
curr_expo
);
try
{
min_expo
=
exp_time
->
get_min
().
data
.
double_val
;
if
(
m_api
==
Eiger1
)
max_expo
=
exp_time
->
get_max
().
data
.
double_val
;
else
max_expo
=
1800
;
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
HANDLE_EIGERERROR
(
exp_time
,
e
);
}
DEB_RETURN
()
<<
DEB_VAR2
(
min_expo
,
max_expo
);
}
...
...
@@ -516,7 +498,6 @@ const
//-----------------------------------------------------------------------------
void
Camera
::
getLatTimeRange
(
double
&
min_lat
,
///< [out] minimum latency
double
&
max_lat
)
///< [out] maximum latency
const
{
DEB_MEMBER_FUNCT
();
...
...
@@ -710,9 +691,14 @@ void Camera::_synchronize()
else
THROW_HW_ERROR
(
InvalidValue
)
<<
"Unexpected trigger mode: "
<<
DEB_VAR1
(
trig_name
);
Requests
::
Param
::
Value
min_frame_time
=
synchro
[
Requests
::
FRAME_TIME
]
->
get_min
();
m_min_frame_time
=
min_frame_time
.
data
.
double_val
;
Requests
::
PARAM_NAME
param
;
try
{
param
=
Requests
::
FRAME_TIME
;
m_min_frame_time
=
synchro
[
param
]
->
get_min
().
data
.
double_val
;
}
catch
(
const
EigerException
&
e
)
{
HANDLE_EIGERERROR
(
synchro
[
param
],
e
);
}
if
(
compression_type
==
"none"
)
m_compression_type
=
NoCompression
;
...
...
@@ -1113,9 +1099,14 @@ void Camera::setCompressionType(Camera::CompressionType type)
}
DEB_TRACE
()
<<
DEB_VAR1
(
s
);
ParamReq
type_req
=
m_requests
->
get_param
(
Requests
::
COMPRESSION_TYPE
);
Requests
::
Param
::
Value
types_allowed
=
type_req
->
get_allowed_values
();
std
::
string
type_str
;
ParamReq
type_req
=
getParam
(
Requests
::
COMPRESSION_TYPE
,
type_str
);
Requests
::
Param
::
Value
types_allowed
;
try
{
types_allowed
=
type_req
->
get_allowed_values
();
}
catch
(
const
EigerException
&
e
)
{
HANDLE_EIGERERROR
(
type_req
,
e
);
}
const
vector
<
string
>&
l
=
types_allowed
.
string_array
;
if
(
DEB_CHECK_ANY
(
DebTypeTrace
))
{
DEB_TRACE
()
<<
"allowed compression types:"
;
...
...
src/EigerCameraRequests.h
View file @
39fb4b84
...
...
@@ -44,76 +44,91 @@ typedef eigerapi::CurlLoop::FutureRequest::CallbackPtr CallbackPtr;
/*----------------------------------------------------------------------------
class Camera request helpers
----------------------------------------------------------------------------*/
template
<
typename
C
>
void
Camera
::
_sendCommand
(
C
cmd
,
DebObj
*
deb_ptr
)
class
CameraRequest
{
DEB_FROM_PTR
(
deb_ptr
);
CommandReq
req
=
m_requests
->
get_command
(
cmd
);
try
{
req
->
wait
();
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
m_requests
->
cancel
(
req
);
HANDLE_EIGERERROR
(
req
,
e
);
public:
CameraRequest
(
Camera
&
cam
)
:
m_cam
(
cam
),
m_requests
(
m_cam
.
m_requests
)
{}
CommandReq
doSendCommandTimeout
(
eigerapi
::
Requests
::
COMMAND_NAME
cmd
,
double
timeout
,
DebObj
*
deb_ptr
)
{
DEB_FROM_PTR
(
deb_ptr
);
CommandReq
req
=
m_requests
->
get_command
(
cmd
);
try
{
req
->
wait
(
timeout
);
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
m_requests
->
cancel
(
req
);
HANDLE_EIGERERROR
(
req
,
e
);
}
return
req
;
}
}
template
<
typename
P
,
typename
T
>
void
Camera
::
_setParam
(
P
param
,
T
value
,
DebObj
*
deb_ptr
)
{
DEB_FROM_PTR
(
deb_ptr
);
ParamReq
req
=
m_requests
->
set_param
(
param
,
value
);
try
{
req
->
wait
();
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
HANDLE_EIGERERROR
(
req
,
e
);
template
<
typename
T
>
ParamReq
doSetParam
(
eigerapi
::
Requests
::
PARAM_NAME
param
,
T
value
,
DebObj
*
deb_ptr
)
{
DEB_FROM_PTR
(
deb_ptr
);
ParamReq
req
=
m_requests
->
set_param
(
param
,
value
);
try
{
req
->
wait
();
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
HANDLE_EIGERERROR
(
req
,
e
);
}
return
req
;
}
}
template
<
typename
P
,
typename
T
>
void
Camera
::
_getParam
(
P
param
,
T
&
value
,
DebObj
*
deb_ptr
)
{
DEB_FROM_PTR
(
deb_ptr
);
ParamReq
req
=
m_requests
->
get_param
(
param
,
value
);
try
{
req
->
wait
();
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
m_requests
->
cancel
(
req
);
HANDLE_EIGERERROR
(
req
,
e
);
template
<
typename
T
>
ParamReq
doGetParam
(
eigerapi
::
Requests
::
PARAM_NAME
param
,
T
&
value
,
DebObj
*
deb_ptr
)
{
DEB_FROM_PTR
(
deb_ptr
);
ParamReq
req
=
m_requests
->
get_param
(
param
,
value
);
try
{
req
->
wait
();
}
catch
(
const
eigerapi
::
EigerException
&
e
)
{
m_requests
->
cancel
(
req
);
HANDLE_EIGERERROR
(
req
,
e
);
}
return
req
;
}
}
template
<
typename
R
>
void
Camera
::
_startTransfer
(
std
::
string
src_file_name
,
std
::
string
dest_path
,
AutoMutex
&
lock
,
R
&
req
,
DebObj
*
deb_ptr
)
{
DEB_FROM_PTR
(
deb_ptr
);
try
{
req
=
m_requests
->
start_transfer
(
src_file_name
,
dest_path
);
}
catch
(
eigerapi
::
EigerException
&
e
)
{
Event
*
event
=
new
Event
(
Hardware
,
Event
::
Error
,
Event
::
Saving
,
Event
::
SaveOpenError
,
e
.
what
());
AutoMutexUnlock
u
(
lock
);
reportEvent
(
event
);
req
.
reset
();
TransferReq
doStartTransfer
(
std
::
string
src_file_name
,
std
::
string
dest_path
,
AutoMutex
&
lock
,
DebObj
*
deb_ptr
)
{
DEB_FROM_PTR
(
deb_ptr
);
TransferReq
req
;
try
{
req
=
m_requests
->
start_transfer
(
src_file_name
,
dest_path
);
}
catch
(
eigerapi
::
EigerException
&
e
)
{
Event
*
event
=
new
Event
(
Hardware
,
Event
::
Error
,
Event
::
Saving
,
Event
::
SaveOpenError
,
e
.
what
());
AutoMutexUnlock
u
(
lock
);
m_cam
.
reportEvent
(
event
);
req
.
reset
();
}
return
req
;
}
}
public:
Camera
&
m_cam
;
eigerapi
::
Requests
*
m_requests
;
};
#define sendEigerCommand(cam, cmd) \
sendEigerCommandTimeout(cam, cmd, eigerapi::CurlLoop::FutureRequest::TIMEOUT)
#define sendEigerCommand(cam, cmd)
\
(cam).
_s
endCommand
(cmd
, DEB_PTR())
#define sendEigerCommand
Timeout
(cam, cmd
, timeout
) \
CameraRequest
(cam).
doS
endCommand
Timeout(cmd, timeout
, DEB_PTR())
#define setEigerParam(cam, param, value) \
(cam).
_s
etParam(param, value, DEB_PTR())
#define setEigerParam(cam, param, value)
\
CameraRequest
(cam).
doS
etParam(param, value, DEB_PTR())
#define getEigerParam(cam, param, value) \
(cam).
_g
etParam(param, value, DEB_PTR())
#define getEigerParam(cam, param, value)
\
CameraRequest
(cam).
doG
etParam(param, value, DEB_PTR())
#define startEigerTransfer(cam, src_file_name, dest_path, lock
, req
) \
(cam).
_s
tartTransfer(src_file_name, dest_path, lock,
req,
DEB_PTR())
#define startEigerTransfer(cam, src_file_name, dest_path, lock)
\
CameraRequest
(cam).
doS
tartTransfer(src_file_name, dest_path, lock, DEB_PTR())
/*----------------------------------------------------------------------------
...
...
src/EigerSavingCtrlObj.cpp
View file @
39fb4b84
...
...
@@ -306,8 +306,9 @@ void SavingCtrlObj::_PollingThread::threadFunction()
std
::
string
master_file_name
=
prefix
+
"_master.h5"
;
std
::
string
dest_path
=
directory
+
"/"
+
master_file_name
;
TransferReq
master_file_req
;
startEigerTransfer
(
m_saving
.
m_cam
,
src_file_name
.
str
(),
dest_path
,
lock
,
master_file_req
);
master_file_req
=
startEigerTransfer
(
m_saving
.
m_cam
,
src_file_name
.
str
(),
dest_path
,
lock
);
if
(
!
master_file_req
)
{
// stop the loop
m_saving
.
m_nb_file_to_watch
=
m_saving
.
m_nb_file_transfer_started
=
0
;
...
...
@@ -360,8 +361,9 @@ void SavingCtrlObj::_PollingThread::threadFunction()
DEB_TRACE
()
<<
"Start transfer file: "
<<
DEB_VAR1
(
*
file_name
);
std
::
string
dest_path
=
directory
+
"/"
+
src_file_name
.
str
();
TransferReq
file_req
;
startEigerTransfer
(
m_saving
.
m_cam
,
src_file_name
.
str
(),
dest_path
,
lock
,
file_req
);
file_req
=
startEigerTransfer
(
m_saving
.
m_cam
,
src_file_name
.
str
(),
dest_path
,
lock
);
if
(
!
file_req
)
{
// stop the loop
m_saving
.
m_nb_file_to_watch
=
m_saving
.
m_nb_file_transfer_started
=
0
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment