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

working on train format

parent 16c0c38a
......@@ -32,10 +32,12 @@ namespace FSDataRecvNS
using namespace FSDetCoreNS;
//using boost::asio::ip::udp;
typedef unique_ptr<ThreadPool> uptr_threads;
typedef shared_ptr<MemPool<int16>> sptr_mem16bit;
typedef unique_ptr<NetworkInterface> uptr_network;
const int16 CHAR_BUFFER = 8192;
const int16 CHAR_BUFFER = 9000;
// train header format
const string TRAIN_HEADER_CHECK="\xCE\xFA\xEF\xBE\x46\x44\x54\x58";
}
......@@ -37,6 +37,7 @@ namespace FSDataRecvNS
m_x(x),
m_y(y),
m_liveviewinterval(-1),
m_collected_bytes(0),
m_packet(),
m_img_data(img_size,0),
m_reordered_img(img_size,0),
......@@ -133,15 +134,86 @@ namespace FSDataRecvNS
//error_code = m_udpconn->ReceivePacket((char*)(&m_packet),packet_size);
while(m_udpconn->ReceivePacket((char*)(&m_packet),packet_size) != -1)
{
if(packet_size != 8192)
LOG_STREAM(__FUNCTION__,ERROR,"packet size error : " + to_string(packet_size));
BuildImage(m_packet);
//usleep(1);
// if(packet_size != 8192)
// LOG_STREAM(__FUNCTION__,ERROR,"packet size error : " + to_string(packet_size));
if(m_packets_collected == 0 && IsTrainFormat(m_packet))
BuildTrainImage(m_packet,packet_size);
else
BuildImage(m_packet);
}
}
}
bool ReceiverTask::IsTrainFormat(packet_struct const& packet_data)
{
LOG_TRACE(__FUNCTION__);
string header = string(packet_data.data,8);
if(header == TRAIN_HEADER_CHECK)
{
LOG_INFOS("train format");
return true;
}
LOG_INFOS("not train format");
return false;
}
void ReceiverTask::BuildTrainImage(packet_struct const& packet_data,szt packet_size)
{
bool sof = ((((uchar)packet_data.data[packet_size-1]) & 0x80) >> 7) & 0x1;
bool eof = ((((uchar)packet_data.data[packet_size-1]) & 0x40) >> 6) & 0x1;
m_current_frame_number = (((uint64)packet_data.data[47]& 0xff)<<56)
+(((uint64)packet_data.data[46]& 0xff)<<48)
+(((uint64)packet_data.data[45]& 0xff)<<40)
+(((uint64)packet_data.data[44]& 0xff)<<32)
+(((uint64)packet_data.data[43]& 0xff)<<24)
+(((uint64)packet_data.data[42]& 0xff)<<16)
+(((uint64)packet_data.data[41]& 0xff)<<8)
+((uint64)packet_data.data[40]& 0xff);
int bytes_to_copy = 0;
if(sof)
{
bytes_to_copy = packet_size
- 64 //train header size
- 8; //trailer size
memcpy(&m_img_data[m_collected_bytes/2],
&(packet_data.data[0]) + 64,
bytes_to_copy);
m_collected_bytes += bytes_to_copy;
}
else
{
bytes_to_copy = packet_size
- 8; // trailer size,no header
memcpy(&m_img_data[m_collected_bytes/2],
&(packet_data.data[0]),
bytes_to_copy);
m_collected_bytes += bytes_to_copy;
if(eof)
{
LOG_INFOS("last packet, copy image into buffer" + to_string(m_current_frame_number));
LOG_INFOS("received packets:" + to_string(m_packets_collected));
++m_received_imgs;
short error_code = 0;
if(m_collected_bytes != 131072) // expected image size is 131072
LOG_STREAM(__FUNCTION__,ERROR,"collected bytes error" + to_string(m_collected_bytes)) ;
m_mempool16bit->SetImage(m_img_data.data(),m_current_frame_number,error_code);
}
}
++m_packets_collected;
}
void ReceiverTask::BuildImage(packet_struct const& packet_data)
{
LOG_TRACE(__FUNCTION__);
......@@ -172,7 +244,7 @@ namespace FSDataRecvNS
int16* data = m_reordered_img.data();
m_mempool16bit->SetImage(data,m_received_imgs,0);
//update live image
if(m_received_imgs % m_liveviewinterval == 0 && m_liveviewinterval !=-1)
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());
......@@ -183,7 +255,6 @@ namespace FSDataRecvNS
if(m_received_imgs % 352 == 0)
LOG_INFOS("Get image : "+to_string(m_received_imgs));
}
}
}
......@@ -29,7 +29,7 @@ namespace FSDataRecvNS
#pragma pack(2)
struct packet_struct{
// char emptyheader[6];
//char header[64];
// uint64_t framenum;
// uint32_t exptime;
// uint32_t packetnum;
......@@ -43,7 +43,8 @@ namespace FSDataRecvNS
// uint16_t roundRobin;
// uint8_t detectortype;
// uint8_t headerVersion;
uint16_t data[CHAR_BUFFER];
char data[CHAR_BUFFER];
//char tailer[8];
};
#pragma pack(pop)
......@@ -103,18 +104,35 @@ namespace FSDataRecvNS
void DoTaskAction();
private:
/**
* @brief check if it is train format
*
* @param packet_data packet data
* @return true train format
* @return false non train format
*/
bool IsTrainFormat(packet_struct const& packet_data);
/**
* @brief build train image
*
* @param packet_data
*/
void BuildTrainImage(packet_struct const& packet_data,szt packet_size);
/**
* @brief build image from UDP packet
* @param packet UDP packet
*/
void BuildImage(packet_struct const& packet_data);
sptr_mem16bit m_mempool16bit;
uptr_network m_udpconn;
int64 m_current_frame_number;
int32 m_img_size,m_received_imgs,m_requested_frames,m_packets_collected,m_x,m_y,m_liveviewinterval;
int32 m_img_size,m_received_imgs,m_requested_frames,m_packets_collected,m_x,m_y,m_liveviewinterval,m_collected_bytes;
packet_struct m_packet;
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