CAN Module

Post Reply
User avatar
EV_Builder
Posts: 1199
Joined: Tue Apr 28, 2020 3:50 pm
Location: The Netherlands
Has thanked: 16 times
Been thanked: 33 times
Contact:

CAN Module

Post by EV_Builder »

johu wrote: Thu Oct 14, 2021 8:47 am Yes, I believe that's what I've done. You can check out the latest code here: https://github.com/damienmaguire/Stm32- ... t-refactor
Ok i will check it out.
Now that we are at it i have some small request which i think you agree/like.

In stm32_can.cpp i added:

Code: Select all

/** \brief Send a user defined CAN message
 *
 * \param SENDBUFFER *data
 * \return void
 *
 */
void Can::Send(SENDBUFFER *canmsg)
{
   //copy to the local stack...
   uint32_t canId=canmsg->id;
   uint32_t data[2];
   uint8_t len=canmsg->len;

   data[0]= canmsg->data[0];
   data[1]= canmsg->data[1];

   can_disable_irq(canDev, CAN_IER_TMEIE);

   if (can_transmit(canDev, canId, false, false, len, (uint8_t*)data) < 0 && sendCnt < SENDBUFFER_LEN)
   {
      /* enqueue in send buffer if all TX mailboxes are full */
      sendBuffer[sendCnt].id = canId;
      sendBuffer[sendCnt].len = len;
      sendBuffer[sendCnt].data[0] = data[0];
      sendBuffer[sendCnt].data[1] = data[1];
      sendCnt++;
   }

   if (sendCnt > 0)
   {
      can_enable_irq(canDev, CAN_IER_TMEIE);
   }
}
For it to work you make the SENDBUFFER type public.
Now you can easyly dump a item to the canbus.
but also move around pointers or start new canbus items within the application and ditch the data[2] way of doing it...(sorry who started that)..


Now for my project i want to make an extension like

Code: Select all


 struct CANMSG
   {
      SENDBUFFER msg; //this one can be sended out to the bus...
      
      //lets drag allong some more information...      
      uint8_t crcpresent;
      uint8_t crcbyte;
      uint8_t crcpoly;
      uint8_t crcoffset;
      uint8_t counterbyte;
      
   };

Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
User avatar
EV_Builder
Posts: 1199
Joined: Tue Apr 28, 2020 3:50 pm
Location: The Netherlands
Has thanked: 16 times
Been thanked: 33 times
Contact:

Re: The ZombieVerter VCU Project

Post by EV_Builder »

EV_Builder wrote: Sat Oct 16, 2021 3:22 pm Ok i will check it out.
Now that we are at it i have some small request which i think you agree/like.

EDIT johu: redacted huge quote
mhhh i see that i still have those ugly uint32_t array in there i will take it out, why not 8 bytes?
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
User avatar
johu
Site Admin
Posts: 5683
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: The ZombieVerter VCU Project

Post by johu »

EV_Builder wrote: Sat Oct 16, 2021 6:24 pm mhhh i see that i still have those ugly uint32_t array in there i will take it out, why not 8 bytes?
Matter of taste, thought in 2021 we should ditch those antiquated bytes :) Also it's easier to handle, instead of looping over 8 bytes, just copy to two words explicitly.

Might add that function, will see. Just do it locally. And never copy paste. Just do

Code: Select all

Send(SB *b)
{
   Send(b->id, b->len, b->data);
}
And lastly please quote more precisely, don't quote a half-pager post just to add one line of new comment. Hard to read.

And lastly lastly I think we're going off-topic.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
EV_Builder
Posts: 1199
Joined: Tue Apr 28, 2020 3:50 pm
Location: The Netherlands
Has thanked: 16 times
Been thanked: 33 times
Contact:

Re: The ZombieVerter VCU Project

Post by EV_Builder »

johu wrote: Sat Oct 16, 2021 9:32 pm Matter of taste, thought in 2021 we should ditch those antiquated bytes :) Also it's easier to handle, instead of looping over 8 bytes, just copy to two words explicitly.

Might add that function, will see. Just do it locally. And never copy paste. Just do

Code: Select all

Send(SB *b)
{
   Send(b->id, b->len, b->data);
}
And lastly please quote more precisely, don't quote a half-pager post just to add one line of new comment. Hard to read.

And lastly lastly I think we're going off-topic.
Yes we are in 2021, but my point is about the fact that later on in the program you see us undo the int32_t and assigning/reading the bytes manually.
But if you want to have both thats also possible with c++.

I will check my quotes, (maybe next forum update we can facilitate that a bit..), none the less i will watch carefully. Do remember that that's also a matter of taste.. i never edit quotes so they are only a reminder of where the response is related too. But hey i will try to remember and take care. ;) :) :)


If you want/like that we collaborate maybe we should open a new thread about it is that an idea?
And don't forget that if this party is one for everyone to join we should make sure there is something for everyone in it.
If you don't like or have other ideas, that's fine too just tell and i will sh*t up... :)

Edit: i now just saw that you are running behind me cleaning up my quotes :o
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
User avatar
johu
Site Admin
Posts: 5683
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: CAN Module

Post by johu »

Ok, now we are more free to discuss without distracting the VCU thread. So a Send(id, len, bytes[]) function is actually a good idea. For receiving we can't overload so that still needs casting.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
EV_Builder
Posts: 1199
Joined: Tue Apr 28, 2020 3:50 pm
Location: The Netherlands
Has thanked: 16 times
Been thanked: 33 times
Contact:

Re: CAN Module

Post by EV_Builder »

First of all: Thank u for moving. Maybe sometimes i'm to quick (enthusiast) quoting and reacting etc. but i do it with the best intentions.
So a Send(id, len, bytes[]) function is actually a good idea. For receiving we can't overload so that still needs casting.
Ok, thats fair; but we could make a function who does that one time and then feed all the handle methods with the canframe or other struct pointer.
It saves in all handle methods the casting/converting and IMHO that adds to readability.

Would that be an option?
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
Post Reply