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

changed live image method

parent 76a80181
......@@ -202,6 +202,12 @@ namespace FSDataRecvNS
if(m_save_file)
m_filesaving_task->Stop();
}
void DataReceiver::SetLiveViewInterval(int32 interval)
{
LOG_TRACE(__FUNCTION__);
m_receiver_task->SetLiveViewInterval(interval);
}
void DataReceiver::GetLiveImageData(shared_ptr<int32>& img_data,
int32& frame_number,
......
......@@ -127,6 +127,12 @@ namespace FSDataRecvNS
*/
void Stop();
/**
* @brief set live view interval
* @param interval interval of liveview
*/
void SetLiveViewInterval(int32 interval);
/**
* @brief get live image data
* @param img_data data of live image
......
......@@ -42,7 +42,7 @@ namespace FSDataRecvNS
m_file_name("test"),
m_xml_structure(""),
m_file_split(false),
m_fileopen(false),
m_fileopen(false),
m_img_data(m_x*m_y,0)
{
LOG_TRACE(__FUNCTION__);
......@@ -90,9 +90,9 @@ namespace FSDataRecvNS
int32 FileSavingTask::GetFileIndex()
{
LOG_TRACE(__FUNCTION__);
LOG_TRACE(__FUNCTION__);
return m_file_index;
return m_file_index;
}
int32 FileSavingTask::GetSavedImages()
......@@ -112,23 +112,23 @@ namespace FSDataRecvNS
boost::unique_lock<boost::mutex> lock(m_bstSync);
if(!m_fStart)
{
{
if(m_fileopen)
CloseFile();
if(m_fileopen)
CloseFile();
m_bstCond.wait(lock);
m_bstCond.wait(lock);
if(m_fExit)
break;
if(m_fExit)
break;
UpdateParameters();
if(!CreateFile())
{
Stop();
continue;
}
}
UpdateParameters();
if(!CreateFile())
{
Stop();
continue;
}
}
......@@ -138,8 +138,8 @@ namespace FSDataRecvNS
if(m_saved_images >= m_requested_frames)
{
Stop();
CloseFile();
++m_file_index;
CloseFile();
++m_file_index;
continue;
}
......@@ -161,12 +161,12 @@ namespace FSDataRecvNS
lock.unlock();
if(m_file_split &&
(m_saved_images % m_frames_per_file) == 0 && m_saved_images<m_requested_frames)
(m_saved_images % m_frames_per_file) == 0 && m_saved_images<m_requested_frames)
{
CloseFile();
++m_file_index;
if(!CreateFile())
Stop();
CloseFile();
++m_file_index;
if(!CreateFile())
Stop();
}
}
}
......@@ -203,36 +203,36 @@ namespace FSDataRecvNS
}
if(nx_writer->FileConfig(nxs_filename,
true,
1,
m_y,
m_x,
16,
1,
false,
false,
false,
2,
false,
0) !=0 )
true,
1,
m_y,
m_x,
16,
1,
false,
false,
false,
2,
false,
0) !=0 )
return false;
if(nx_writer->CreateFile() !=0 )
return false;
LOG_INFOS("Create file:" + m_file_name);
LOG_INFOS("Create file:" + m_file_name);
if(nx_writer->CreateStructureFromXMLString(m_xml_structure) !=0 )
return false;
LOG_INFOS("XML file structure:" + m_xml_structure);
//open related fields for data written
nx_writer->PreAcq(string("/:NXentry/:NXinstrument/:NXdetector/data"),
string("/:NXentry/:NXinstrument/:NXdetector/sequence_number"),
string("/:NXentry/:NXinstrument/:NXdetector/:NXcollection/error_code"));
//open related fields for data written
nx_writer->PreAcq(string("/:NXentry/:NXinstrument/:NXdetector/data"),
string("/:NXentry/:NXinstrument/:NXdetector/sequence_number"),
string("/:NXentry/:NXinstrument/:NXdetector/:NXcollection/error_code"));
m_fileopen = true;
m_fileopen = true;
return true;
}
......@@ -243,9 +243,9 @@ namespace FSDataRecvNS
if(nx_writer->CloseFile() !=0 )
return false;
m_fileopen=false;
m_fileopen=false;
LOG_INFOS("Close file:" + m_file_name);
LOG_INFOS("Close file:" + m_file_name);
return true;
}
......
......@@ -26,19 +26,21 @@ namespace FSDataRecvNS
ReceiverTask::ReceiverTask(string udp_ip,
int16 port,
int32 x,
int32 y,
int32 x,
int32 y,
int32 img_size,
sptr_mem16bit const& mempool)
:m_mempool16bit(mempool),
m_img_size(img_size),
m_received_imgs(0),
m_packets_collected(0),
m_x(x),
m_y(y),
m_x(x),
m_y(y),
m_liveviewinterval(-1),
m_packet(),
m_img_data(img_size,0),
m_reordered_img(img_size,0)
m_reordered_img(img_size,0),
m_liveimg(img_size,0)
{
LOG_TRACE(__FUNCTION__);
......@@ -67,6 +69,12 @@ namespace FSDataRecvNS
LOG_TRACE(__FUNCTION__);
return m_received_imgs;
}
void ReceiverTask::SetLiveViewInterval(int32 interval)
{
LOG_TRACE(__FUNCTION__);
m_liveviewinterval = interval;
}
void ReceiverTask::GetLiveImageData(shared_ptr<int32> const& img_data,
int32& frame_number,
......@@ -74,7 +82,10 @@ namespace FSDataRecvNS
{
LOG_TRACE(__FUNCTION__);
boost::unique_lock<boost::mutex> lock(m_bstSync);
std::copy(m_reordered_img.begin(),m_reordered_img.end(),img_data.get());
//img_data = m_liveimg;
std::copy(m_liveimg.begin(),m_liveimg.end(),img_data.get());
frame_number = m_current_frame_number;
error_code = 0;//not used for live images
lock.unlock();
......@@ -84,22 +95,24 @@ namespace FSDataRecvNS
{
LOG_TRACE(__FUNCTION__);
int32 frame_no;
//int32 frame_no;
int16 error_code;
szt packet_size;
while(1)
{
usleep(100);
usleep(20);
boost::unique_lock<boost::mutex> lock(m_bstSync);
if(!m_fStart)
{
m_udpconn->ClearDataInSocket();
m_bstCond.wait(lock);
if(m_fExit)
break;
if(m_fExit)
break;
LOG_INFOS("Get requested images : "+to_string(m_requested_frames));
m_received_imgs = 0;
m_packets_collected = 0;
......@@ -109,13 +122,18 @@ namespace FSDataRecvNS
if(m_mempool16bit->GetTotalReceivedFrames() == m_requested_frames)
{
LOG_INFOS("Get enough images stop : "+to_string(m_requested_frames));
Stop();
continue;
}
error_code = m_udpconn->ReceivePacket((char*)(&m_packet),packet_size);
if(error_code != -1)
{
if(packet_size != 8192)
LOG_STREAM(__FUNCTION__,ERROR,"packet size error : " + to_string(packet_size));
BuildImage(m_packet);
}
}
}
......@@ -124,32 +142,41 @@ namespace FSDataRecvNS
LOG_TRACE(__FUNCTION__);
memcpy(&m_img_data[m_packets_collected*4096],
packet_data.data,
4096*sizeof(uint16_t));
packet_data.data,
4096*sizeof(int16));
++m_packets_collected;
if(m_packets_collected == 16) // one image is finished
{
++m_received_imgs;
m_current_frame_number = m_received_imgs;
//covert col-major order to row-major order
int32 col = 0;
int32 row = 0;
for(int32 i=0; i<m_img_size; ++i)
{
m_reordered_img[(col+m_x*row)]=m_img_data[i];
++row;
if(row == m_y)
{
row = 0;
++col;
//covert col-major order to row-major order
int32 col = 0;
int32 row = 0;
for(int32 i=0; i<m_img_size; ++i)
{
m_reordered_img[(col+m_x*row)]=m_img_data[i];
++row;
if(row == m_y)
{
row = 0;
++col;
}
}
}
int16* data = reinterpret_cast<int16*>(&m_reordered_img[0]);
int16* data = reinterpret_cast<int16*>(&m_reordered_img[0]);
m_mempool16bit->SetImage(data,m_received_imgs,0);
m_packets_collected = 0;
LOG_INFOS("Get image : "+to_string(m_received_imgs));
//update live image
if(m_received_imgs % m_liveviewinterval == 0 && m_liveviewinterval !=-1)
{
boost::unique_lock<boost::mutex> lock(m_bstSync);
std::copy(m_reordered_img.begin(),m_reordered_img.end(),m_liveimg.begin());
lock.unlock();
}
m_packets_collected = 0;
if(m_received_imgs % 352 == 0)
LOG_INFOS("Get image : "+to_string(m_received_imgs));
}
}
......
......@@ -81,6 +81,12 @@ namespace FSDataRecvNS
*/
int32 GetReceivedImages();
/**
* @brief set live view interval
* @param interval interval of liveview
*/
void SetLiveViewInterval(int32 interval);
/**
* @brief get live image
* @param img_data image data
......@@ -108,9 +114,9 @@ namespace FSDataRecvNS
int64 m_current_frame_number;
int32 m_img_size,m_received_imgs,m_requested_frames,m_packets_collected,m_x,m_y;
int32 m_img_size,m_received_imgs,m_requested_frames,m_packets_collected,m_x,m_y,m_liveviewinterval;
packet_struct m_packet;
vector<int16> m_img_data,m_reordered_img;
vector<int16> m_img_data,m_reordered_img,m_liveimg;
};
}
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