hideakitai / MsgPacketizer

msgpack based serializer / deserializer + packetize for Arduino, ROS, and more
MIT License
79 stars 10 forks source link

Cannot compile library on Mega 2560 #16

Closed KennethThompson closed 9 months ago

KennethThompson commented 9 months ago

Attempting to compile some examples on a 2560 produces numerous compile errors. This is a problem my code is facing, but the example below reproduces the issue.

Try the following code with 2560 set as a target:


#include <ArduinoJson.h>  // include before MsgPacketizer.h

#define MSGPACKETIZER_DEBUGLOG_ENABLE
#include <MsgPacketizer.h>
#include <Ethernet.h>

const uint8_t msg_index = 0x12;

// Ethernet stuff
uint8_t mac[] = {0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45};
const IPAddress ip(192, 168, 0, 201);
// Ethernet with useful options
// const IPAddress dns (192, 168, 0, 1);
// const IPAddress gateway (192, 168, 0, 1);
// const IPAddress subnet (255, 255, 255, 0);

const char* host = "192.168.0.201";  // loop back
const int port = 54321;

EthernetUDP client;

void setup() {
    Serial.begin(115200);
    delay(2000);

    // Ethernet stuff
    Ethernet.begin(mac, ip);
    // Ethernet with useful options
    // Ethernet.begin(mac, ip, dns, gateway, subnet); // full
    // Ethernet.setRetransmissionCount(4); // default: 8[times]
    // Ethernet.setRetransmissionTimeout(50); // default: 200[ms]

    // start client
    client.begin(port);

    // only subscribing ArduinoJson with lambda is allowed
    // because subscribing JsonDocument as global object is not reccomended
    // see https://arduinojson.org/v6/how-to/reuse-a-json-document/
    MsgPacketizer::subscribe(client, msg_index,
        [&](const StaticJsonDocument<200>& doc) {
            Serial.print(doc["us"].as<uint32_t>());
            Serial.print(" ");
            Serial.print(doc["usstr"].as<String>());
            Serial.print(" [");
            Serial.print(doc["now"][0].as<double>());
            Serial.print(" ");
            Serial.print(doc["now"][1].as<double>());
            Serial.println("]");
        });

    // you can also use DynamicJsonDocument if you want
    // MsgPacketizer::subscribe(client, msg_index,
    //     [&](const DynamicJsonDocument& doc) {
    //         Serial.print(doc["us"].as<uint32_t>());
    //         Serial.print(" ");
    //         Serial.print(doc["usstr"].as<String>());
    //         Serial.print(" [");
    //         Serial.print(doc["now"][0].as<double>());
    //         Serial.print(" ");
    //         Serial.print(doc["now"][1].as<double>());
    //         Serial.println("]");
    //     });

    // or of course you can bind to variables directly
    // MsgPacketizer::subscribe(client, msg_index,
    //     [&](const MsgPack::map_size_t,
    //         const String& k_us, const uint32_t v_us,
    //         const String& k_usstr, const String& v_usstr,
    //         const String& k_now, const MsgPack::arr_size_t, const double now0, const double now1) {
    //         Serial.print(v_us);
    //         Serial.print(" ");
    //         Serial.print(v_usstr);
    //         Serial.print(" [");
    //         Serial.print(now0);
    //         Serial.print(" ");
    //         Serial.print(now1);
    //         Serial.println("]");
    //     });
}

void loop() {
    static uint32_t prev_ms = millis();
    if (millis() > prev_ms + 1000) {
        prev_ms = millis();

        uint32_t now = micros();

        StaticJsonDocument<200> doc;
        // you can also use DynamicJsonDocument if you want
        // DynamicJsonDocument doc(200);
        doc["us"] = now;
        doc["usstr"] = String(now) + "[us]";
        JsonArray data = doc.createNestedArray("now");
        data.add(now * 0.001);
        data.add(now * 0.001 * 0.001);

        // only `send` ArduinoJson is supported (you can `publish` but not recommended)
        // because ArduinoJson is designed to be throw-away objects
        // please use standard `publish` without ArduinoJson
        // see https://arduinojson.org/v6/how-to/reuse-a-json-document/ for the detail
        MsgPacketizer::send(client, host, port, msg_index, doc);

        // or you can send them directly
        // MsgPacketizer::send(client, host, port, msg_index,
        //     MsgPack::map_size_t(3),
        //     "us", now,
        //     "usstr", String(now) + "[us]",
        //     "now", MsgPack::arr_size_t(2), now * 0.001, now * 0.001 * 0.001);
    }

    // must be called to trigger callback and publish data
    MsgPacketizer::update();
}

Observe these compile errors:

In file included from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/type_traits.h:411:0,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits.h:36,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog.h:14,
                 from /home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer.h:64,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:4:
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/functional.h: In instantiation of 'R arx::stdx::function<R(Args ...)>::operator()(Args ...) const [with R = void; Args = {const ArduinoJson::V702L1::DynamicJsonDocument&}]':
/home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer/Subscriber.h:150:33:   required from here
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/functional.h:133:53: error: call of overloaded 'forward<const ArduinoJson::V702L1::DynamicJsonDocument&>(const ArduinoJson::V702L1::DynamicJsonDocument&)' is ambiguous
             return table->invoke(data, forward<Args>(args)...);
                                        ~~~~~~~~~~~~~^~~~~~
In file included from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits.h:36:0,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog.h:14,
                 from /home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer.h:64,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:4:
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/type_traits.h:153:19: note: candidate: constexpr T&& arx::stdx::forward(typename arx::stdx::remove_reference<T>::type&) [with T = const ArduinoJson::V702L1::DynamicJsonDocument&; typename arx::stdx::remove_reference<T>::type = const ArduinoJson::V702L1::DynamicJsonDocument]
     constexpr T&& forward(typename remove_reference<T>::type& t) noexcept
                   ^~~~~~~
In file included from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Memory/StringPool.hpp:10:0,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Memory/ResourceManager.hpp:8,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/JsonVariantConst.hpp:10,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRefBase.hpp:9,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp:7,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp:7,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson.hpp:29,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson.h:9,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:1:
/home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Polyfills/utility.hpp:14:5: note: candidate: T&& ArduinoJson::V702L1::detail::forward(typename ArduinoJson::V702L1::detail::remove_reference<T>::type&) [with T = const ArduinoJson::V702L1::DynamicJsonDocument&; typename ArduinoJson::V702L1::detail::remove_reference<T>::type = const ArduinoJson::V702L1::DynamicJsonDocument]
 T&& forward(typename remove_reference<T>::type& t) noexcept {
     ^~~~~~~
In file included from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/type_traits.h:411:0,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits.h:36,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog.h:14,
                 from /home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer.h:64,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:4:
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/functional.h: In instantiation of 'R arx::stdx::function<R(Args ...)>::operator()(Args ...) const [with R = void; Args = {unsigned char, const ArduinoJson::V702L1::DynamicJsonDocument&}]':
/home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer/Subscriber.h:176:40:   required from here
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/functional.h:133:53: error: call of overloaded 'forward<const ArduinoJson::V702L1::DynamicJsonDocument&>(const ArduinoJson::V702L1::DynamicJsonDocument&)' is ambiguous
             return table->invoke(data, forward<Args>(args)...);
                                        ~~~~~~~~~~~~~^~~~~~
In file included from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits.h:36:0,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog.h:14,
                 from /home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer.h:64,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:4:
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/type_traits.h:153:19: note: candidate: constexpr T&& arx::stdx::forward(typename arx::stdx::remove_reference<T>::type&) [with T = const ArduinoJson::V702L1::DynamicJsonDocument&; typename arx::stdx::remove_reference<T>::type = const ArduinoJson::V702L1::DynamicJsonDocument]
     constexpr T&& forward(typename remove_reference<T>::type& t) noexcept
                   ^~~~~~~
In file included from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Memory/StringPool.hpp:10:0,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Memory/ResourceManager.hpp:8,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/JsonVariantConst.hpp:10,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRefBase.hpp:9,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp:7,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp:7,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson.hpp:29,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson.h:9,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:1:
/home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Polyfills/utility.hpp:14:5: note: candidate: T&& ArduinoJson::V702L1::detail::forward(typename ArduinoJson::V702L1::detail::remove_reference<T>::type&) [with T = const ArduinoJson::V702L1::DynamicJsonDocument&; typename ArduinoJson::V702L1::detail::remove_reference<T>::type = const ArduinoJson::V702L1::DynamicJsonDocument]
 T&& forward(typename remove_reference<T>::type& t) noexcept {
     ^~~~~~~
In file included from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/type_traits.h:411:0,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits.h:36,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog.h:14,
                 from /home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer.h:64,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:4:
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/functional.h: In instantiation of 'R arx::stdx::function<R(Args ...)>::operator()(Args ...) const [with R = void; Args = {const ArduinoJson::V702L1::StaticJsonDocument<200>&}]':
/home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer/Subscriber.h:138:29:   required from 'void arduino::msgpack::msgpacketizer::detail::subscribe_staticjson(const uint8_t*, const arx::stdx::function<void(const ArduinoJson::V702L1::StaticJsonDocument<N>&)>&) [with unsigned int N = 200; uint8_t = unsigned char]'
/home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer/Subscriber.h:371:41:   required from 'arduino::msgpack::msgpacketizer::detail::subscribe(S&, uint8_t, arx::stdx::function<void(const ArduinoJson::V702L1::StaticJsonDocument<N>&)>&&)::<lambda(const uint8_t*, size_t)> [with S = EthernetUDP; unsigned int N = 200; uint8_t = unsigned char; size_t = unsigned int]'
/home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer/Subscriber.h:370:58:   required from 'struct arduino::msgpack::msgpacketizer::detail::subscribe(S&, uint8_t, arx::stdx::function<void(const ArduinoJson::V702L1::StaticJsonDocument<N>&)>&&) [with S = EthernetUDP; unsigned int N = 200; uint8_t = unsigned char]::<lambda(const uint8_t*, size_t)>'
/home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer/Subscriber.h:370:38:   required from 'void arduino::msgpack::msgpacketizer::detail::subscribe(S&, uint8_t, arx::stdx::function<void(const ArduinoJson::V702L1::StaticJsonDocument<N>&)>&&) [with S = EthernetUDP; unsigned int N = 200; uint8_t = unsigned char]'
/home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer/Subscriber.h:405:30:   required from 'arx::stdx::enable_if_t<arx::is_callable<T>::value> arduino::msgpack::msgpacketizer::subscribe(S&, uint8_t, F&&) [with S = EthernetUDP; F = setup()::<lambda(const ArduinoJson::V702L1::StaticJsonDocument<200>&)>; arx::stdx::enable_if_t<arx::is_callable<T>::value> = void; uint8_t = unsigned char]'
/tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:49:10:   required from here
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/functional.h:133:53: error: call of overloaded 'forward<const ArduinoJson::V702L1::StaticJsonDocument<200>&>(const ArduinoJson::V702L1::StaticJsonDocument<200>&)' is ambiguous
             return table->invoke(data, forward<Args>(args)...);
                                        ~~~~~~~~~~~~~^~~~~~
In file included from /home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits.h:36:0,
                 from /home/ken/Arduino/libraries/DebugLog/DebugLog.h:14,
                 from /home/ken/Arduino/libraries/MsgPacketizer/MsgPacketizer.h:64,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:4:
/home/ken/Arduino/libraries/DebugLog/DebugLog/util/ArxTypeTraits/ArxTypeTraits/type_traits.h:153:19: note: candidate: constexpr T&& arx::stdx::forward(typename arx::stdx::remove_reference<T>::type&) [with T = const ArduinoJson::V702L1::StaticJsonDocument<200>&; typename arx::stdx::remove_reference<T>::type = const ArduinoJson::V702L1::StaticJsonDocument<200>]
     constexpr T&& forward(typename remove_reference<T>::type& t) noexcept
                   ^~~~~~~
In file included from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Memory/StringPool.hpp:10:0,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Memory/ResourceManager.hpp:8,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/JsonVariantConst.hpp:10,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRefBase.hpp:9,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp:7,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp:7,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson.hpp:29,
                 from /home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson.h:9,
                 from /tmp/.arduinoIDE-unsaved202413-2067-80ztgm.3pekm/sketch_feb3a/sketch_feb3a.ino:1:
/home/ken/Arduino/libraries/ArduinoJson/src/ArduinoJson/Polyfills/utility.hpp:14:5: note: candidate: T&& ArduinoJson::V702L1::detail::forward(typename ArduinoJson::V702L1::detail::remove_reference<T>::type&) [with T = const ArduinoJson::V702L1::StaticJsonDocument<200>&; typename ArduinoJson::V702L1::detail::remove_reference<T>::type = const ArduinoJson::V702L1::StaticJsonDocument<200>]
 T&& forward(typename remove_reference<T>::type& t) noexcept {
     ^~~~~~~

exit status 1

Compilation error: exit status 1
hideakitai commented 9 months ago

What's the version of ArduinoJson?

KennethThompson commented 9 months ago

What's the version of ArduinoJson?

7.0.2

KennethThompson commented 9 months ago

What's the version of ArduinoJson?

I tried compiling examples from ArduinoJson and I can't get the error to reappear- not sure if that is helpful.

KennethThompson commented 9 months ago

What's the version of ArduinoJson?

Apparently, 'Arduino Nano' board also triggers the compile errors above. Maybe it is using the same DebugLog conflicting code as the 2560?

hideakitai commented 9 months ago

forward() may be conflicting with ArduinoJson (and ArxTypeTraits). Could you try ArduinoJson v6.x.x?

KennethThompson commented 9 months ago

forward() may be conflicting with ArduinoJson (and ArxTypeTraits). Could you try ArduinoJson v6.x.x?

Funny you mention that. I tried a few different 6.x versions and all of them have the same compiler error. For now, we're moving the #include after the MsgPacketizer include as we are not using your automatic json parsing.

hideakitai commented 9 months ago

It should compile up to ArduinoJson v6.20.1, have you tried that?

Also, why are you including ArduinoJson when you don't need it, it should only be included in examples that use ArduinoJson, so please remove it.

KennethThompson commented 9 months ago

It should compile up to ArduinoJson v6.20.1, have you tried that?

Also, why are you including ArduinoJson when you don't need it, it should only be included in examples that use ArduinoJson, so please remove it.

The example still does not compile with 6.20.1 installed. At some point, we decided to not use the integrated JSON abilities of MsgPacketizer and just forgot. We still use ArduinoJson, but were not concerned with whether we included it before or after MsgPacketizer. It would be nice if we could use the ArduinoJson features of MsgPacketizer in the future- but maybe that will be limited to specific boards if we need it.

hideakitai commented 9 months ago

Fixed. Please update your dependencies

KennethThompson commented 9 months ago

Excellent! Thank you- will be testing ASAP

On Sun, Feb 4, 2024 at 4:02 PM Hideaki Tai @.***> wrote:

Fixed. Please update your dependencies

  • DebugLog v0.8.0
  • ArxTypeTraits v0.3.1

— Reply to this email directly, view it on GitHub https://github.com/hideakitai/MsgPacketizer/issues/16#issuecomment-1925912994, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4HTDOGKHOFR5A5SOLUKIDYR7ZNDAVCNFSM6AAAAABCYDPNACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRVHEYTEOJZGQ . You are receiving this because you authored the thread.Message ID: @.***>