Extracting a variable from a buffer
hi all,
noob question here.
i have following code prints buff[ ] value serial monitor (it's continuous stream coming in via udp) i'd extract value , use elsewhere. in snippet below i'm trying reassign buff[ ] value new variable, t, , print that., 0 value.
any tips appreciated.
noob question here.
i have following code prints buff[ ] value serial monitor (it's continuous stream coming in via udp) i'd extract value , use elsewhere. in snippet below i'm trying reassign buff[ ] value new variable, t, , print that., 0 value.
any tips appreciated.
code: [select]
indata = recvfrom(sockfd, buff, sizeof(buff), 0, (sockaddr*)&from, &socklen);
int i;
//-----print buffer contents------//
for(i=0;i<sizeof(buff);i++){
serial.print(buff[i]); // bit works expected
int t = buff[i];
}
serial.println("here comes t!");
serial.println(t); // returns 0 value
if (t >= 300) {
serial.print("made it!"); // never happens
}}
quote
it's continuous stream coming in via udp
no, isn't. it's populated new data each time function called. not same thing.
code: [select]
for(i=0;i<sizeof(buff);i++){
serial.print(buff[i]); // bit works expected
int t = buff[i];
}
while works, useless. copying 1 byte @ time t, of wrong type. local statement, goes out of scope when loop ends.
if snippet compiles, because have t declared somewhere else. using same name 2 different variables in 2 different, overlapping, scopes bad idea.
code: [select]
if (t >= 300) {
since value trying assign t in range 0 255, never true.
now, need show kind of data in udp packet, can suggest ways accomplish goal work.
Arduino Forum > Using Arduino > Programming Questions > Extracting a variable from a buffer
arduino
Comments
Post a Comment