YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
9#include <yarp/os/PortInfo.h>
11#include <yarp/os/RFModule.h>
12#include <yarp/os/Stamp.h>
13#include <yarp/sig/all.h>
14
15#include <iostream>
16#include <iomanip>
17#include <fstream>
18#include <sstream>
19#include <string>
20#include <array>
21#include <deque>
22#include <utility>
23#include <mutex>
24#include <algorithm>
25
26#ifdef ADD_VIDEO
27# include <opencv2/opencv.hpp>
28# include <yarp/cv/Cv.h>
29# include <opencv2/videoio.hpp>
30#endif // ADD_VIDEO
31
32
33using namespace yarp::os;
34using namespace yarp::sig;
35
36#ifdef ADD_VIDEO
37 using namespace yarp::cv;
38#endif
39
40/**************************************************************************/
42
43// Abstract object definition for queuing
44/**************************************************************************/
46{
47protected:
49
50public:
51 virtual ~DumpObj() = default;
52 virtual const std::string toFile(const std::string&, unsigned int) = 0;
53 virtual void attachFormat(const DumpFormat &format) { m_dump_format=format; }
54};
55
56
57// Specialization for Bottle object
58/**************************************************************************/
59class DumpBottle : public DumpObj
60{
61private:
62 Bottle *p;
63
64public:
65 DumpBottle() { p=new Bottle; }
66 DumpBottle(const DumpBottle &obj) { p=new Bottle(*(obj.p)); }
67 DumpBottle(const Bottle &b) { p=new Bottle(b); }
68 const DumpBottle &operator=(const DumpBottle &obj) { *p=*(obj.p); return *this; }
69 ~DumpBottle() { delete p; }
70
71 const std::string toFile(const std::string &dirName, unsigned int cnt) override
72 {
73 std::string ret=p->toString();
74 return ret;
75 }
76};
77
78
79// Object creator of type Bottle - overloaded
80/**************************************************************************/
82{
83 auto* p=new DumpBottle(obj);
84 return p;
85}
86
87
88// Specialization for Image object
89/**************************************************************************/
90class DumpImage : public DumpObj
91{
92private:
93 Image *p;
94#ifdef ADD_VIDEO
95 cv::Mat img;
96#endif
97
98public:
99 DumpImage() { p=new Image(); }
100 DumpImage(const DumpImage &obj) { p=new Image(*(obj.p)); }
101 DumpImage(const Image &img) { p=new Image(img); }
102 const DumpImage &operator=(const DumpImage &obj) { *p=*(obj.p); return *this; }
103 ~DumpImage() { delete p; }
104
105 const std::string toFile(const std::string &dirName, unsigned int cnt) override
106 {
108 std::string ext;
109
110 int code=p->getPixelCode();
111 switch (code)
112 {
113 //depth images
116 {
118 ext = ".float";
119 }
121 {
123 ext = ".floatzip";
124 }
125 break;
126
127 //grayscale images
128 case VOCAB_PIXEL_MONO:
130 {
132 ext = ".png";
133 }
134 else
135 {
137 ext = ".pgm";
138 }
139 break;
140
141 //rgb, bgr and other type of color images
142 default:
144 {
146 ext = ".jpg";
147 }
149 {
151 ext = ".png";
152 }
153 else
154 {
156 ext = ".ppm";
157 }
158 break;
159 }
160
161 std::ostringstream fName;
162 fName << std::setw(8) << std::setfill('0') << cnt << ext;
163 file::write(*p,dirName+"/"+fName.str(), fileformat);
164
165 return (fName.str()+" ["+Vocab32::decode(code)+"]");
166 }
167
168#ifdef ADD_VIDEO
169 const cv::Mat &getImage()
170 {
171 int code=p->getPixelCode();
172 if (code==VOCAB_PIXEL_MONO_FLOAT)
173 {
174 img=toCvMat(*static_cast<ImageOf<PixelFloat>*>(p));
175 }
176 else if (code==VOCAB_PIXEL_MONO)
177 {
178 img=toCvMat(*static_cast<ImageOf<PixelMono>*>(p));
179 }
180 else
181 {
182 img=toCvMat(*static_cast<ImageOf<PixelRgb>*>(p));
183 }
184 return img;
185 }
186#endif
187};
188
189
190// Object creator of type Image - overloaded
191/**************************************************************************/
193{
194 auto* p=new DumpImage(obj);
195 return p;
196}
197
198
199// Class to manage tx and rx time stamps
200/**************************************************************************/
202{
203 double rxStamp{0.0};
204 double txStamp{0.0};
205 bool rxOk{false};
206 bool txOk{false};
207
208public:
209 DumpTimeStamp() = default;
210
211 void setRxStamp(const double stamp) { rxStamp=stamp; rxOk=true; }
212 void setTxStamp(const double stamp) { txStamp=stamp; txOk=true; }
213 double getStamp() const
214 {
215 if (txOk) {
216 return txStamp;
217 } else if (rxOk) {
218 return rxStamp;
219 } else {
220 return -1.0;
221 }
222 }
223 std::string getString() const
224 {
225 std::ostringstream ret;
226 ret<<std::fixed;
227
228 if (txOk) {
229 ret << txStamp;
230 }
231 if (rxOk)
232 {
233 if (!ret.str().empty()) {
234 ret << ' ';
235 }
236 ret<<rxStamp;
237 }
238 return ret.str();
239 }
240};
241
242
243// Definition of item to be put in the queue
244/**************************************************************************/
251
252
253// Definition of the queue
254// Two services act on this resource:
255// 1) the port, which listens to incoming data
256// 2) the thread, which stores the data to disk
257/**************************************************************************/
258class DumpQueue : public std::deque<DumpItem>
259{
260private:
261 std::mutex mutex;
262
263public:
264 void lock() { mutex.lock(); }
265 void unlock() { mutex.unlock(); }
266};
267
268
269/**************************************************************************/
270template <class T>
271class DumpPort : public BufferedPort<T>
272{
273public:
274 DumpPort(DumpQueue &Q, unsigned int _dwnsample=1,
275 bool _rxTime=true, bool _txTime=false, DumpFormat _dataformat= DumpFormat::bottle) : buf(Q)
276 {
277 rxTime=_rxTime;
278 txTime=_txTime;
279 dwnsample=_dwnsample>0?_dwnsample:1;
280 cnt=0;
281 itemformat = _dataformat;
282 firstIncomingData=true;
283 }
284
285private:
286 DumpQueue &buf;
287 unsigned int dwnsample;
288 unsigned int cnt;
289 bool firstIncomingData;
290 bool rxTime;
291 bool txTime;
292 DumpFormat itemformat;
293
294 using BufferedPort<T>::onRead;
295 void onRead(T &obj) override
296 {
297 if (++cnt==dwnsample)
298 {
299 if (firstIncomingData)
300 {
301 yInfo() << "Incoming data detected";
302 firstIncomingData=false;
303 }
304
306 Stamp info;
307
309 item.seqNumber=info.getCount();
310
311 if (txTime || (info.isValid() && !rxTime)) {
312 item.timeStamp.setTxStamp(info.getTime());
313 }
314
315 if (rxTime || !info.isValid()) {
316 item.timeStamp.setRxStamp(Time::now());
317 }
318
319 item.obj=factory(obj);
320 item.obj->attachFormat(itemformat);
321
322 buf.lock();
323 buf.push_back(item);
324 buf.unlock();
325
326 cnt=0;
327 }
328 }
329};
330
331
332/**************************************************************************/
334{
335private:
336 DumpQueue &buf;
337 DumpFormat type;
338 std::ofstream finfo;
339 std::ofstream fdata;
340 std::string dirName;
341 std::string infoFile;
342 std::string dataFile;
343 unsigned int blockSize;
344 unsigned int cumulSize;
345 unsigned int counter;
346 double oldTime;
347
348 bool saveData;
349 bool videoOn;
350 std::string videoType;
351 bool rxTime;
352 bool txTime;
353 bool closing;
354
355#ifdef ADD_VIDEO
356 std::ofstream ftimecodes;
357 std::string videoFile;
358 std::string timecodesFile;
359 double t0;
361 bool doSaveFrame;
362 cv::VideoWriter videoWriter;
363#endif
364
365public:
366 DumpThread(DumpFormat _type, DumpQueue &Q, const std::string &_dirName, const int szToWrite,
367 const bool _saveData, const bool _videoOn, const std::string &_videoType,
368 const bool _rxTime, const bool _txTime) :
369 PeriodicThread(0.05),
370 buf(Q),
371 type(_type),
372 dirName(std::move(_dirName)),
373 blockSize(szToWrite),
374 cumulSize(0),
375 counter(0),
376 oldTime(0.0),
377 saveData(_saveData),
378 videoOn(_videoOn),
379 videoType(std::move(_videoType)),
380 rxTime(_rxTime),
381 txTime(_txTime),
382 closing(false)
383 {
384 infoFile=dirName;
385 infoFile+="/info.log";
386
387 dataFile=dirName;
388 dataFile+="/data.log";
389
390 #ifdef ADD_VIDEO
391 t0 = 0.0;
392 transform(videoType.begin(),videoType.end(),videoType.begin(),::tolower);
393 if ((videoType!="mkv") && (videoType!="avi"))
394 {
395 yWarning() << "unknown video type '" << videoType << "' specified; "
396 << "'mkv' type will be used.";
397 videoType="mkv";
398 }
399
400 videoFile=dirName;
401 videoFile+="/video.";
402 videoFile+=videoType;
403
404 timecodesFile=dirName;
405 timecodesFile+="/timecodes.log";
406
407 doImgParamsExtraction=videoOn;
408 doSaveFrame=false;
409 #endif
410 }
411
412 void writeSource(const std::string &sourceName, const bool connected)
413 {
414 finfo << "[" << std::fixed << Time::now() << "] ";
415 finfo << sourceName << " ";
416 finfo << (connected?"[connected]":"[disconnected]") << '\n';
417 }
418
419 bool threadInit() override
420 {
421 oldTime=Time::now();
422
423 finfo.open(infoFile.c_str());
424 if (!finfo.is_open())
425 {
426 yError() << "unable to open file: " << infoFile;
427 return false;
428 }
429
430 finfo<<"Type: ";
431 if (type == DumpFormat::bottle) {
432 finfo<<"Bottle;";
433 } else if (type == DumpFormat::image) {
435 finfo<<"Image;";
436 if (videoOn) {
437 finfo << " Video:" << videoType << "(huffyuv);";
438 }
439 } else if (type == DumpFormat::depth) {
440 finfo << "Depth;";
441 } else if (type == DumpFormat::depth_compressed) {
442 finfo << "DepthCompressed;";
443 } else if (type == DumpFormat::image_jpg) {
444 finfo << "Image:jpg;";
445 } else if (type == DumpFormat::image_png) {
446 finfo << "Image:png;";
447 } else {
448 yError() << "I should not reach this line! Unknown data type" << (int)type;
449 }
450 finfo<<'\n';
451
452 finfo<<"Stamp: ";
453 if (txTime && rxTime) {
454 finfo<<"tx+rx;";
455 } else if (txTime) {
456 finfo<<"tx;";
457 } else {
458 finfo << "rx;";
459 }
460 finfo<<'\n';
461
462 fdata.open(dataFile.c_str());
463 if (!fdata.is_open())
464 {
465 yError() << "unable to open file: " << dataFile;
466 return false;
467 }
468
469 #ifdef ADD_VIDEO
470 if (videoOn)
471 {
473 if (!ftimecodes.is_open())
474 {
475 yError() << "unable to open file: " << timecodesFile;
476 return false;
477 }
478 ftimecodes<<"# timecode format v2\n";
479 }
480 #endif
481
482 return true;
483 }
484
485 void run() override
486 {
488 buf.lock();
489 unsigned int sz=(unsigned int)buf.size();
490 buf.unlock();
491
492 // each 10 seconds it issues a writeToDisk command straightaway
493 bool writeToDisk=false;
494 double curTime=Time::now();
495 if ((curTime-oldTime>10.0) || closing)
496 {
497 writeToDisk=sz>0;
498 oldTime=curTime;
499 }
500
501 // it performs the writeToDisk on command or as soon as
502 // the queue size is greater than the given threshold
503 if ((sz>blockSize) || writeToDisk)
504 {
505 #ifdef ADD_VIDEO
506 // extract images parameters just once
507 if (doImgParamsExtraction && (sz>1))
508 {
509 buf.lock();
510 DumpItem itemFront=buf.front();
511 DumpItem itemEnd=buf.back();
512 buf.unlock();
513
514 int fps;
515 auto& img=static_cast<DumpImage*>(itemEnd.obj)->getImage();
516 int frameW=img.size().width;
517 int frameH=img.size().height;
518
519 t0=itemFront.timeStamp.getStamp();
520 double dt=itemEnd.timeStamp.getStamp()-t0;
521 fps=(dt<=0.0)?25:int(double(sz-1)/dt);
522
523 videoWriter.open(videoFile.c_str(),cv::VideoWriter::fourcc('H','F','Y','U'),
524 fps,cv::Size(frameW,frameH),true);
525
527 doSaveFrame=true;
528 }
529 #endif
530
531 // save to disk
532 for (unsigned int i=0; i<sz; i++)
533 {
534 buf.lock();
535 DumpItem item=buf.front();
536 buf.pop_front();
537 buf.unlock();
538
539 fdata << item.seqNumber << ' ' << item.timeStamp.getString() << ' ';
540 if (saveData) {
541 fdata << item.obj->toFile(dirName,counter++) << '\n';
542 } else {
543 std::ostringstream frame;
544 frame << "frame_" << std::setw(8) << std::setfill('0') << counter++;
545 fdata << frame.str() << '\n';
546 }
547
548#ifdef ADD_VIDEO
549 if (doSaveFrame)
550 {
552
553 // write the timecode of the frame
554 int dt=(int)(1000.0*(item.timeStamp.getStamp()-t0));
555 ftimecodes << dt << '\n';
556 }
557 #endif
558
559 delete item.obj;
560 }
561
562 cumulSize+=sz;
563 yInfo() << sz << " items stored [cumul #: " << cumulSize << "]";
564 }
565 }
566
567 void threadRelease() override
568 {
569 // call run() for the last time to flush the queue
570 closing=true;
571 run();
572
573 finfo.close();
574 fdata.close();
575
576 #ifdef ADD_VIDEO
577 if (videoOn) {
579 }
580#endif
581 }
582};
583
584
585/**************************************************************************/
587{
588private:
589 DumpThread *thread{nullptr};
590
591public:
592 DumpReporter() = default;
593 void setThread(DumpThread *thread) { this->thread=thread; }
594 void report(const PortInfo &info) override
595 {
596 if ((thread != nullptr) && info.incoming) {
597 thread->writeSource(info.sourceName, info.created);
598 }
599 }
600};
601
602
603/**************************************************************************/
604class DumpModule: public RFModule
605{
606private:
607 DumpQueue *q{nullptr};
608 DumpPort<Bottle> *p_bottle{nullptr};
609 DumpPort<Image> *p_image{nullptr};
610 DumpThread *t{nullptr};
611 DumpReporter reporter;
612 Port rpcPort;
614 bool rxTime{false};
615 bool txTime{false};
616 unsigned int dwnsample{0};
617 std::string portName;
618
619 void polish_filename(std::string &fname)
620 {
621 std::array<char,6> notallowed={':','*','?','|','>','<'};
622 for (const auto& c : notallowed)
623 {
624#if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
625 replace(fname.begin(),fname.end(),c,'_');
626#else
627 auto it = fname.begin();
628 for (; it != fname.end(); ++it) {
629 if (*it == c) {
630 *it = '_';
631 }
632 }
633#endif
634 }
635 }
636
637public:
638 DumpModule() = default;
639
640 bool configure(ResourceFinder &rf) override
641 {
642 portName=rf.check("name",Value("/dump")).asString();
643 if (portName[0] != '/') {
644 portName = "/" + portName;
645 }
646
647 bool saveData=true;
648 bool videoOn=false;
649 std::string videoType=rf.check("videoType",Value("mkv")).asString();
650
651 if (rf.check("type"))
652 {
653 std::string optTypeName=rf.find("type").asString();
654 if (optTypeName=="bottle")
655 {
656 dumptype = DumpFormat::bottle;
657 }
658 else if (optTypeName == "depth")
659 {
660 dumptype = DumpFormat::depth;
661 }
662 else if (optTypeName == "depth_compressed")
663 {
665 }
666 else if ((optTypeName == "image"))
667 {
668 dumptype = DumpFormat::image;
669 #ifdef ADD_VIDEO
670 if (rf.check("addVideo")) {
671 videoOn = true;
672 }
673#endif
674 }
675 else if ((optTypeName == "image_jpg"))
676 {
677 dumptype = DumpFormat::image_jpg;
678 #ifdef ADD_VIDEO
679 if (rf.check("addVideo")) {
680 videoOn = true;
681 }
682#endif
683 }
684 else if ((optTypeName == "image_png"))
685 {
686 dumptype = DumpFormat::image_png;
687 #ifdef ADD_VIDEO
688 if (rf.check("addVideo")) {
689 videoOn = true;
690 }
691#endif
692 }
693 #ifdef ADD_VIDEO
694 else if (optTypeName=="video")
695 {
696 dumptype = DumpFormat::image;
697 videoOn=true;
698 saveData=false;
699 }
700 #endif
701 else
702 {
703 yError() << "Error: invalid type";
704 return false;
705 }
706 }
707 else
708 {
709 dumptype = DumpFormat::bottle;
710 }
711
712 dwnsample=rf.check("downsample",Value(1)).asInt32();
713 rxTime=rf.check("rxTime");
714 txTime=rf.check("txTime");
715 std::string templateDirName=rf.check("dir")?rf.find("dir").asString():portName;
716 polish_filename(templateDirName);
717 if (templateDirName[0] != '/') {
719 }
720
721 std::string dirName;
722 if (rf.check("overwrite")) {
723 dirName="."+templateDirName;
724 } else {
725 // look for a proper directory
726 int i=0;
727 do
728 {
729 std::ostringstream checkDirName;
730 if (i > 0) {
731 checkDirName << "." << templateDirName << "_" << std::setw(5) << std::setfill('0') << i;
732 } else {
734 }
735
736 dirName=checkDirName.str();
737 i++;
738 }
739 while (!yarp::os::stat(dirName.c_str()));
740 }
741 yarp::os::mkdir_p(dirName.c_str());
742
743 q=new DumpQueue();
744 t=new DumpThread(dumptype,*q,dirName,100,saveData,videoOn,videoType,rxTime,txTime);
745
746 if (!t->start())
747 {
748 delete t;
749 delete q;
750
751 return false;
752 }
753
754 reporter.setThread(t);
755
756 if (dumptype == DumpFormat::bottle)
757 {
758 p_bottle=new DumpPort<Bottle>(*q,dwnsample,rxTime,txTime, DumpFormat::bottle);
759 p_bottle->useCallback();
760 p_bottle->open(portName);
761 p_bottle->setStrict();
762 p_bottle->setReporter(reporter);
763 }
764 else
765 {
766 p_image=new DumpPort<Image>(*q,dwnsample,rxTime,txTime, dumptype);
767 p_image->useCallback();
768 p_image->open(portName);
769 p_image->setStrict();
770 p_image->setReporter(reporter);
771 }
772
773 if (rf.check("connect"))
774 {
775 std::string srcPort=rf.find("connect").asString();
776 bool ok=Network::connect(srcPort.c_str(),
777 (dumptype == DumpFormat::bottle)? p_bottle->getName().c_str() : p_image->getName().c_str(),
778 "tcp");
779
780 std::ostringstream msg;
781 msg << "Connection to " << srcPort << " " << (ok?"successful":"failed");
782
783 if (ok) {
784 yInfo() << msg.str();
785 } else {
786 yWarning() << msg.str();
787 }
788 }
789
790 // this port serves to handle the "quit" rpc command
791 rpcPort.open(portName+"/rpc");
792 attach(rpcPort);
793
794 yInfo() << "Service yarp port: " << portName;
795 yInfo() << "Data stored in : " << dirName;
796
797 return true;
798 }
799
800 bool close() override
801 {
802 t->stop();
803
804 if (dumptype == DumpFormat::bottle)
805 {
806 p_bottle->interrupt();
807 p_bottle->close();
808 delete p_bottle;
809 }
810 else
811 {
812 p_image->interrupt();
813 p_image->close();
814 delete p_image;
815 }
816
817 rpcPort.interrupt();
818 rpcPort.close();
819
820 delete t;
821 delete q;
822
823 return true;
824 }
825
826 double getPeriod() override { return 1.0; }
827 bool updateModule() override { return true; }
828};
829
830
831/**************************************************************************/
832int main(int argc, char *argv[])
833{
835
837 rf.configure(argc,argv);
838
839 if (rf.check("help"))
840 {
841 yInfo() << "Options:";
842 yInfo() << "\t--name port: service port name (default: /dump)";
843 yInfo() << "\t--connect port: name of the port to connect the dumper to at launch time";
844 yInfo() << "\t--dir name: provide explicit name of storage directory";
845 yInfo() << "\t--overwrite : overwrite pre-existing storage directory";
846 #ifdef ADD_VIDEO
847 yInfo() << "\t--type type: type of the data to be dumped [bottle(default), image, image_jpg, image_png, video, depth, depth_compressed]";
848 yInfo() << "\t--addVideo : produce video as well (if image* is selected)";
849 yInfo() << "\t--videoType ext: produce video of specified container type [mkv(default), avi]";
850 #else
851 yInfo() << "\t--type type: type of the data to be dumped [bottle(default), image, image_jpg, image_png, depth, depth_compressed]";
852 #endif
853 yInfo() << "\t--downsample n: downsample rate (default: 1 => downsample disabled)";
854 yInfo() << "\t--rxTime : dump the receiver time instead of the sender time";
855 yInfo() << "\t--txTime : dump the sender time straightaway";
856 yInfo();
857
858 return 0;
859 }
860
861 if (!yarp.checkNetwork())
862 {
863 yError()<<"YARP server not available!";
864 return 1;
865 }
866
867 DumpModule mod;
868 return mod.runModule(rf);
869}
@ VOCAB_PIXEL_MONO_FLOAT
Definition Image.h:53
@ VOCAB_PIXEL_MONO
Definition Image.h:42
#define yInfo(...)
Definition Log.h:319
#define yError(...)
Definition Log.h:361
#define yWarning(...)
Definition Log.h:340
DumpBottle(const Bottle &b)
Definition main.cpp:67
DumpBottle()
Definition main.cpp:65
DumpBottle(const DumpBottle &obj)
Definition main.cpp:66
~DumpBottle()
Definition main.cpp:69
const DumpBottle & operator=(const DumpBottle &obj)
Definition main.cpp:68
const std::string toFile(const std::string &dirName, unsigned int cnt) override
Definition main.cpp:71
DumpImage()
Definition main.cpp:99
~DumpImage()
Definition main.cpp:103
DumpImage(const DumpImage &obj)
Definition main.cpp:100
DumpImage(const Image &img)
Definition main.cpp:101
const std::string toFile(const std::string &dirName, unsigned int cnt) override
Definition main.cpp:105
const DumpImage & operator=(const DumpImage &obj)
Definition main.cpp:102
bool close() override
Close function.
Definition main.cpp:800
bool updateModule() override
Override this to do whatever your module needs to do.
Definition main.cpp:827
bool configure(ResourceFinder &rf) override
Configure the module, pass a ResourceFinder object to the module.
Definition main.cpp:640
DumpModule()=default
double getPeriod() override
You can override this to control the approximate periodicity at which updateModule() is called by run...
Definition main.cpp:826
virtual ~DumpObj()=default
virtual void attachFormat(const DumpFormat &format)
Definition main.cpp:53
virtual const std::string toFile(const std::string &, unsigned int)=0
DumpFormat m_dump_format
Definition main.cpp:48
DumpPort(DumpQueue &Q, unsigned int _dwnsample=1, bool _rxTime=true, bool _txTime=false, DumpFormat _dataformat=DumpFormat::bottle)
Definition main.cpp:274
void unlock()
Definition main.cpp:265
void lock()
Definition main.cpp:264
DumpReporter()=default
void setThread(DumpThread *thread)
Definition main.cpp:593
void report(const PortInfo &info) override
Callback for port event/state information.
Definition main.cpp:594
DumpThread(DumpFormat _type, DumpQueue &Q, const std::string &_dirName, const int szToWrite, const bool _saveData, const bool _videoOn, const std::string &_videoType, const bool _rxTime, const bool _txTime)
Definition main.cpp:366
void writeSource(const std::string &sourceName, const bool connected)
Definition main.cpp:412
bool threadInit() override
Initialization method.
Definition main.cpp:419
void run() override
Loop function.
Definition main.cpp:485
void threadRelease() override
Release method.
Definition main.cpp:567
std::string getString() const
Definition main.cpp:223
DumpTimeStamp()=default
void setTxStamp(const double stamp)
Definition main.cpp:212
double getStamp() const
Definition main.cpp:213
void setRxStamp(const double stamp)
Definition main.cpp:211
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:217
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of port.
bool getEnvelope(PortReader &envelope) override
Get the envelope information (e.g., a timestamp) from the last message received on the port.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void setReporter(PortReport &reporter) override
Set a callback to be called upon any future connections and disconnections to/from the port.
void useCallback(TypedReaderCallback< T > &callback) override
Set an object whose onRead method will be called when data is available.
void setStrict(bool strict=true) override
Call this to strictly keep all messages, or allow old ones to be quietly dropped.
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
An abstraction for a periodic thread.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
Information about a port connection or event.
Definition PortInfo.h:25
A base class for objects that want information about port status changes.
Definition PortReport.h:25
A mini-server for network communication.
Definition Port.h:46
void interrupt() override
Interrupt any current reads or writes attached to the port.
Definition Port.cpp:347
void close() override
Stop port activity.
Definition Port.cpp:330
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A base-class for standard YARP modules that supports ResourceFinder.
Definition RFModule.h:20
virtual int runModule()
Calls updateModule() until that returns false.
Definition RFModule.cpp:323
virtual bool attach(yarp::os::Port &source)
Make any input from a Port object go to the respond() method.
Definition RFModule.cpp:456
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21
A single value (typically within a Bottle).
Definition Value.h:44
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
Base class for storing images.
Definition Image.h:79
virtual int getPixelCode() const
Gets pixel type identifier.
Definition Image.cpp:375
int main(int argc, char *argv[])
Definition main.cpp:832
DumpObj * factory(Bottle &obj)
Definition main.cpp:81
DumpFormat
Definition main.cpp:41
STL namespace.
::cv::Mat toCvMat(const yarp::sig::Image &yarpImage)
Convert a yarp::sig::FlexImage to a cv::Mat object.
Definition Cv-inl.h:84
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition Vocab32.cpp:33
An interface to the operating system, including Port based communication.
Definition OSTestMsg.cpp:13
int stat(const char *path)
Portable wrapper for the stat() function.
Definition Os.cpp:78
int mkdir_p(const char *p, int ignoreLevels=0)
Create a directory and all parent directories needed.
Definition Os.cpp:35
@ FORMAT_NUMERIC_COMPRESSED
Definition ImageFile.h:22
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
The main, catch-all namespace for YARP.
Definition dirs.h:16
DumpObj * obj
Definition main.cpp:249
DumpTimeStamp timeStamp
Definition main.cpp:248
int seqNumber
Definition main.cpp:247