Open justClouds opened 5 years ago
syscall.h is used for getting thread id. Are you using Non-Os or RTOS?
I'm using RTOS
Could you attach a sample project?
I just started coding a new program to handle RS485 data from a SolarEdge inverter and noticed the include error, hence my question. My aim is to change the plog code to 'log' to a serial port, since I use an embedded device without file system.
I see. Then you have to fix everything multithreading related. You need to remove syscall.h
and gettid
.
Also I'm not sure about iostream
functionality. Anyways, you can replace it with sprintf
.
I see. Then you have to fix everything multithreading related. You need to remove
syscall.h
andgettid
.
Yes, I already did that, but now I'm looking into iostream and related stuff and trying to find out how to send to a serial port. I like to keep the 'stringstream functionality' in tact.
Hi there, have you found a solution for logging to a µC Serial port? I'm looking into that exact problem at the moment and just found your issue and was wondering...
@MarkusFelix I've order a couple of Arduino boards (I'm expecting the delivery in a couple of days), so I'll be able to take a look at PlatformIO.
@MarkusFelix Could you show your platformio.ini file content?
I do not have a running build with a platformio.ini file I could share ☹️ . Im trying to get your project to run on another hardware platform. The basic idea is the same, PLOG tries to include some threading stuff but I'm not using an RTOS but one fixed, plain core of the µC. I'm not shure if that use case is in scope for plog or if I'm better off forking your code to build a Serial implementation - but for maintainability I would like to avoid that 😄
@MarkusFelix What platform and framework do you use?
I'm using an 32-Bit TriCore Aurix with plain old CC14
@MarkusFelix I see. What functions do they use to write data to serial ports?
My serial write ln in the abstraction looks like this:
bool serial_interface_aurix_write(IfxAsclin_Asc *asc, const fixed::String<> &str) { str_new.append("\n"); Ifx_SizeT count = str_new.length() + 1; bool res = IfxAsclin_Asc_write(asc, str_new.c_str(), &count, TIME_INFINITE); while (asc->txInProgress) { IfxAsclin_Asc_isrTransmit(asc); } return res; }
But that part could easily be a custom appender I suppose - the main problem is, as stated by you above, the use of threads...
I can make a macro definition that turns off thread related info. I think that will do the trick.
I do believe thats the only mayor change that would allow plogto run on embedded systems - I've read through the code and haven't found and dynamic allocations that are not guarded by ifdef _WIN32
statements so those should be fine as well.
@MarkusFelix I added automatic checks for threading functionality of a platform. I successfully built and run plog
on ESP32 and ESP8266. Please try it.
Do you have any plans to make it work on other boards? I've made a minimum example of using plog on Raspberry Pi Pico.
Almost everything works fine, but note that #define _GNU_SOURCE 1
is required by vasprintf
at Record.h
@u1F992 Yes. Thank you for the minimum example of using plog on Raspberry Pi Pico!
The plan is:
Okay, I understand.
Don't know much about it, it seems like a good idea to me to define an Appender that takes Stream type reference to write log in various ports on various boards (ref)
namespace plog
{
template <class Formatter>
class PLOG_LINKAGE_HIDDEN ArduinoAppender : public IAppender
{
public:
ArduinoAppender(Stream &stream) : m_stream(stream)
{
}
void write(const Record &record) PLOG_OVERRIDE
{
m_stream.print(Formatter::format(record).c_str());
}
private:
Stream &m_stream;
};
}
static plog::ArduinoAppender<plog::TxtFormatter> foo(Serial);
static plog::ArduinoAppender<plog::TxtFormatter> bar(Serial1);
static plog::ArduinoAppender<plog::TxtFormatter> baz(Serial2);
// ...
... so on.
By the way, how about _GNU_SOURCE
. Is there a good alternative way to fix it?
@u1F992 Yes, Appender should be able to work with different Streams. Your implementation is good.
_GNU_SOURCE
enables non-POSIX vasprintf
that is available in GNU and BSD. I think the correct way is to check _GNU_SOURCE
and use vasprintf
or its emulation like it's already done for Windows.
Related issue: #229
Thanks. I'll create a pull request & take a look at the issue later.
I try to use plog in a C++ program targeted at an ESP8266 SoC. Development, build/compile and flash to embedded device from Visual Studio Code on Windows 10 (64-bits). With a PlatformIO extension the Espressif SDK, libraries and headers for this device are installed in the project directory. Plog tries to include <sys/syscall.h> which usually only exist on Linux systems and cannot be found on my system. Is there a 'quick fix' for this? What is using syscall.h entries?