How does the M1 handle CAN messages

Support forum for users of the M1 Build

How does the M1 handle CAN messages

Postby IamTheStig on Sun Feb 25, 2018 8:58 am

Hi all,

I'm adding some CAN sensors to the M1 via build. For this I have a "CAN-Signal-Template", which I just copy-and-paste and change the needed settings according to the type of singal. (I'm wondering why the M1 just does not have this option like it was also possible in the ADL3)
The internal code to get the value is:
Code: Select all
local hBig = CanComms.RxOpenStandard(SensTemplate.CAN Bus.AsInteger() - 1,
   Message.ID, 0x0, true);
local hLittle = CanComms.RxOpenStandard(SensTemplate.CAN Bus.AsInteger() - 1,
   Message.ID, 0x0, false);

local <Unsigned Integer> h = 0;
if (Message.Endianness eq Message.Endianness.Big Endian) {
   h = hBig;
} else {
   h = hLittle;
}
if (SensTemplate.CAN Bus neq SensTemplate.CAN Bus.Not in Use) {
   if (Message.ID > 0) {
      if (CanComms.RxMessage(h)) {
         if (Scale.Signed eq Scale.Signed.On) {
            Value = CanComms.GetInteger(h, Message.Offset,
               Message.Length) * Scale.Factor + Scale.Offset;
         } else {
            Value = CanComms.GetUnsignedInteger(h, Message.Offset,
               Message.Length) * Scale.Factor + Scale.Offset;
         }
         if (Timeout > 0) {
            Timer.Start(Timeout);
         }
      } else {
         if (Timeout > 0) {
            if (Timer.Remaining() <= 0) {
               Value = Calculate.NAN();
            }
         }
      }
   } else { Value = Calculate.NAN(); }
} else { Value = Calculate.NAN(); }

How does a M1 handle if multiple functions check for the same CAN-ID? Has the M1 an internal "distributer" that copies the message to every function. Or are the functions "stealing" messages from each other?
(If you have other comments on my code, feel free to comment ;) )
IamTheStig
 
Posts: 6
Joined: Tue Oct 13, 2015 8:27 pm

Re: How does the M1 handle CAN messages

Postby DarrenR on Thu Aug 16, 2018 3:23 pm

I would have to test it to know for certain, but I believe in the case a received message fits more than one RxOpenStandard() arguments (this case), the message will be copied to both receive buffers.

But why don't you just put the Message.Endianness parameter in the Open funciton, like this -
Code: Select all
local hBig = CanComms.RxOpenStandard(SensTemplate.CAN Bus.AsInteger() - 1,
   Message.ID, 0x0, Message.Endianness eq Message.Endianness.Big Endian);
Darren Reynolds
MoTeC Research Centre - Melbourne, Australia.
DarrenR
MoTeC
 
Posts: 176
Joined: Thu May 01, 2008 2:15 pm
Location: Melbourne, Australia


Return to M1 Build

Who is online

Users browsing this forum: No registered users and 3 guests