Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

From BuffA to BuffB

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hey, i have 2 huge 512 byte buffers and need to copy certain data from BufferA to BufferB. I thought a simple

buffa[x] = buffb[y];

would have worked but i get varying results.

This is partial bufferB
Code:
             C00    [0]                          'A'        0x41               65                                   01000001
             C01    [1]                          'J'        0x4A               74                                   01001010
             C02    [2]                          '.'        0x00                0                                   00000000
             C03    [3]                          'a'        0x61               97                                   01100001
             C04    [4]                          '.'        0x00                0                                   00000000
             C05    [5]                          's'        0x73              115                                   01110011
             C06    [6]                          '.'        0x00                0                                   00000000
             C07    [7]                          'o'        0x6F              111                                   01101111
             C08    [8]                          '.'        0x00                0                                   00000000
             C09    [9]                          'n'        0x6E              110                                   01101110
             C0A    [10]                         '.'        0x00                0                                   00000000
             C0B    [11]                         '.'        0x0F               15                                   00001111
             C0C    [12]                         '.'        0x00                0                                   00000000
             C0D    [13]                         'j'        0x6A              106                                   01101010

This is partial buffA which is items from buffb i need.

Code:
             A00    [0]                          'A'        0x41               65                                   01000001
             A01    [1]                          'J'        0x4A               74                                   01001010
             A02    [2]                          's'        0x73              115                                   01110011
             A03    [3]                          'a'        0x61               97                                   01100001
             A04    [4]                          'n'        0x6E              110                                   01101110
             A05    [5]                          '.'        0x2E               46                                   00101110
             A06    [6]                          '.'        0x00                0                                   00000000
             A07    [7]                          'x'        0x78              120                                   01111000
             A08    [8]                          't'        0x74              116                                   01110100
             A09    [9]                          '.'        0x00                0                                   00000000
             A0A    [10]                         '.'        0x00                0                                   00000000
             A0B    [11]                         '.'        0xFF              255                                   11111111
             A0C    [12]                         '.'        0xFF              255                                   11111111
             A0D    [13]                         'L'        0x4C               76                                   01001100

This is the code im using to copy items from buffb to buffa:
x and y are "unsigned int" Both start at 0x00.

Since each buff is 512 bytes and what i need to get from buffb is in 64 byte parts. I only need some of the 64 bytes not all so i copy from buffb all the bytes i need into buffa (data) then i add 64 to y at the end so i get the next 64 bytes.

Be aware y never changes until the y+=64; at the end.
Code:
	while(1){
		if(buffer[y] == 0x00) 
			break;

		data[x++] = buffer[(y+1)];	
		data[x++] = buffer[(y+3)];
		data[x++] = buffer[(y+5)];
		data[x++] = buffer[(y+7)];
		data[x++] = buffer[(y+9)];
		data[x++] = buffer[(y+14)];
		data[x++] = buffer[(y+16)];
		data[x++] = buffer[(y+18)];
		data[x++] = buffer[(y+20)];
		data[x++] = buffer[(y+22)];
		data[x++] = buffer[(y+24)];
		data[x++] = buffer[(y+28)];
		data[x++] = buffer[(y+30)];

		y+=64;
	}
 
Last edited:
You don't state what is wrong with the result. You also only post part of your code. You can only get the result you post if you call your code multiple times and also setup y each time. Post more code.

Mike.
 
That is actually most of the code. I did state the issue ... varying results... The code should be simple to follow

data[x++] = buffer[(y+1)];

BUFFER[((y = 0) + 1 (1)] now its BUFFER[1]

DATA[0] = BUFFER[1] then add 1 to x so x = 1 now

BUFFER[((y = 0) + 3 (3)] now its BUFFER[3]
DATA[1] = BUFFER[3] then add 1 to x so x = 2

this goes on and on. As for the data look at the buffA/B

Now
Code:
 DATA[0] = BUFFER[1]
This should give me a J in the DATA[0] (aka BUFFA)

Now
Code:
 DATA[1] = BUFFER[3]
This should give me a a in the DATA[1] (aka BUFFA)

Insteat i get

DATA[0] = A
DATA[1] = J

You see the problem? Ill try to write it out in Office so i can see what im typeing better.
 
I think your loop is wrapping round. Get rid of the while(1) and just execute the code once and it should work as planned.

Mike.
 
As mentioned by Pommie, dump the while loop and use a for loop instead. Think of what happens if the statement buffer[y] == 0x00 never becomes true and (y+30) rolls beyond the bounds of the 512 byte array. Besides, you are only checking for buffer[y] == 0x00 every 64th interval of y which doesn't make sense to me.
 
ok as mentioned before this is a 512 byte char array. And it was used as a while mainly because i didnt know how to calculate how many can fit in a 512 byte but i was dumb lol
512 / 64 = 8. So now i can do:

for(i=0;i<8;i++)

instead of the WHILE(1) loop.

I was/am checking every 64bytes because at 0 is the first letter of the name and rest of the name and info if a total of 64 chars. 0-63 makes 1 section of data. so there will be 8 sections with individual names in them inside the buffer. Ill try the for loop now to see if it helps.
 
ok it works somewhat. Anyone know how to fix this GHOST breakpoint problem? Its killing me!

Got tired of trying to fix so i erased the project files and kept source and remade the project files as a new project added all back and made a backup of the project files :D

EDIT

Thanks guys forgot to say it works as its supposed to now i have to parse my items better. The looping is great thanks!!
 
Last edited:
You can start a new project and add your files to it.

I think they may have fixed it in the latest version (8.15). Which version are you using?

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top