-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CAN bus implementation #5120
base: mega
Are you sure you want to change the base?
CAN bus implementation #5120
Conversation
@bclbruno I have assigned Plugin ID |
src/_P155_CAN_helper.ino
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Uncrustify to format the sources (exception: external libraries), to avoid mis-alignments like these.
src/_P155_CAN_helper.ino
Outdated
String log_debug = F("Disconnected"); | ||
addLogMove(LOG_LEVEL_INFO, log_debug); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There's a missing
#if FEATURE_CAN
here - Commands are in this switch statement in alphabetical order, by default
@@ -276,6 +276,10 @@ const char Internal_commands_w[] PROGMEM = | |||
"wdconfig|" | |||
"wdread|" | |||
#endif // ifndef LIMIT_BUILD_SIZE | |||
#ifdef FEUTER_CAN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- That's probably a typo, should better be
#if FEATURE_CAN
- We've stopped using
#ifdef
for feature-flags, to make handling defaults possible, that can also be controller from aCustom.h
file, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🤔
src/src/DataStructs/SettingsStruct.h
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a duplicate for lines 3431..3441
TODOs: