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