Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
NomadSpecialModules
Commits
acb56f65
Commit
acb56f65
authored
Oct 15, 2019
by
yannick legoc
Browse files
Updated DielectricsRemoteWindeta with the sync mode
parent
40339dc9
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/controllers/remotedielectricswindeta/DielectricsRemoteWindeta.cpp
View file @
acb56f65
...
...
@@ -23,6 +23,7 @@
#include
<common/base/FileUtilities.h>
#include
"controllers/common/family/Families.h"
#include
"InstrumentManager/InstrumentManager.h"
#include
"controllers/common/acquisition/Count.h"
#include
"controllers/common/acquisition/ExperimentData.h"
#include
<boost/filesystem/operations.hpp>
#include
<thread>
...
...
@@ -45,9 +46,11 @@ const std::string RemoteWindeta::INDEPENDENT_PREFIX = "windeta-";
const
std
::
string
RemoteWindeta
::
INDEPENDENT_VALUE
=
"independent"
;
const
std
::
string
RemoteWindeta
::
NUMOR_VALUE
=
"numor"
;
const
std
::
string
RemoteWindeta
::
NUMOR_1_VALUE
=
"numor+1"
;
const
std
::
string
RemoteWindeta
::
COUNT_SYNC_VALUE
=
"sync"
;
RemoteWindeta
::
RemoteWindeta
(
const
std
::
string
&
name
)
:
ExperimentController
(
name
),
controller
::
Stoppable
(
this
),
controller
::
Init
(
this
),
controller
::
Raz
(
this
),
Test
(
this
),
m_independentDataFileId
(
0
),
m_stopped
(
false
)
{
ExperimentController
(
name
),
controller
::
Stoppable
(
this
),
controller
::
Init
(
this
),
controller
::
Raz
(
this
),
Test
(
this
),
m_independentDataFileId
(
0
),
m_countNumor
(
0
),
m_stopped
(
false
)
{
setFamily
(
family
::
ACQUISITION
,
family
::
POLARIZATIONS
);
...
...
@@ -63,17 +66,19 @@ RemoteWindeta::RemoteWindeta(const std::string& name) :
dataFilenameFormatSize
.
init
(
this
,
NOSAVE
,
"data_filename_format_size"
);
dataFilenameFormatValues
.
init
(
this
,
NOSAVE
,
"data_filename_format_values"
);
dataFilenameFormatLabels
.
init
(
this
,
NOSAVE
,
"data_filename_format_labels"
);
dataFilenameFormatSize
=
3
;
dataFilenameFormatSize
=
4
;
dataFilenameFormatValues
.
resize
(
dataFilenameFormatSize
());
dataFilenameFormatValues
.
set
(
0
,
NUMOR_VALUE
);
dataFilenameFormatValues
.
set
(
1
,
NUMOR_1_VALUE
);
dataFilenameFormatValues
.
set
(
2
,
INDEPENDENT_VALUE
);
dataFilenameFormatValues
.
set
(
3
,
COUNT_SYNC_VALUE
);
dataFilenameFormatLabels
.
resize
(
dataFilenameFormatSize
());
dataFilenameFormatLabels
.
set
(
0
,
"Numor"
);
dataFilenameFormatLabels
.
set
(
1
,
"Numor+1"
);
dataFilenameFormatLabels
.
set
(
2
,
"Independent"
);
dataFilenameFormatLabels
.
set
(
3
,
"Sync"
);
dataFilenameFormat
.
setEnumeratedValues
(
dataFilenameFormatValues
);
dataFilenameFormat
.
setEnumeratedLabels
(
dataFilenameFormatLabels
);
...
...
@@ -82,13 +87,15 @@ RemoteWindeta::RemoteWindeta(const std::string& name) :
presetsSize
.
init
(
this
,
NOSAVE
,
"presets_size"
);
presets
.
init
(
this
,
NOSAVE
,
"presets"
);
m_CountSpy
.
init
(
this
,
"acquisition_spy"
);
m_driver
.
init
(
this
,
"driver"
);
initIndependentDataFileId
();
}
RemoteWindeta
::
RemoteWindeta
(
const
RemoteWindeta
&
controller
)
:
ExperimentController
(
controller
),
controller
::
Stoppable
(
this
),
controller
::
Init
(
this
),
controller
::
Raz
(
this
),
Test
(
this
),
m_independentDataFileId
(
0
),
m_stopped
(
false
)
{
ExperimentController
(
controller
),
controller
::
Stoppable
(
this
),
controller
::
Init
(
this
),
controller
::
Raz
(
this
),
Test
(
this
),
m_independentDataFileId
(
0
),
m_countNumor
(
0
),
m_stopped
(
false
)
{
}
RemoteWindeta
::~
RemoteWindeta
()
{
...
...
@@ -97,6 +104,8 @@ RemoteWindeta::~RemoteWindeta() {
void
RemoteWindeta
::
postConfiguration
()
{
registerUpdater
(
m_CountSpy
->
statusMessage
,
&
RemoteWindeta
::
updateStatusMessage
,
this
);
if
(
m_server
.
get
()
==
nullptr
)
{
// Create a new server if it is not already created.
// In case of a simulated server, avoid the real remote endpoint.
...
...
@@ -117,7 +126,6 @@ void RemoteWindeta::postConfiguration() {
void
RemoteWindeta
::
setEnabled
(
bool
all
,
bool
postconf
)
{
ExperimentController
::
setEnabled
(
all
);
}
void
RemoteWindeta
::
setDisabled
(
bool
all
)
{
...
...
@@ -176,7 +184,7 @@ bool RemoteWindeta::initApplication() {
m_subscriber
=
application
::
Subscriber
::
create
(
*
m_windetaApplication
,
PUBLISHER_NAME
);
// Start the subscriber loop
m_subscriberThread
.
reset
(
new
boo
st
::
thread
(
boo
st
::
bind
(
&
RemoteWindeta
::
subscriberLoop
,
this
)));
m_subscriberThread
.
reset
(
new
st
d
::
thread
(
st
d
::
bind
(
&
RemoteWindeta
::
subscriberLoop
,
this
)));
// Application initialized.
initialized
=
true
;
...
...
@@ -207,8 +215,6 @@ void RemoteWindeta::initPresets() {
// Send the message.
m_requester
->
sendTwoBinaryParts
(
requestType
.
SerializeAsString
(),
""
);
cout
<<
getName
()
<<
" sent request "
<<
static_cast
<
int
>
(
requestType
.
type
())
<<
endl
;
// Wait for the response synchronously.
// Note that responses can be processed asynchronously if the server is able to.
string
data
;
...
...
@@ -216,8 +222,6 @@ void RemoteWindeta::initPresets() {
windeta
::
Response
response
;
response
.
ParseFromString
(
data
);
cout
<<
"received response "
<<
response
.
errorcode
()
<<
endl
;
}
void
RemoteWindeta
::
init
()
{
...
...
@@ -247,12 +251,21 @@ void RemoteWindeta::reset() {
}
}
void
RemoteWindeta
::
updateStatusMessage
()
{
if
(
m_CountSpy
->
statusMessage
()
==
acquisition
::
Count
::
COUNTING_MESSAGE
)
{
m_countNumor
=
m_CountSpy
->
numor
();
}
}
void
RemoteWindeta
::
start
()
{
if
(
!
initApplication
())
{
return
;
}
commandStatus
.
setIdle
();
// Check initial status.
if
(
commandStatus
.
isRunning
())
{
log
(
Level
::
s_Error
)
<<
name
<<
"cannot start because it is already running"
<<
endlog
;
...
...
@@ -261,6 +274,32 @@ void RemoteWindeta::start() {
log
(
Level
::
s_Debug
)
<<
name
<<
cursor
<<
"preset "
<<
preset
()
<<
endlog
;
int
timeout
=
startTimeout
();
int
i
=
0
;
m_stopped
=
false
;
m_countNumor
=
0
;
// Wait for the count to have changed the numor so that we can use it in case of sync.
if
(
dataFilenameFormat
()
==
COUNT_SYNC_VALUE
)
{
// Poll in milliseconds.
while
(
m_countNumor
==
0
&&
i
<
timeout
*
100
&&
!
m_stopped
)
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
10
));
i
++
;
}
if
(
m_stopped
)
{
log
(
Level
::
s_Info
)
<<
name
<<
"preset "
<<
preset
()
<<
" stopped"
<<
endlog
;
return
;
}
if
(
m_countNumor
==
0
)
{
log
(
Level
::
s_Error
)
<<
name
<<
"preset "
<<
preset
()
<<
" start timeout"
<<
endlog
;
return
;
}
}
// Serialize the request.
windeta
::
Request
requestType
;
requestType
.
set_type
(
windeta
::
Request
::
START_MEASURE
);
...
...
@@ -271,8 +310,6 @@ void RemoteWindeta::start() {
// Send the message.
m_requester
->
sendTwoBinaryParts
(
requestType
.
SerializeAsString
(),
requestMessage
.
SerializeAsString
());
cout
<<
getName
()
<<
" sent request "
<<
static_cast
<
int
>
(
requestType
.
type
())
<<
endl
;
// Wait for the response synchronously.
// Note that responses can be processed asynchronously if the server is able to.
string
data
;
...
...
@@ -281,22 +318,17 @@ void RemoteWindeta::start() {
windeta
::
Response
response
;
response
.
ParseFromString
(
data
);
cout
<<
"received response "
<<
response
.
errorcode
()
<<
endl
;
m_stopped
=
false
;
// Set the data filename.
setDataFilename
();
// The status must pass to running within a timeout.
int
i
=
0
;
int
timeout
=
startTimeout
();
while
(
!
commandStatus
.
isRunning
()
&&
i
<
timeout
&&
!
m_stopped
)
{
// The status must become running within a timeout.
i
=
0
;
while
(
!
commandStatus
.
isRunning
()
&&
!
commandStatus
.
isError
()
&&
i
<
timeout
&&
!
m_stopped
)
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
i
++
;
}
if
(
!
commandStatus
.
isRunning
())
{
if
(
!
commandStatus
.
isRunning
()
&&
!
commandStatus
.
isError
()
&&
!
m_stopped
)
{
log
(
Level
::
s_Error
)
<<
name
<<
"preset "
<<
preset
()
<<
" to "
<<
m_dataFilename
<<
" start timeout"
<<
endlog
;
return
;
}
...
...
@@ -306,10 +338,11 @@ void RemoteWindeta::start() {
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
}
// Check the execution.
if
(
m_stopped
)
{
log
(
Level
::
s_Info
)
<<
name
<<
"preset "
<<
preset
()
<<
" to "
<<
m_dataFilename
<<
" stopped"
<<
endlog
;
}
else
if
(
commandStatus
.
isError
())
{
}
else
if
(
commandStatus
.
isError
())
{
log
(
Level
::
s_Error
)
<<
name
<<
"preset "
<<
preset
()
<<
" to "
<<
m_dataFilename
<<
" on error"
<<
endlog
;
}
else
{
...
...
@@ -376,8 +409,6 @@ void RemoteWindeta::stopApplication() {
// Send the message.
m_requester
->
sendTwoBinaryParts
(
requestType
.
SerializeAsString
(),
""
);
cout
<<
getName
()
<<
" sent request "
<<
static_cast
<
int
>
(
requestType
.
type
())
<<
endl
;
// Wait for the response synchronously.
// Note that responses can be processed asynchronously if the server is able to.
string
data
;
...
...
@@ -386,8 +417,6 @@ void RemoteWindeta::stopApplication() {
windeta
::
Response
response
;
response
.
ParseFromString
(
data
);
cout
<<
"received response "
<<
response
.
errorcode
()
<<
endl
;
// Stop the remote application.
m_windetaApplication
->
stop
();
...
...
@@ -443,12 +472,17 @@ void RemoteWindeta::setDataFilename() {
m_independentDataFileId
++
;
m_dataFilename
=
ServerProperties
::
getInstance
()
->
getNomadDataPath
()
+
INDEPENDENT_PREFIX
+
lexical_cast
<
string
>
(
m_independentDataFileId
)
+
".diel"
;
cout
<<
"Independent data filename "
<<
m_dataFilename
<<
endl
;
}
else
{
// Set the filename related to numor.
int
numor
=
0
;
if
(
dataFilenameFormat
()
==
NUMOR_VALUE
||
dataFilenameFormat
()
==
NUMOR_1_VALUE
)
{
numor
=
experimentData
->
numor
();
}
else
{
numor
=
m_countNumor
;
}
int
numor
=
experimentData
->
numor
();
if
(
dataFilenameFormat
()
==
NUMOR_1_VALUE
)
{
numor
++
;
}
...
...
@@ -476,8 +510,6 @@ void RemoteWindeta::setDataFilename() {
}
m_dataFilename
=
dataFilename
;
cout
<<
"Numor data filename "
<<
m_dataFilename
<<
endl
;
}
}
...
...
@@ -530,8 +562,6 @@ void RemoteWindeta::subscriberLoop() {
numberOfPoints
=
data
.
points
();
saveData
(
data
.
data
());
cout
<<
"Data "
<<
data
.
points
()
<<
" points"
<<
endl
;
}
else
if
(
event
.
type
()
==
windeta
::
Event
::
PRESETS
)
{
windeta
::
Presets
messagePresets
;
...
...
src/controllers/remotedielectricswindeta/DielectricsRemoteWindeta.h
View file @
acb56f65
...
...
@@ -21,7 +21,9 @@
#include
<Controller.h>
#include
<cameo/cameo.h>
#include
"controllers/common/utilities/CountSpy.h"
#include
"drivers/utilities/null/NullDriver.h"
#include
<thread>
namespace
dielectrics
{
...
...
@@ -89,6 +91,7 @@ private:
void
stopApplication
();
void
subscriberLoop
();
void
updateStatusMessage
();
void
initPresets
();
void
initIndependentDataFileId
();
void
setDataFilename
();
...
...
@@ -102,16 +105,19 @@ private:
static
const
std
::
string
INDEPENDENT_VALUE
;
static
const
std
::
string
NUMOR_VALUE
;
static
const
std
::
string
NUMOR_1_VALUE
;
static
const
std
::
string
COUNT_SYNC_VALUE
;
std
::
unique_ptr
<
cameo
::
Server
>
m_server
;
std
::
unique_ptr
<
cameo
::
application
::
Instance
>
m_windetaApplication
;
std
::
unique_ptr
<
cameo
::
application
::
Requester
>
m_requester
;
std
::
unique_ptr
<
cameo
::
application
::
Subscriber
>
m_subscriber
;
std
::
unique_ptr
<
boo
st
::
thread
>
m_subscriberThread
;
std
::
unique_ptr
<
st
d
::
thread
>
m_subscriberThread
;
ControllerPtr
<
utilities
::
CountSpy
>
m_CountSpy
;
DriverPtr
<
driver
::
NullDriver
>
m_driver
;
int
m_independentDataFileId
;
int
m_countNumor
;
bool
m_stopped
;
std
::
string
m_dataFilename
;
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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