MajenkoLibraries / ICSC

Inter-Chip Serial Communications
BSD 3-Clause "New" or "Revised" License
81 stars 27 forks source link

how to make longer packet lengths #7

Open nindidooo opened 7 years ago

nindidooo commented 7 years ago

I'm trying to send a string of up to 54 characters from master to slave.

The characters are integers from 0 to 1000. Could you tell me how to do this?

miketedeschi commented 7 years ago

You can change it in the header file i believe...im not on a computer otherwise i would look. Mine is set to 100 and it works great.

On Nov 29, 2016 10:04 PM, "nindidooo" notifications@github.com wrote:

I'm trying to send a string of up to 54 characters from master to slave.

The characters are integers from 0 to 1000. Could you tell me how to do this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MajenkoLibraries/ICSC/issues/7, or mute the thread https://github.com/notifications/unsubscribe-auth/AGLKn4glULuhaMf1R2AThv6TbWPLT6J3ks5rDOfKgaJpZM4K_wKq .

majenkotech commented 7 years ago

By default you already have 250 bytes in the message buffer. That is more than enough for 54 characters.

If it's just a normal text string you can:

icsc.send(20, 'F', myString);

This is the same as:

icsc.send(20, 'F', myString, strlen(myString));

If it is an array of byte values you need to include the size of the array:

icsc.send(20, 'F', myData, 54);

For larger data types you need to cast it and make sure you give it the byte count. For 16-bit integers:

icsc.send(20, 'F', (uint8_t *)myData, 108);

sizeof() is useful for this, since it gives the byte size (as long as it's in the same scope as the definition of the array since it's calculated at compile time, not runtime):

icsc.send(20, 'F', (uint8_t *)myData, sizeof(myData));