Sort CAN-ID and Data (string)

Hi guys,

I have a problem. For a project I need to build a device how can read CAN-Datas. So far so good. I can already read them and I can display them on my TFT Display. But they are all unsorted at the moment.

The next step is to sort the received datas but I don’t want to use so may strings and sprintf()-functions. Because the memory is limited.

Here is the importend part of my code:

char stringcan[16] = {0};
char stringcanid[3] = {0};

CAN_Frame message, message2;// Create message object to use CAN message structure
message = CAN.read();
if (CAN.available() == true)
{

do
{
for ( int x = 0; x < 16; x++)
{
xpos = 100;
message = CAN.read();

sprintf(stringcanid, “%02X”, message.id);
myGLCD.print(stringcanid, 20, ypos);

for (int i = 0; i <= message.length - 1; i++)
{
sprintf(stringcan, “%02X”, message.data*);*

  • myGLCD.print(stringcan, xpos, ypos);*
  • xpos = xpos + 20;*
  • }*
  • ypos = ypos + 12;*
  • xpos = 90;*
  • }*
    [/color]
    I attached a photo of the displayed data.
    Have anyone a clue? how can I sort the IDs?
    From small to big.
    Thank you for your help
    greetings
    Kev

I assume you are just printing the CAN-messages as they arrive? You have to store them in some kind of buffer if you want to sort them.

lg, couka

yes, i am just printing the CAN-message as they arrive.
Of what kind of buffer do you think?

I am using the Arduino Due.
I have to read up to 256 ID's. I hope this can manage the Due in a decent time.

lg Kev

I presume the purpose of sorting the values is so that you do something else with the sorted list. What is that something?

...R

I only want to sort them. the LSB of the CAN-ID (0...F) is the position of the Chip with the attached CAN-Data on this particular device.

the other numbers of the CAN-ID in my example 19111x and 19211x are the ID of the device. There are up to 16 of this devices, who i have to read at the same time.

And this is why I want to sort them, for a good overview

lg

Kev

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

If you need to sort and store them, it may be worthwhile passing the output to a PC to do the rest.

Thanks.. Tom... :slight_smile: