Commit b7e1902b authored by Yuelong Yu's avatar Yuelong Yu
Browse files

Merge branch '7-add-reboot-command' into 'master'

add reboot command

Closes #7

See merge request !8
parents 2daab3ae 6c74e6a4
Pipeline #26473 passed with stage
in 1 minute and 10 seconds
variables:
debian9_image_name: yyl10/debian9:latest
debian10_image_name: yyl10/debian10:latest
debian9_image_name: gitlab.desy.de:5555/yuelong.yu/docker-image-debian9/debian9:latest
debian10_image_name: gitlab.desy.de:5555/yuelong.yu/docker-image-debian10/debian10:latest
debian11_image_name: gitlab.desy.de:5555/yuelong.yu/docker-image-debian11/debian11:latest
stages:
- build
- test
- deploy
.runscript: &runscript
.build_scripts: &build_scripts
before_script:
- apt install -y unzip
- apt install libfsdetcore-0.11 libfsdetcore-0.11-devel
- apt update
- apt install -y libfsdetcore-0.13 libfsdetcore-0.13-devel
script:
- source .gitlab/build.sh
......@@ -19,15 +20,9 @@ build on debian 9:
image: $debian9_image_name
tags:
- DESY-intern
only:
- master
- develop
- merge_requests
<<: *runscript
artifacts:
paths:
- report/*.xml
- branches
<<: *build_scripts
build on debian 10:
stage: build
......@@ -35,36 +30,14 @@ build on debian 10:
tags:
- DESY-intern
only:
- master
- develop
- merge_requests
<<: *runscript
artifacts:
paths:
- report/*.xml
build package debian 9:
stage: deploy
only:
- master
- tags
variables:
UPSTREAM_IMAGENAME: $debian9_image_name
UPSTREAM_DIST: debian9
UPSTREAM_BRANCH: $CI_COMMIT_REF_NAME
UPSTREAM_HASH: $CI_COMMIT_SHORT_SHA
trigger: detectorsoftware/libagipdctrl-deploy
build package debian 10:
stage: deploy
only:
- master
- tags
variables:
UPSTREAM_IMAGENAME: $debian10_image_name
UPSTREAM_DIST: debian10
UPSTREAM_BRANCH: $CI_COMMIT_REF_NAME
UPSTREAM_HASH: $CI_COMMIT_SHORT_SHA
- branches
<<: *build_scripts
trigger: detectorsoftware/libagipdctrl-deploy
build on debian 11:
stage: build
image: $debian11_image_name
tags:
- DESY-intern
only:
- branches
<<: *build_scripts
......@@ -9,7 +9,7 @@ echo "=start build="
cmake -DCMAKE_INSTALL_PREFIX="/lib.local/" -DCMAKE_BUILD_TYPE=DEBUG "$SOURCE_ROOT"
make -j4
echo "=run test="
ctest --verbose
ctest -VV
echo "=install="
make install
cd "$SOURCE_ROOT"
\ No newline at end of file
......@@ -4,7 +4,7 @@ enable_testing()
set(MAJOR_VERSION 0)
set(MINOR_VERSION 8)
set(MINOR_VERSION 9)
set(LIBRARY_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}")
set(SO_VERSION ${LIBRARY_VERSION})
......
# Introduction
libagipdctrl is used to control AGIPD4M system.
# libagipdctrl
This library is used to control AGIPD4M system.
# Dependency
- [libfsdetcore v0.11 ](https://stash.desy.de/plugins/servlet/network/FSDSDET/libfsdetcore)
Debian packages for stretch/buster are available, please contact the author.
- [libfsdetcore >= 0.11 ](https://gitlab.desy.de/detectorsoftware/libfsdetcore)
# Installation
Debian packages of libfsdetcore for stretch/buster/bullseye are available, please contact the author.
- build from source
```
mkdir build
cd build
cmake ..
make
# Installation
## Build
Clone source and build
```bash
$ git clone https://gitlab.desy.de/detectorsoftware/libagipdctrl.git
$ mkdir build
$ cd build
$ cmake ..
$ make
```
# Packages
Debian packages for stretch/buster are available.
## Packages
Debian packages of libagipdctrl for stretch/buster/bullseye are available.
\ No newline at end of file
/*
* (c) Copyright 2018-2020 DESY
* (c) Copyright 2018-2022 DESY
*
* This file is part of FS-DS detector software.
*
......@@ -41,14 +41,12 @@ namespace AGIPDCtrlNS
m_start = false;
}
bool AGIPDComm::Init(sptr_network& tcp,string log_path)
void AGIPDComm::Init(sptr_network& tcp,string log_path)
{
LOG_TRACE(__FUNCTION__);
m_tcp = tcp;
m_logpath = log_path;
return true;
}
string AGIPDComm::GetFirmwareVersion()
......@@ -634,6 +632,25 @@ namespace AGIPDCtrlNS
}
}
RESPONSE AGIPDComm::Reboot()
{
LOG_TRACE(__FUNCTION__);
vector<uint8> cmd = m_cmd;
cmd[0] = 0x80;
cmd[1] = 0x0e; // command code
cmd[2] = 0x00; // to ZYNC
cmd[3] = GetSequenceTag();
cmd[5] = 0x00;
PrintCmd(cmd);
m_tcp->SendData(cmd);
vector<char> response(6,0x00);
return CheckResponse(response);
}
string AGIPDComm::ReadFile(string& file_path)
{
LOG_TRACE(__FUNCTION__);
......
/*
* (c) Copyright 2018-2020 DESY
* (c) Copyright 2018-2022 DESY
*
* This file is part of FS-DS detector software.
*
......@@ -48,10 +48,8 @@ namespace AGIPDCtrlNS
* \brief init the communication part
* \param tcp connection for communication
* \param log_path path for saving log files
* \return status. true : OK
* flase : init is failed
*/
bool Init(sptr_network& tcp, string log_path);
void Init(sptr_network& tcp, string log_path);
/**
* \brief get firmware version
......@@ -211,6 +209,12 @@ namespace AGIPDCtrlNS
* \return response of command \see AGIPDCtrlNS::RESPONSE
*/
RESPONSE StopAcq();
/**
* \brief reboot the hardware
* \return response of command \see AGIPDCtrlNS::RESPONSE
*/
RESPONSE Reboot();
private:
/**
......
/*
* (c) Copyright 2018-2020 DESY
* (c) Copyright 2018-2022 DESY
*
* This file is part of FS-DS detector software.
*
......@@ -26,46 +26,14 @@
namespace AGIPDCtrlNS
{
AGIPDCtrlInterface::AGIPDCtrlInterface(ComConnConfigs& c1, MetadataConnConfigs& c2, Enum_log_level level)
:m_cc(c1),
m_mc(c2)
{
FSDetCoreNS::InitLogLevel(level);
LOG_TRACE(__FUNCTION__);
auto conn_com = sptr_network(new NetworkTCPInterface(new NetworkTCPImplementation(c1.ip,c1.port)));
auto conn_metadata = sptr_network(new NetworkTCPInterface(new NetworkTCPImplementation(c2.ip,c2.port)));
string msg = "control connection: " + c1.ip + ":" + to_string(c1.port)
+ " - log path:" + c1.log_path;
LOG_INFOS(msg);
if(conn_com->Connect() != 0)
{
msg += " failed";
LOG_STREAM(__FUNCTION__,ERROR,msg);
//recycle resources
conn_com.reset();
throw runtime_error(msg);
}
m_communication = uptr_agipdcomm(new AGIPDComm());
m_communication->Init(conn_com,c1.log_path);
msg = "metadata connection " + c2.ip + ":" + to_string(c2.port)
+ " - data length:" + to_string(c2.data_length)
+ " - polling:" + to_string(c2.polling_interval);
LOG_INFOS(msg);
if(conn_metadata->Connect() != 0)
{
msg += " failed";
LOG_STREAM(__FUNCTION__,ERROR,msg);
//recycle resources
conn_metadata.reset();
conn_com.reset();
m_communication.reset();
throw runtime_error(msg);
}
m_metadata = sptr_agipdmetadata(new AGIPDMetaData(conn_metadata,c2.data_length,c2.polling_interval));
std::thread(&AGIPDMetaData::DoTaskAction,m_metadata.get()).detach();
Init();
}
AGIPDCtrlInterface::~AGIPDCtrlInterface()
......@@ -239,6 +207,36 @@ namespace AGIPDCtrlNS
return m_communication->StopAcq();
}
RESPONSE AGIPDCtrlInterface::Reboot(int32 time_to_reboot)
{
LOG_TRACE(__FUNCTION__);
LOG_INFOS("Disconnect metadata connection, it may take up to 2 mins");
m_metadata->Reboot();
auto ret = m_communication->Reboot();
if(ret != SC)
return ret;
m_metadata.reset();
m_communication.reset();
LOG_INFOS("wait for " + to_string(time_to_reboot) + " to reboot");
this_thread::sleep_for(std::chrono::seconds(time_to_reboot));
LOG_INFOS("start to re-establish connections");
try
{
Init();
return SC;
}
catch(std::runtime_error &e)
{
LOG_STREAM(__FUNCTION__,ERROR,string(e.what()));
return CE;
}
}
string AGIPDCtrlInterface::GetResponseType(RESPONSE rc)
{
LOG_TRACE(__FUNCTION__);
......@@ -292,4 +290,45 @@ namespace AGIPDCtrlNS
return m_metadata->GetAcquisitionCounter(counter);
}
void AGIPDCtrlInterface::Init()
{
LOG_TRACE(__FUNCTION__);
auto conn_com = sptr_network(new NetworkTCPInterface(new NetworkTCPImplementation(m_cc.ip,m_cc.port)));
auto conn_metadata = sptr_network(new NetworkTCPInterface(new NetworkTCPImplementation(m_mc.ip,m_mc.port)));
string msg = "control connection: " + m_cc.ip + ":" + to_string(m_cc.port)
+ " - log path:" + m_cc.log_path;
LOG_INFOS(msg);
if(conn_com->Connect() != 0)
{
msg += " failed";
LOG_STREAM(__FUNCTION__,ERROR,msg);
//recycle resources
conn_com.reset();
throw runtime_error(msg);
}
m_communication = uptr_agipdcomm(new AGIPDComm());
m_communication->Init(conn_com,m_cc.log_path);
msg = "metadata connection " + m_mc.ip + ":" + to_string(m_mc.port)
+ " - data length:" + to_string(m_mc.data_length)
+ " - polling:" + to_string(m_mc.polling_interval);
LOG_INFOS(msg);
if(conn_metadata->Connect() != 0)
{
msg += " failed";
LOG_STREAM(__FUNCTION__,ERROR,msg);
//recycle resources
conn_metadata.reset();
conn_com.reset();
m_communication.reset();
throw runtime_error(msg);
}
m_metadata = sptr_agipdmetadata(new AGIPDMetaData(conn_metadata,m_mc.data_length,m_mc.polling_interval));
std::thread(&AGIPDMetaData::DoTaskAction,m_metadata.get()).detach();
}
}
/*
* (c) Copyright 2018-2020 DESY
* (c) Copyright 2018-2022 DESY
*
* This file is part of FS-DS detector software.
*
......@@ -248,6 +248,14 @@ namespace AGIPDCtrlNS
*/
RESPONSE StopAcq();
/**
* \brief reboot the hardware
* \param time_to_reboot in seconds, the client tries to re-establish connection to hardware
* by default 20s
* \return response of command \see AGIPDCtrlNS::RESPONSE
*/
RESPONSE Reboot(int32 time_to_reboot = 20);
/**
* \brief get response string via response type
* \param rc response type
......@@ -293,8 +301,15 @@ namespace AGIPDCtrlNS
RESPONSE GetAcquisitionCounter(uint32& counter);
private:
/**
* \brief init device
* \throw runtime_error
*/
void Init();
uptr_agipdcomm m_communication;
sptr_agipdmetadata m_metadata;
ComConnConfigs m_cc;
MetadataConnConfigs m_mc;
};
......
/*
* (c) Copyright 2018-2020 DESY
* (c) Copyright 2018-2022 DESY
*
* This file is part of FS-DS detector software.
*
......@@ -55,10 +55,12 @@ namespace AGIPDCtrlNS
m_exit = true;
}
void AGIPDMetaData::Exit()
void AGIPDMetaData::Reboot()
{
LOG_TRACE(__FUNCTION__);
m_exit = true;
while(m_running)
this_thread::sleep_for(std::chrono::seconds(1));
}
void AGIPDMetaData::DoTaskAction()
......@@ -110,13 +112,14 @@ namespace AGIPDCtrlNS
void AGIPDMetaData::StartReadMetaData()
{
LOG_TRACE(__FUNCTION__);
m_running = true;
vector<uint8> data;
LOG_INFOS("read metadata thread start...");
while(true)
{
if(m_exit)
break;
//reads data
std::this_thread::sleep_for(std::chrono::milliseconds(m_polling_interval));
char* rec_data = m_metadata.data();
......@@ -165,10 +168,11 @@ namespace AGIPDCtrlNS
}
}
LOG_INFOS("read metadata thread quit...");
m_running = false;
}
void AGIPDMetaData::PrintCmd(vector<uint8>& cmd)
{
LOG_STREAM1(__FUNCTION__,INFO,cmd);
LOG_STREAM1(__FUNCTION__,DEBUG,cmd);
}
}
/*
* (c) Copyright 2018-2021 DESY
* (c) Copyright 2018-2022 DESY
*
* This file is part of FS-DS detector software.
*
......@@ -57,8 +57,8 @@ namespace AGIPDCtrlNS
* \brief destructor
*/
~AGIPDMetaData();
void Exit();
void DoTaskAction();
void Reboot();
RESPONSE GetHighVoltage(uint16& high_voltage);
RESPONSE GetHighVoltageSlewRate(uint16& hv_slewrate);
RESPONSE GetTemperatures(vector<int16>& temperature);
......@@ -82,7 +82,7 @@ namespace AGIPDCtrlNS
uint16 m_hv, m_hvsr, m_power;
uint32 m_length_of_metadata, m_polling_interval, m_acq_counter;
std::mutex m_mtx;
std::atomic<bool> m_exit;
std::atomic<bool> m_exit, m_running;
RESPONSE m_rs;
};
......
......@@ -8,32 +8,9 @@ target_link_libraries(${PROJECT_NAME} ${SHARED_LINKER_FLAGS})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION "${LIBRARY_VERSION}"
SOVERSION "${SO_VERSION}")
#install target
#install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIB_PATH})
#create and install pkg-config file
#configure_file(${CMAKE_MODULE_PATH}/pkgconfig.pc.cmake
# ${EXECUTABLE_OUTPUT_PATH}/${PROJECT_NAME}.pc @ONLY)
#install(FILES ${EXECUTABLE_OUTPUT_PATH}/${PROJECT_NAME}.pc
# DESTINATION ${CMAKE_INSTALL_LIB_PATH}/pkgconfig)
configure_file(${CMAKE_MODULE_PATH}/Version.h.cmake
${PROJECT_SOURCE_DIR}/src/Version.h @ONLY)
# get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
# foreach(dir ${dirs})
# message(STATUS "include dir='${dir}'")
# endforeach()
# get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_DIRECTORIES)
# foreach(dir ${dirs})
# message(STATUS "library dir='${dir}'")
# endforeach()
#install target
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIB_PATH})
......
......@@ -4,5 +4,5 @@
namespace AGIPDCtrlNS
{
const std::string AGIPDCTRL_VERSION="0.8";
const std::string AGIPDCTRL_VERSION="0.9";
}
/*
* (c) Copyright 2018-2020 DESY
* (c) Copyright 2018-2022 DESY
*
* This file is part of FS-DS detector software.
*
......@@ -34,7 +34,7 @@ namespace TestNS
m_file =uptr_file(new FileReader());
auto ptr = static_pointer_cast<NetworkInterface>(m_tcp);
EXPECT_TRUE(m_agipd->Init(ptr,m_testdir));
m_agipd->Init(ptr,m_testdir);
}
void CtrlTest::TearDown()
......@@ -765,6 +765,27 @@ namespace TestNS
EXPECT_EQ(ref_data,m_output);
}
TEST_F(CtrlTest,RebootTest)
{
vector<uint8> ref_data={0x80,0x0e,0x00,0x01,0x00,0x00};
vector<uint8> response={0x0,0x0,0x3,0x4,0x0,0x0};
szt length = response.size();
EXPECT_CALL(*m_tcp,SendData(_))
.Times(1)
.WillOnce(DoAll(SaveArg<0>(&m_output),Return(0)));
EXPECT_CALL(*m_tcp,ReceiveData(_,length,length,_))
.Times(1)
.WillOnce(DoAll(SetArrayArgument<0>(response.begin(),response.end()),
SetArgReferee<3>(length),
Return(0)));
EXPECT_EQ(SC,m_agipd->Reboot());
EXPECT_EQ(ref_data,m_output);
}
TEST_F(CtrlTest,StartAcqStopAcqTest)
{
vector<uint8> ref_data={0x80,0x81,0x00,0x01,0x00,0x00,0x80,0x82,0x00,0x02,0x00,0x00};
......
......@@ -31,13 +31,12 @@ namespace TestNS
uint32 interval = 100; //ms
m_tcp =sptr_mocknet(new MockNetwork());
auto ptr = static_pointer_cast<NetworkInterface>(m_tcp);
auto ptr = dynamic_pointer_cast<NetworkInterface>(m_tcp);
m_agipd = uptr_agipd(new AGIPDMetaData(ptr,m_datalength,interval));
}
void MetaDataTest::TearDown()
{
m_agipd->Exit();
m_agipd.reset();
}
......@@ -90,7 +89,6 @@ namespace TestNS
.WillRepeatedly(DoAll(SetArrayArgument<0>(data_ret.begin(),data_ret.end()),
SetArgReferee<3>(sz),
Return(0)));
std::thread(&AGIPDMetaData::DoTaskAction,m_agipd.get()).detach();
this_thread::sleep_for(std::chrono::seconds(2));
uint16 hv, hvsr,p;
......@@ -117,7 +115,6 @@ namespace TestNS
.WillRepeatedly(DoAll(SetArrayArgument<0>(data_ret.begin(),data_ret.end()),
SetArgReferee<3>(m_datalength),
Return(0)));
std::thread(&AGIPDMetaData::DoTaskAction,m_agipd.get()).detach();
this_thread::sleep_for(std::chrono::seconds(2));
uint16 hv, hvsr,p;
......
......@@ -47,6 +47,7 @@ namespace TestNS
using ::testing::Return;
using ::testing::DoAll;
using ::testing::InvokeWithoutArgs;
using ::testing::Mock;
using ::testing::_;
typedef shared_ptr<MockNetwork> sptr_mocknet;
......
Supports Markdown
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