I am about to implement some algorithm in telosb motes. What I need to do is, take a file and split it up in smaller objects and then splitting up the object to even smaller object called pages, like described in the figure below.
After doing that, the page will be transmitted wirelessly to other mote. One at a time called packet.
I have an array with of 2000 bytes which i want to spilt up like shown in the figure, the requirement for the page is that the packet shall be less then 110 bytes each or less.
nx_uint16_t file[1000];
int j, A;
for ( j = 0;j<1000;j++)
{
int ra = (rand() +1) % 10;
}
A = sizeof(file);
printf("\n Array size: %d Bytes", A );
Any help would be appreciated.
If you have three defined sizes for Object, Page and Packet, then use the three arrays of said sizes and copy the elements serially.
Since you have 2000 bytes, dividing it into 110 byte chunk means that there will be ceil(2000/110) packets. However your packet may contain headers or checksums or both (prefix and suffix data).
byte array[2000];
byte packet[110];
unsigned packet_count = 0;
for(int i = packet_count * 110, j = 0; j < 110; ++j, ++i)
packet[j] = array[i] ;
++packet_count ;
forward(packet);
Notice that i
starts from packet_count * 110
whereas j
moves from 0
to 109
.