plog icon indicating copy to clipboard operation
plog copied to clipboard

Using plog in VS Code w/PlatformIO

Open ghost opened this issue 6 years ago • 23 comments

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?

ghost avatar Nov 13 '18 21:11 ghost

syscall.h is used for getting thread id. Are you using Non-Os or RTOS?

SergiusTheBest avatar Nov 13 '18 22:11 SergiusTheBest

I'm using RTOS

Justclouds avatar Nov 13 '18 22:11 Justclouds

Could you attach a sample project?

SergiusTheBest avatar Nov 14 '18 18:11 SergiusTheBest

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.

Justclouds avatar Nov 15 '18 19:11 Justclouds

I see. Then you have to fix everything multithreading related. You need to remove syscall.h and gettid.

SergiusTheBest avatar Nov 15 '18 20:11 SergiusTheBest

Also I'm not sure about iostream functionality. Anyways, you can replace it with sprintf.

SergiusTheBest avatar Nov 15 '18 20:11 SergiusTheBest

I see. Then you have to fix everything multithreading related. You need to remove syscall.h and gettid.

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.

Justclouds avatar Nov 15 '18 20:11 Justclouds

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 avatar Jan 12 '21 12:01 MarkusFelix

@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.

SergiusTheBest avatar Jan 12 '21 13:01 SergiusTheBest

@MarkusFelix Could you show your platformio.ini file content?

SergiusTheBest avatar Jan 16 '21 10:01 SergiusTheBest

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 avatar Jan 18 '21 12:01 MarkusFelix

@MarkusFelix What platform and framework do you use?

SergiusTheBest avatar Jan 18 '21 12:01 SergiusTheBest

I'm using an 32-Bit TriCore Aurix with plain old CC14

MarkusFelix avatar Jan 18 '21 12:01 MarkusFelix

@MarkusFelix I see. What functions do they use to write data to serial ports?

SergiusTheBest avatar Jan 18 '21 12:01 SergiusTheBest

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...

MarkusFelix avatar Jan 18 '21 12:01 MarkusFelix

I can make a macro definition that turns off thread related info. I think that will do the trick.

SergiusTheBest avatar Jan 18 '21 12:01 SergiusTheBest

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 avatar Jan 18 '21 12:01 MarkusFelix

@MarkusFelix I added automatic checks for threading functionality of a platform. I successfully built and run plog on ESP32 and ESP8266. Please try it.

SergiusTheBest avatar Jan 21 '21 15:01 SergiusTheBest

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 avatar Mar 06 '23 10:03 u1f992

@u1F992 Yes. Thank you for the minimum example of using plog on Raspberry Pi Pico!

The plan is:

  • add Arduino-specific appenders
  • make a working Arduino sample (now it's just a stub for CI)
  • add plog to the platformio package registry
  • add more boards to CI (currently CI builds for esp8266 and esp32)

SergiusTheBest avatar Mar 06 '23 11:03 SergiusTheBest

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 avatar Mar 07 '23 11:03 u1f992

@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

SergiusTheBest avatar Mar 07 '23 13:03 SergiusTheBest

Thanks. I'll create a pull request & take a look at the issue later.

u1f992 avatar Mar 07 '23 13:03 u1f992