JeVois
1.17
JeVois Smart Embedded Machine Vision Toolkit
|
Share this page: |
|
|
|
 |
 |
|
Go to the documentation of this file.
35 template <
int Level>
char const * levelStr();
36 template <>
char const * levelStr<LOG_DEBUG>() {
return "DBG"; }
37 template <>
char const * levelStr<LOG_INFO>() {
return "INF"; }
38 template <>
char const * levelStr<LOG_ERR>() {
return "ERR"; }
39 template <>
char const * levelStr<LOG_CRIT>() {
return "FTL"; }
42 #ifdef JEVOIS_USE_SYNC_LOG
46 std::mutex logOutputMutex;
50 {
LFATAL(
"Cannot set Engine for logs when JeVois has been compiled with -D JEVOIS_USE_SYNC_LOG"); }
52 {
LINFO(
"Terminating Log service"); }
54 #else // JEVOIS_USE_SYNC_LOG
65 LogCore() : itsBuffer(10000), itsRunning(true)
66 #ifdef JEVOIS_LOG_TO_FILE
67 , itsStream(
"jevois.log")
80 itsBuffer.push(
"Terminating Log service");
90 std::string msg = itsBuffer.pop();
91 #ifdef JEVOIS_LOG_TO_FILE
92 itsStream << msg << std::endl;
94 #ifdef JEVOIS_PLATFORM
98 std::cerr << msg <<
'\r' << std::endl;
100 std::cerr << msg << std::endl;
103 if (itsEngine) itsEngine->sendSerial(msg,
true);
111 LINFO(
"Terminating log facility.");
115 volatile bool itsRunning;
116 std::future<void> itsRunFuture;
117 #ifdef JEVOIS_LOG_TO_FILE
118 std::ofstream itsStream;
126 #endif // JEVOIS_USE_SYNC_LOG
134 std::string
const fn(fullFileName);
135 size_t const lastSlashPos = fn.rfind(
'/');
136 size_t const lastDotPos = fn.rfind(
'.');
137 std::string
const partialFileName = fn.substr(lastSlashPos+1, lastDotPos-lastSlashPos-1);
140 itsLogStream << levelStr<Level>() <<
' ' << partialFileName <<
"::" << functionName <<
": ";
144 #ifdef JEVOIS_USE_SYNC_LOG
149 std::lock_guard<std::mutex> guard(jevois::logOutputMutex);
150 std::string
const msg = itsLogStream.str();
151 std::cerr << msg << std::endl;
152 if (itsOutStr) *itsOutStr = msg;
155 #else // JEVOIS_USE_SYNC_LOG
160 std::string
const msg = itsLogStream.str();
161 LogCore::instance().itsBuffer.push(msg);
162 if (itsOutStr) *itsOutStr = msg;
164 #endif // JEVOIS_USE_SYNC_LOG
170 itsLogStream << static_cast<int>(out_item);
178 itsLogStream << static_cast<int>(out_item);
196 if (prefix.empty() ==
false) pfx = prefix +
": ";
201 catch (std::exception
const & e)
203 LERROR(pfx <<
"Passing through std::exception: " << e.what());
207 catch (boost::python::error_already_set & e)
209 LERROR(pfx <<
"Received exception from the Python interpreter:");
212 for (std::string
const & li : lines)
LERROR(
" " << li);
218 LERROR(pfx <<
"Passing through unknown exception");
227 if (prefix.empty() ==
false) pfx = prefix +
": ";
229 std::vector<std::string> retvec;
234 catch (std::exception
const & e)
236 retvec.emplace_back(pfx +
"Caught std::exception [" + std::string(e.what()) +
']');
239 catch (boost::python::error_already_set & e)
241 retvec.emplace_back(pfx +
"Caught exception from the Python interpreter:");
244 for (std::string
const & li : lines) retvec.emplace_back(
" " + li);
249 retvec.emplace_back(pfx +
"Caught unknown exception");
254 for (std::string & m : retvec) {
LERROR(m); ret += m +
"\n"; }
262 if (videoerrimg.
valid() ==
false) {
LERROR(
"Cannot draw in empty image -- IGNORED");
return; }
279 if (videoerrimg.
width <= 352 || videoerrimg.
height <= 240)
281 else if (videoerrimg.
width <= 640 || videoerrimg.
height <= 480)
286 std::vector<std::string> lines =
jevois::split(errmsg,
"\\n");
287 for (std::string & m : lines)
290 unsigned int nchar = (videoerrimg.
width - 6) / fw;
291 while (m.size() > nchar)
295 m = m.substr(nchar, m.npos);
308 if (itsMutex.try_lock_for(std::chrono::seconds(5)) ==
false)
311 throw std::runtime_error(
"FATAL DEADLOCK ERROR");
317 { itsMutex.unlock(); }
#define JEVOIS_WAIT_GET_FUTURE(f)
Wait for a future to become ready for 5 seconds, get(), warn and ignore exception,...
unsigned int whiteColor(unsigned int fcc)
Return a value that corresponds to white for the given video format.
void drawDisk(RawImage &img, int x, int y, unsigned int rad, unsigned int col)
Draw a disk in a YUYV image.
void clear()
Clear the pixels to all black.
std::vector< std::string > split(std::string const &input, std::string const ®ex="\\s+")
Split string into vector of tokens using a regex to specify what to split on; default regex splits by...
void warnAndRethrowException(std::string const &prefix="")
Convenience function to catch an exception, issue some LERROR (depending on type),...
~timed_lock_guard()
Destructor, unlocks the mutex.
Thread-safe synchronized producer/consumer queue.
Font
Available fonts for writeText()
void drawErrorImage(std::string const &errmsg, RawImage &videoerrimg)
Display an error message into a RawImage.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
~Log()
Close the Log, outputting the aggregated message.
bool valid() const
Check whether the image has a valid pixel buffer.
timed_lock_guard(std::timed_mutex &mtx, char const *file, char const *func)
Constructor, locks the mutex or throw if it cannot be locked before timeout.
int traceLevel
Current trace level.
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async_little(Function &&f, Args &&... args)
Async execution using a thread pool.
Data collection mode RAW means that the latest available raw data is returned each time hence timing may not be very accurate depending on how regularly grate into a FIFO and and accumulates resulting output data into the IMU s internal FIFO buffer at a fixed rate This parameter can only be set in a module s params cfg file
unsigned int width
Image width in pixels.
void writeText(RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
Write some text in an image.
void logSetEngine(Engine *e)
Set an Engine so that all log messages will be forwarded to its serial ports.
JeVois processing engine - gets images from camera sensor, processes them, and sends results over USB...
std::string warnAndIgnoreException(std::string const &prefix="")
Convenience function to catch an exception, issue some LERROR (depending on type),...
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
unsigned int height
Image height in pixels.
Log< Level > & operator<<(T const &out_item)
Overloaded stream input operator for any type that has operator<< defined for ostream.
int logLevel
Current log level.
Log(char const *fullFileName, char const *functionName, std::string *outstr=nullptr)
Construct a new Log, adding a prefix to the log stream.
A generic singleton class to enforce a single instance of an object.
unsigned int fmt
Pixel format as a V4L2_PIX_FMT_XXX.
std::string getPythonExceptionString(boost::python::error_already_set &)
Python exception translation to string so we can print the traceback to our serlog stream.
void logEnd()
Terminate log service.
void drawLine(RawImage &img, int x1, int y1, int x2, int y2, unsigned int thick, unsigned int col)
Draw a line in a YUYV image.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.