Page 1 of 1

Counter

PostPosted: Mon Mar 11, 2019 1:55 pm
by gtihk
Hi,
I want to duplicate a counter at the last byte of a CAN message.
I think I know how to do it if the counter increment a fixed amount.
However, I am stuck on this one.
The following is the sequence : 3,79,139,199 and so on.

Could someone please help me out on this?

Re: Counter

PostPosted: Mon Mar 11, 2019 6:43 pm
by rntechnologies
Hi Githk,
Is the loop just the 4 messages and then loop again?

If so, there are a few ways you could do this (here is one):

static local something = 1;
if (something eq 1)
{
//3
}
else if (something eq 2)
{
//79
}

ETC ETC

//Send the message here

if (something eq 4)
{
something = 1;
}
else
{
something += 1;
}

Re: Counter

PostPosted: Tue Mar 12, 2019 2:13 am
by David Ferguson
If you are reverse engineering the protocol, are you sure the value is not actually a value that naturally increments, such as a timer or a distance value? If so, I would calculate the time, or increment the distance (based on speed & time)

Re: Counter

PostPosted: Tue Mar 12, 2019 1:54 pm
by gtihk
I do not think it is time or distance dependent.
Yes, there are just four values that loop.
Thanks for the help, Ryan!

Re: Counter

PostPosted: Tue Mar 12, 2019 5:44 pm
by gtihk
I have the project validated now. Will need to test on a car to see if things work out.
Thanks again!