Open buddhafragt opened 1 year ago
It looks like there is still a missing/old reference to the send_canbus_message function somewhere, try searching the other source code files.
Hello Stuart, I have searched all files and found no reference.
In main.cpp, this code sends the CANBUS message. It uses the ESP32 library, message.identifier
is only a uint32_t not a uint64, so your idea won't work as it stands.
You would need to research the ESP32 library for extended frames - https://docs.espressif.com/projects/esp-idf/en/release-v3.3/api-reference/peripherals/can.html
void send_canbus_message(uint32_t identifier, uint8_t *buffer, uint8_t length)
{
twai_message_t message;
message.identifier = identifier;
message.flags = TWAI_MSG_FLAG_NONE;
message.data_length_code = length;
extended frames use 29-bit ID field. The switch to uint64_t
wouldn't yield any benefit as the underlying API will truncate to 29-bits anyway.
However, the flags
field should have CAN_MSG_FLAG_EXTD
set for extended frames.
Thanks @atanisoft
Thanks for the hint, the flag is TWAI_MSG_FLAG_EXTD, and working! :-) The next problem is: How I can send Big-Endian instead if Little-Endian for the Pylontech?
Hi @buddhafragt - it doesn't sound like you require the PylonTech protocol for the device you are trying to communicate with.
I don't know a simple way to adjust to big-endian - you would most likely have to modify each of the calls/requests and swap the byte order in the data packets.
Hi @buddhafragt - it doesn't sound like you require the PylonTech protocol for the device you are trying to communicate with.
I don't know a simple way to adjust to big-endian - you would most likely have to modify each of the calls/requests and swap the byte order in the data packets.
Hi Stuart, I use your pylontech implementation to have a start. Unfortunately, the VE.CAN is also little-endian, so it seems that it will be more work. Can you give me a hint where to modify the calls/requests?
In the end, it was easy, so I answer my question by myself if someone like to do it: Simply swap in pylon_canbus.cpp the appropriate bytes before sending: data.battery_charge_voltage = ((data.battery_charge_voltage>>8) | (data.battery_charge_voltage<<8)); and voila.... Big Endian.
Does it all work now then?
I use it with a TC charger with CAN bus and a first test was successful. The TC charger also sent back a CAN message with the actual charging values, but we dont need it.
Hi @buddhafragt how is the TC charger integration going? Do you have code you could commit back to the project?
For a special CAN charger I try to change the CAN ID from standard to extended (for testing I edit Pylon_canbus.cpp): This is what I done:
Pylon_canbus.cpp: Row 88: send_canbus_message(0x355, (uint8_t )&data, sizeof(data355)); send_canbus_message(0x1806E5F4, (uint8_t )&data, sizeof(data355));
Main.cpp Row 2561: //void send_canbus_message(uint32_t identifier, uint8_t buffer, uint8_t length) void send_canbus_message(uint64_t identifier, uint8_t buffer, uint8_t length)
Pylon_canbus.h: Row 26: //extern void send_canbus_message(uint32_t identifier, uint8_t buffer, uint8_t length); extern void send_canbus_message(uint64_t identifier, uint8_t buffer, uint8_t length);
It seems I vorgot to change something, I get a compiling error: ...... .pio/build/esp32-devkitc/src/victron_canbus.cpp.o:(.literal._Z23victron_message_370_371v+0x4): undefined reference to `send_canbus_message(unsigned int, unsigned char*, unsigned char)'
Where do i still have to change something?