CAN bus implementation#5120
Conversation
|
@bclbruno I have assigned Plugin ID |
| for (int i = 0; i < valueCount; ++i) { | ||
| if (lines[i].length() == 0) { | ||
| lines[i] = concat(F("val"), i + 1); | ||
| } | ||
| ExtraTaskSettings.setTaskDeviceValueName(i, lines[i]); | ||
| } |
There was a problem hiding this comment.
Please use Uncrustify to format the sources (exception: external libraries), to avoid mis-alignments like these.
| String log_debug = F("Disconnected"); | ||
| addLogMove(LOG_LEVEL_INFO, log_debug); |
There was a problem hiding this comment.
To preserve code-size and memory use, this can be a single statement, no need to instantiate that String first.
addLog(LOG_LEVEL_INFO, F("Disconnected"));
|
|
||
| case ESPEasy_cmd_e::sendcan: COMMAND_CASE_A(Command_CAN_SendCAN, -1); //CAN.h | ||
| case ESPEasy_cmd_e::sendtocan: COMMAND_CASE_A(Command_CAN_SendToCAN, -1); //CAN.h | ||
|
|
There was a problem hiding this comment.
- There's a missing
#if FEATURE_CANhere - Commands are in this switch statement in alphabetical order, by default
| "wdconfig|" | ||
| "wdread|" | ||
| #endif // ifndef LIMIT_BUILD_SIZE | ||
| #ifdef FEUTER_CAN |
There was a problem hiding this comment.
- That's probably a typo, should better be
#if FEATURE_CAN - We've stopped using
#ifdeffor feature-flags, to make handling defaults possible, that can also be controller from aCustom.hfile, to be explicitly enabled (1) or disabled (0)
| #ifdef FEATURE_CAN | ||
| #define USES_C020 //CAN | ||
| #define USES_C021 | ||
| #define USES_P155 | ||
| #endif |
There was a problem hiding this comment.
This should be like:
#ifndef FEATURE_CAN
#ifdef ESP32
#define FEATURE_CAN 1
#endif
#ifdef ESP8266
#define FEATURE_CAN 0 // Default disabled for ESP8266 for size reasons
#endif
#endif
#if FEATURE_CAN
#ifndef USES_C022 // CAN Controller
#define USE_C022
#endif
#ifndef USES_P174
#define USES_P174 // CAN Import plugin
#endif
#endif
(For Plugin, Controller and Notifiers we still use #ifdef USES_... checks...)
Not sure why you also try to enable Controller C021? If that's one you also created yourself, then it should probably get ID C023, as C021 is reserved for a (planned) LoRa controller 🤔
| uint8_t CAN_Tx_pin = -1; | ||
| uint8_t CAN_Rx_pin = -1; | ||
| long CAN_baudrate = DEFAULT_CAN_BAUDRATE; | ||
| int CAN_node_id = 0; |
There was a problem hiding this comment.
I think this belongs in the CAN Controller, where the CAN Importer can get it's pins from, if needed, as the CAN Controller seems t o be a requirement for the importer to function.
44f2f69 to
0bc2b45
Compare
Current implementation can only build on ESP32-classic. May need significant code changes for ESP32C3/C6/S2/S3
| #if FEATURE_CAN | ||
| #define USES_C022 //CAN | ||
| #define USES_P174 | ||
| #endif |
There was a problem hiding this comment.
This is a duplicate for lines 3431..3441
| addLogMove(LOG_LEVEL_INFO, log); | ||
|
|
||
| for (taskIndex_t x = 0; x < TASKS_MAX; x++) { | ||
| constexpr pluginID_t PLUGIN_ID_CAN_HELPER(155); |
There was a problem hiding this comment.
That 155 seems to be a typo, AFAICS the helper plugin (now) has PluginID 174.
| { | ||
| String lines[VARS_PER_TASK]; | ||
|
|
||
| addRowLabel(F("Node")); |
There was a problem hiding this comment.
For the PLUGIN_WEBFORM_SAVE function, no new UI elements should be added.
| case PLUGIN_READ: | ||
| { | ||
|
|
||
| addLogMove(LOG_LEVEL_DEBUG, strformat( |
There was a problem hiding this comment.
DEBUG level logging must be wrapped with #ifndef BUILD_NO_DEBUG / #endif
|
|
||
| for (int i = 0; i < VARS_PER_TASK; ++i) { | ||
| lines[i] = webArg(concat(F("p174_value"), i)); | ||
| if (lines[i].length() == 0) { |
There was a problem hiding this comment.
The String class has an isEmpty() method available (multiple occurrences found)
|
There are quite a few merge conflicts. |
|
I tried to merge it as it also required some manual interactions. Hopefully I didn't break anything :) |
|
Hopefully the build will now complete successfully. There are also examples (now, likely not when you started the PR) for using TWAI in arduino-esp32: https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP32/examples/TWAI This way it doesn't depend on such highly platform specific code as used in the lib currently included in the PR. I did have to move the settings members to the end of the settings struct, as there have been some network related settings added to the Settings struct and the original location would have rendered existing settings without this PR code incompatible. Right now the code is up-to-date with the current |
TODOs: