Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
NomadSpecialModules
Commits
43f161b7
Commit
43f161b7
authored
May 21, 2019
by
d11
Browse files
no
parent
31c894b5
Changes
20
Expand all
Hide whitespace changes
Inline
Side-by-side
src/drivers/gigecam/photonics/BufferInformation.h
0 → 100644
View file @
43f161b7
#ifndef _BUFFER_INFORMATION_
#define _BUFFER_INFORMATION_
#include <thread>
#include <vector>
#include <mutex>
#include <list>
#define _GNULINUX
#include <bgapi2_genicam/bgapi2_genicam.hpp>
// structure which holds additional information
// transferred together with the camera buffer
// this structure should be adapted to needs of the application
struct
BufferInformation
{
BufferInformation
()
{
frameid
=
0
;
number_of_incomplete_images
=
0
;
resend_requests
=
0
;
resend_requests_single
=
0
;
resend_requests_range
=
0
;
}
// frame id of the camera buffer
bo_uint64
frameid
;
// statistic value, number of incomplete images
bo_uint64
number_of_incomplete_images
;
// statistic value, number of resend requests
bo_int64
resend_requests
;
// statistic value, number resend requests requesting a single data packet
bo_int64
resend_requests_single
;
// statistic value, number of resend requests requesting a bunch of data packet
bo_int64
resend_requests_range
;
};
#endif //_BUFFER_INFORMATION_
src/drivers/gigecam/photonics/CameraHandler.cpp
0 → 100644
View file @
43f161b7
This diff is collapsed.
Click to expand it.
src/drivers/gigecam/photonics/CameraHandler.h
0 → 100644
View file @
43f161b7
#pragma once
#include <thread>
#include <vector>
#include <mutex>
#include <list>
#define _GNULINUX
#include </usr/local/src/baumer/inc/bgapi2_genicam/bgapi2_genicam.hpp>
#include "../../../../../NomadSpecialModules/src/drivers/gigecam/photonics/DoubleBufferHandler.h"
// the class represents a BGAPI camera object and additional camera specific information
class
CCameraControl
{
public:
// this function activates the feature command
// the feature command use the ExposureTime feature of the camera
// the parameter passes the new exposure time to be written to the camera
void
StartFeatureCommandExposure
(
double
exposure_time
);
// this function activates the capture command
// the parameter passes the number of images to be captured
void
StartCaptureCommand
(
unsigned
int
images
);
// this function checks, if the capture command was activated
// in this case the capture command is automatically reset
bool
IsCommandCaptureActivated
();
// this function checks, if the feature command was activated
// in this case the feature command is automatically reset
bool
IsCommandExposureActivated
();
// this function writes the desired exposure time to the passed camera
bool
ExposureFeatureBGAPI
();
// this function makes all necessary preparations on the buffer management to be able to capture images with BGAPI
// it opens the data stream and creates the camera buffers
void
InitializeBGAPIBufferManagement
();
// this function clears the buffer management and
// deletes the camera buffers
void
DeinitializeBGAPIBufferManagement
();
// this function capture the desired number of images from the passed camera
// and store some additional information (BufferInformation struct)
bool
CaptureBGAPIImages
(
const
bool
*
abort_flag
,
unsigned
int
number_of_images
);
// this function starts the streaming for the passed camera
bool
StartStreamingBGAPI
();
// this function stops the streaming for the passed camera
void
StopStreamingBGAPI
();
// this function fill the BufferInformation struct
void
FillBufferInformation
(
BGAPI2
::
DataStream
*
datastream_pointer
,
BGAPI2
::
Buffer
*
buffer
);
// function to add a string with logging information to the logging string list
void
LoggingStringAdd
(
std
::
string
logging_message
);
// this function returns a logging string and remove this string from the logging string list
std
::
string
LoggingString
();
// function to check, if some logging information is available
bool
LoggingListEmpty
()
{
return
(
logging_list_
.
size
()
==
0
);
}
public:
// buffer exchange strategy (double buffer)
CDoubleBufferHandler
buffer_handler_
;
// BGAPI camera object
BGAPI2
::
Device
*
camera_pointer_
;
// a list to transfer massages, generated by the feature command
std
::
list
<
std
::
string
>
feature_command_message_list_
;
// a mutex to synchronize the access to feature_command_message_list_
std
::
mutex
feature_command_message_list_lock_
;
// a worker thread that captures images from BGAPI
std
::
thread
capture_thread_
;
// a worker thread that control camera features from BGAPI
std
::
thread
feature_thread_
;
// a flag which controls the capture command
bool
command_capture_
;
// a flag which shows if the capture command is active
bool
capture_active_
;
// number of images to capture
unsigned
int
number_of_images_
;
// number of currently captured images
unsigned
int
number_of_captured_images_
;
// number of incomplete images
unsigned
int
number_of_incomplete_images_
;
// a flag which controls the feature command
bool
command_feature_
;
// exposure time to be set
double
exposure_time_
;
private:
// mutex to synchronize the access to capture command flag of all cameras
std
::
mutex
capture_command_lock_
;
// mutex to synchronize the access to feature command flag of all cameras
std
::
mutex
feature_command_lock_
;
// a list which holds logging strings
std
::
list
<
std
::
string
>
logging_list_
;
// a mutex to synchronize the access to the logging list
std
::
mutex
logging_list_lock_
;
};
// the class encapsulate camera search, capture command and feature command
// it also implements the worker threads
class
CCameraHandler
{
// ----
// public functions which are used in the context of the main thread and application threads
// to control the main settings from the user application
// ----
public:
// construction / destruction
CCameraHandler
();
virtual
~
CCameraHandler
();
// this function starts the init thread to search for connected cameras
// it also passed the buffer handler
void
Start
(
CDoubleBufferHandler
buffer_handler
);
// close all connected cameras and frees all BGAPI resources
// this function doesn't run in a separate thread
void
Stop
();
// this function initialize the buffer management of all connected cameras
// it also creates the struct BufferInformation for every camera buffer
// all cameras use 10 buffers to store the image data
// the memory for the camera buffers will be allocated inside BGAPI
// the size of the memory to allocated will determined from the maximum image size
// this function also starts the worker threads
void
StartCameras
();
// this function stops the worker threads
// and deinitialize the BGAPI
void
StopCameras
();
// function to check for an initialisation error
bool
IsInitOK
();
// returns the number of connected cameras
size_t
NumberOfCameras
();
// this function returns the number of images taken by the camera that took the least number of images
unsigned
int
CapturedImages
();
// function to return the camera control vector
const
std
::
vector
<
CCameraControl
*>*
GetCameraControlVector
()
{
return
&
camera_control_
;
}
// this function returns a logging string and remove this string from the logging string list
std
::
string
LoggingString
();
// function to check, if some logging information is available
bool
LoggingListEmpty
()
{
return
(
logging_list_
.
size
()
==
0
);
}
// ----
// public functions which are partly used in the worker threads
// to handle and process the code regarding to main settings
// ----
public:
// this function initializes the Baumer GAPI SDK and
// searches for connected cameras
// all found cameras will be opened to work with
void
InitializeBGAPI
();
// this function deinitialises the Baumer GAPI SDK and
// close all connected cameras
void
DeinitializeBGAPI
();
// function to signal an initialisation error while start up
void
SetInitError
();
// function to add a string with logging information to the logging string list
void
LoggingStringAdd
(
std
::
string
logging_message
);
// this function adds a camera object to the camera control vector
void
AddCamera
(
BGAPI2
::
Device
*
camera_pointer
);
// this function set a flag to signal the worker thread to exit
const
bool
*
FinishWorkerThreads
()
{
return
&
finish_worker_threads_
;
}
private:
// pointer to the buffer handler
CDoubleBufferHandler
buffer_handler_
;
// flag to signal the worker threads to exit themselves
bool
finish_worker_threads_
;
// initialisation thread
std
::
thread
init_thread
;
// camera control vector holds information regarding synchronisation and
// the BGAPI camera object
std
::
vector
<
CCameraControl
*>
camera_control_
;
// flag is set for initialisation errors
bool
init_ok_
;
// a list which holds logging strings
std
::
list
<
std
::
string
>
logging_list_
;
// a mutex to synchronize the access to the logging list
std
::
mutex
logging_list_lock_
;
};
src/drivers/gigecam/photonics/DoubleBufferHandler.cpp
0 → 100644
View file @
43f161b7
#include "../../../../../NomadSpecialModules/src/drivers/gigecam/photonics/DoubleBufferHandler.h"
#include <iostream>
#include <sstream>
#include "../../../../../NomadSpecialModules/src/drivers/gigecam/photonics/BufferInformation.h"
CDoubleBufferHandler
::
CDoubleBufferHandler
()
:
buffer_read_
(
nullptr
)
,
buffer_write_
(
nullptr
)
,
new_data
(
false
)
{
}
CDoubleBufferHandler
::~
CDoubleBufferHandler
()
{
}
void
CDoubleBufferHandler
::
PushBuffer
(
BGAPI2
::
Buffer
*
buffer
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
buffer_exchange_lock_
);
if
(
!
buffer_write_
)
{
buffer_write_
=
buffer
;
new_data
=
true
;
}
else
{
buffer
->
QueueBuffer
();
}
}
BGAPI2
::
Buffer
*
CDoubleBufferHandler
::
PullBuffer
()
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
buffer_exchange_lock_
);
if
(
buffer_write_
)
{
if
(
buffer_read_
)
{
buffer_read_
->
QueueBuffer
();
}
buffer_read_
=
buffer_write_
;
buffer_write_
=
nullptr
;
new_data
=
false
;
}
return
buffer_read_
;
}
void
CDoubleBufferHandler
::
FreeBuffer
(
BGAPI2
::
Buffer
*
buffer
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
buffer_exchange_lock_
);
if
(
buffer_read_
&&
buffer_write_
)
{
buffer_read_
->
QueueBuffer
();
buffer_read_
=
nullptr
;
}
}
void
CDoubleBufferHandler
::
Init
()
{
if
(
buffer_write_
)
{
buffer_write_
->
QueueBuffer
();
buffer_write_
=
nullptr
;
}
if
(
buffer_read_
)
{
buffer_read_
->
QueueBuffer
();
buffer_read_
=
nullptr
;
}
new_data
=
false
;
}
bool
CDoubleBufferHandler
::
HasNewData
()
{
return
new_data
;
}
CDoubleBufferHandler
::
CDoubleBufferHandler
(
const
CDoubleBufferHandler
&
instance
)
{
buffer_read_
=
instance
.
buffer_read_
;
buffer_write_
=
instance
.
buffer_write_
;
}
CDoubleBufferHandler
&
CDoubleBufferHandler
::
operator
=
(
const
CDoubleBufferHandler
&
instance
)
{
buffer_read_
=
instance
.
buffer_read_
;
buffer_write_
=
instance
.
buffer_write_
;
return
*
this
;
}
src/drivers/gigecam/photonics/DoubleBufferHandler.h
0 → 100644
View file @
43f161b7
#pragma once
#include <thread>
#include <vector>
#include <mutex>
#include <list>
#define _GNULINUX
#include </usr/local/src/baumer/inc/bgapi2_genicam/bgapi2_genicam.hpp>
class
CDoubleBufferHandler
{
public:
CDoubleBufferHandler
();
CDoubleBufferHandler
(
const
CDoubleBufferHandler
&
instance
);
virtual
~
CDoubleBufferHandler
();
virtual
void
PushBuffer
(
BGAPI2
::
Buffer
*
buffer
);
virtual
BGAPI2
::
Buffer
*
PullBuffer
();
virtual
void
FreeBuffer
(
BGAPI2
::
Buffer
*
buffer
);
virtual
void
Init
();
virtual
bool
HasNewData
();
CDoubleBufferHandler
&
operator
=
(
const
CDoubleBufferHandler
&
instance
);
private:
BGAPI2
::
Buffer
*
buffer_read_
;
BGAPI2
::
Buffer
*
buffer_write_
;
std
::
mutex
buffer_exchange_lock_
;
bool
new_data
;
};
src/drivers/gigecam/photonics/Module.xml
0 → 100644
View file @
43f161b7
<module
name=
"photonics"
>
<driver
class=
"photonics::PhotonicsDriver"
/>
<link
path=
"/usr/local/lib/baumer"
lib=
"bgapi2_genicam"
/>
<link
lib=
"opencv_core"
/>
<link
lib=
"opencv_calib3d"
/>
<link
lib=
"opencv_highgui"
/>
<include
path=
"/usr/local/src/baumer/inc"
/>
<include
path=
"$(NOMAD_HOME)/../NomadModules/src"
/>
</module>
src/drivers/gigecam/photonics/PerfectPhotonicsDriver.cpp
0 → 100644
View file @
43f161b7
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "../../../../../NomadSpecialModules/src/drivers/gigecam/photonics/PerfectPhotonicsDriver.h"
#include <stdlib.h>
#include "../../../../../NomadSpecialModules/src/drivers/gigecam/photonics/PhotonicsDef.h"
#include "../../../../../NomadSpecialModules/src/drivers/gigecam/photonics/PhotonicsDriver.h"
namespace
photonics
{
/*
* Constructor
*/
PerfectPhotonicsDriver
::
PerfectPhotonicsDriver
(
PhotonicsDriver
*
owner
)
:
PhotonicsState
(
owner
)
{
/* Empty */
}
/*
* Destructor
*/
PerfectPhotonicsDriver
::~
PerfectPhotonicsDriver
()
{
/* Empty */
}
void
PerfectPhotonicsDriver
::
init
()
{
}
/*
* clearvme/daugther/Photonics
*/
void
PerfectPhotonicsDriver
::
clear
()
{
// Read command
owner
()
->
time
=
0
;
owner
()
->
counts
=
0
;
owner
()
->
counts2
=
0
;
owner
()
->
counts3
=
0
;
}
/*
* writeParam
*/
void
PerfectPhotonicsDriver
::
writeParam
()
{
}
/*
* synchroniseRead
*/
void
PerfectPhotonicsDriver
::
synchroniseRead
()
{
read
();
owner
()
->
m_SynchroniseReadTerminated
=
true
;
}
//
///*
// * regroup
// */
//void PerfectPhotonicsDriver::regroup() {
// std::cout << owner()->xSize() << std::endl;
// std::cout << owner()->ySize() << std::endl;
//}
/*
* read
*/
void
PerfectPhotonicsDriver
::
read
()
{
// Read command
int32
size
=
owner
()
->
dataSize
();
int32
*
tab
=
owner
()
->
data
();
int32
sum
=
0
;
// if (m_FirstRead) {
// for (uint32 i=0;i<size;i++) {
// tab[i] = i + 1;
// sum = sum + tab[i];
// }
// m_FirstRead = false;
// } else {
// for (uint32 i=0;i<size;i++) {
// tab[i] = tab[i] + 1;
// sum = sum + tab[i];
// }
// }
for
(
int32
i
=
0
;
i
<
size
;
i
++
)
{
tab
[
i
]
=
i
;
sum
=
sum
+
tab
[
i
];
}
owner
()
->
sum
=
sum
;
owner
()
->
data
.
sendEvent
();
}
/*
* pause
*/
void
PerfectPhotonicsDriver
::
pause
()
{
}
/*
* continue
*/
void
PerfectPhotonicsDriver
::
resume
()
{
}
/*
* start
*/
void
PerfectPhotonicsDriver
::
start
()
{
owner
()
->
time
=
owner
()
->
time
.
setpoint
();
}
/*
* stop
*/
void
PerfectPhotonicsDriver
::
stop
()
{
}
/*
* readStatus
*/
void
PerfectPhotonicsDriver
::
readStatus
()
{
owner
()
->
startActivated
=
false
;
// Status command
owner
()
->
computeGateStatus
(
photonics
::
READOUT_COMPLETE
);
owner
()
->
computeAcquisitionStatus
(
0
);
owner
()
->
computeDetectorStatus
(
0
);
if
(
owner
()
->
m_SynchroniseReadActivated
==
true
)
{
if
(
owner
()
->
m_SynchroniseReadTerminated
==
true
)
{
owner
()
->
m_SynchroniseReadActivated
=
false
;
owner
()
->
m_SynchroniseReadTerminated
=
false
;
owner
()
->
commandProgression
=
PROGRESSION_END_DEVICE_CONTAINER
;
}
}
else
{
owner
()
->
commandProgression
=
PROGRESSION_END_DEVICE_CONTAINER
;
}
}
/*
* readInfos
*/
void
PerfectPhotonicsDriver
::
readInfos
()
{
}
}
src/drivers/gigecam/photonics/PerfectPhotonicsDriver.h
0 → 100644
View file @
43f161b7
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef PERFECTPHOTONICSDRIVER_H
#define PERFECTPHOTONICSDRIVER_H
#include "../../../../../NomadSpecialModules/src/drivers/gigecam/photonics/PhotonicsState.h"
namespace
photonics
{
/*!
* \class PerfectPhotonicsDriver
* \brief Perfect implementation class for the Photonics device driver
*
* This class is a perfect implementation of Photonics device driver.
* On start command, all actual values become target's ones.
*/
class
PerfectPhotonicsDriver
:
public
PhotonicsState
{
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
PerfectPhotonicsDriver
(
PhotonicsDriver
*
owner
);
/*!
* \brief Destructor
*/
virtual
~
PerfectPhotonicsDriver
();
/*!
* \brief Init command implementation
*/
virtual
void
init
();
/*!
* \brief Clear command implementation
*/
virtual
void
clear
();
/*!
* \brief Write Param command implementation
*/
virtual
void
writeParam
();
/*!
* \brief Read command implementation
*/
virtual
void
read
();
/*!
* \brief Synchronize Read command implementation
*/
virtual
void
synchroniseRead
();
/*!
* \brief Start command implementation
*/
virtual
void
start
();
/*!
* \brief Resume command implementation
*/
virtual
void
resume
();
/*!
* \brief Pause command implementation
*/
virtual
void
pause
();
/*!
* \brief Stop command implementation
*/
virtual
void
stop
();
/*!
* \brief Read Infos command implementation
*/
virtual
void
readStatus
();
/*!
* \brief Read Infos command implementation
*/