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

Merge branch '8-sequence-tag-overflow' into 'master'

Resolve "sequence tag overflow"

Closes #8

See merge request !9
parents b7e1902b 3e994974
Pipeline #26475 passed with stage
in 1 minute and 8 seconds
......@@ -4,7 +4,7 @@ enable_testing()
set(MAJOR_VERSION 0)
set(MINOR_VERSION 9)
set(MINOR_VERSION 10)
set(LIBRARY_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}")
set(SO_VERSION ${LIBRARY_VERSION})
......
......@@ -753,8 +753,8 @@ namespace AGIPDCtrlNS
uint8 AGIPDComm::GetSequenceTag()
{
LOG_TRACE(__FUNCTION__);
return static_cast<uint8>(((m_tag++ == 255)?0:m_tag) & 0xff);
return static_cast<uint8>((m_tag = (m_tag++ == 255?0:m_tag)) & 0xff);
}
void AGIPDComm::PrintCmd(vector<uint8>& cmd)
......@@ -879,7 +879,6 @@ namespace AGIPDCtrlNS
vector<uint8> data(response.size());
std::copy(response.begin(),response.end(),data.begin());
PrintCmd(data);
if((static_cast<uint16>(response[3])& 0xff) == m_tag && response[0] == 0x0) // stop
{
LOG_INFOS("get reply of stop acquistion, continue waiting for reply of start acquistion");
......
......@@ -25,7 +25,7 @@ namespace TestNS
{
void CtrlTest::SetUp()
{
InitLogLevel(ERROR);
InitLogLevel(INFO);
m_testdir = "./testdata/";
......@@ -837,6 +837,69 @@ namespace TestNS
EXPECT_EQ(ref_return,log);
}
TEST_F(CtrlTest,StartAcqStopAcqSequenceTagResetTest)
{
// run some commands to increase sequence tag to 254
int32 pre_calls = 254;
EXPECT_CALL(*m_tcp,SendData(_))
.Times(pre_calls);
EXPECT_CALL(*m_tcp,ReceiveData(_,_,_,_))
.Times(pre_calls);
for(int32 i = 1; i <= pre_calls; i++)
m_agipd->Reboot();
// sequence tag now should be 255
vector<uint8> ref_data={0x80,0x81,0x00,0xff,0x00,0x00,0x80,0x82,0x00,0x00,0x00,0x00};
vector<uint8> rs_start_acq={0x1,0x0,0x3,0xff,0x0,0x2};
vector<uint8> rs_stop_acq = {0x0,0x0,0x3,0x00,0x0,0x0};
vector<uint8> data_ret_start_acq = {0x48,0x49};//HI
auto time_to_sleep = 1000; // millisecond
string ref_return(data_ret_start_acq.begin(),data_ret_start_acq.end());
szt rs_stop_len = rs_stop_acq.size();
szt rs_start_len = rs_start_acq.size();
szt data_length = data_ret_start_acq.size();
EXPECT_CALL(*m_tcp,SendData(_))
.Times(2)
.WillRepeatedly(DoAll(Invoke(this,&CtrlTest::OutputData),Return(0))); // one start one stop
EXPECT_CALL(*m_tcp,ReceiveData(_,_,_,_))
.Times(2)
.WillOnce(DoAll(InvokeWithoutArgs([time_to_sleep](){std::this_thread::sleep_for(std::chrono::milliseconds(time_to_sleep));}),
SetArrayArgument<0>(rs_stop_acq.begin(),rs_stop_acq.end()),
SetArgReferee<3>(rs_stop_len),
Return(0)))
.WillOnce(DoAll(SetArrayArgument<0>(rs_start_acq.begin(),rs_start_acq.end()),
SetArgReferee<3>(rs_start_len),
Return(0)));
EXPECT_CALL(*m_tcp,ReceiveData(_,data_length,data_length,_))
.Times(1)
.WillOnce(DoAll(SetArrayArgument<0>(data_ret_start_acq.begin(),data_ret_start_acq.end()),
SetArgReferee<3>(data_length),
Return(0)));
string log;
std::future<RESPONSE> rs = std::async(std::launch::async,[&]()
{
return m_agipd->StartAcq(log);
});
std::this_thread::sleep_for(std::chrono::seconds(1)); // wait for 1s
EXPECT_EQ(SC, m_agipd->StopAcq());
EXPECT_EQ(true, rs.valid());
while(rs.valid())
if(rs.wait_for(std::chrono::milliseconds(10)) == std::future_status::ready)
break;
EXPECT_EQ(SC,rs.get());
EXPECT_EQ(ref_data,m_output);
EXPECT_EQ(ref_return,log);
}
void CtrlTest::OutputData(vector<uint8> data)
{
......
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