Commit 9724548f authored by ahoms's avatar ahoms
Browse files

* removed default BufferSave constructor; using default parameter list

* added buffer saving to testsimulator



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@38 45c4679d-1946-429d-baad-37912b19538b
parent cd108f10
......@@ -28,17 +28,6 @@ BufferSave::BufferSave( FileFormat format, const String& prefix, int idx,
}
BufferSave::BufferSave( )
: m_format(Raw), m_prefix(), m_idx(0), m_overwrite(false),
m_tot_file_frames(1)
{
m_written_frames = 0;
m_fout = NULL;
if (m_suffix == "")
m_suffix = getDefSuffix();
}
BufferSave::~BufferSave( )
{
closeFile();
......@@ -80,25 +69,25 @@ void BufferSave::closeFile()
void BufferSave::writeEdfHeader( const FrameInfoType& finfo )
{
time_t ctime_now;
struct timeval tod_now;
char time_str[64], buffer[EDF_HEADER_BUFFER_LEN], *p;
int l, len, rem;
const FrameDim *fdim = finfo.frame_dim;
const Size& frame_size = fdim->getSize();
int depth = fdim->getDepth();
int image = m_written_frames + 1;
time(&ctime_now);
struct timeval tod_now;
gettimeofday(&tod_now, NULL);
char time_str[64];
ctime_r(&ctime_now, time_str);
time_str[strlen(time_str) - 1] = '\0';
p = buffer;
const FrameDim *fdim = finfo.frame_dim;
const Size& frame_size = fdim->getSize();
int depth = fdim->getDepth();
int image_nb = m_written_frames + 1;
char buffer[EDF_HEADER_BUFFER_LEN];
char *p = buffer;
p += sprintf(p, "{\n");
p += sprintf(p, "HeaderID = EH:%06u:000000:000000 ;\n", image);
p += sprintf(p, "Image = %u ;\n", image);
p += sprintf(p, "HeaderID = EH:%06u:000000:000000 ;\n", image_nb);
p += sprintf(p, "Image = %u ;\n", image_nb);
p += sprintf(p, "ByteOrder = LowByteFirst ;\n");
p += sprintf(p, "DataType = %s ;\n",
(depth == 1) ? "UnsignedByte" :
......@@ -115,9 +104,9 @@ void BufferSave::writeEdfHeader( const FrameInfoType& finfo )
p += sprintf(p, "time_of_frame = %.6f ;\n",
double(finfo.frame_timestamp));
l = p - buffer;
len = l;
rem = len % EDF_HEADER_LEN;
int l = p - buffer;
int len = l;
int rem = len % EDF_HEADER_LEN;
if (rem > 0)
len += EDF_HEADER_LEN - rem;
p += sprintf(p, "%*s}\n", len - (l + 2), "");
......
......@@ -18,8 +18,7 @@ class BufferSave {
typedef std::string String;
BufferSave( );
BufferSave( FileFormat format, const String& prefix,
BufferSave( FileFormat format = Raw, const String& prefix = "img",
int idx = 0, const String& suffix = "",
bool overwrite = false , int tot_file_frames = 1);
~BufferSave( );
......
......@@ -4,7 +4,7 @@ std-objs = ../../../common/src/Common.o ../../../hardware/src/Hw.o
test-objs = test.o BufferSave.o
test-ext-objs = ../src/FrameBuilder.o
testsimulator-objs = testsimulator.o
testsimulator-objs = testsimulator.o BufferSave.o
testsimulator-ext-objs = ../src/Simulator.o ../src/FrameBuilder.o $(std-objs)
INC = -I../include -I../../../common/include -I../../../hardware/include
......
#include "Simulator.h"
#include "BufferSave.h"
#include <iostream>
......@@ -8,11 +9,13 @@ using namespace std;
class TestFrameCallback : public HwFrameCallback
{
public:
TestFrameCallback(Simulator& simu) : m_simu(simu) {}
TestFrameCallback(Simulator& simu, BufferSave& buffer_save)
: m_simu(simu), m_buffer_save(buffer_save) {}
protected:
virtual bool newFrameReady(const FrameInfoType& frame_info);
private:
Simulator& m_simu;
BufferSave& m_buffer_save;
};
bool TestFrameCallback::newFrameReady(const FrameInfoType& frame_info)
......@@ -20,6 +23,7 @@ bool TestFrameCallback::newFrameReady(const FrameInfoType& frame_info)
cout << "acq_frame_nb=" << frame_info.acq_frame_nb << ", "
<< "ts=" << frame_info.frame_timestamp << ", "
<< "simu=" << m_simu << endl;
m_buffer_save.writeFrame(frame_info);
return true;
}
......@@ -27,14 +31,15 @@ bool TestFrameCallback::newFrameReady(const FrameInfoType& frame_info)
int main(int argc, char *argv[])
{
Simulator simu;
TestFrameCallback cb(simu);
BufferSave buffer_save(BufferSave::EDF);
TestFrameCallback cb(simu, buffer_save);
FrameDim frame_dim;
simu.getFrameDim(frame_dim);
BufferCtrlMgr& buffer_mgr = simu.getBufferMgr();
buffer_mgr.setFrameDim(frame_dim);
buffer_mgr.setNbBuffers(1);
buffer_mgr.setNbBuffers(10);
buffer_mgr.registerFrameCallback(&cb);
cout << "simu=" << simu << endl;
......
Markdown is supported
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