Pedro Neves wrote:Hello, i have some data i want to read from a socket. I wrote the following code:
The problem is that i have the following output:
fÆ$[] something like this.
well i saw a code in C language and the guy that wrote it read it to a char buffer[]. That why i think i could read to a string. The output was supost to show me some numbers.
Please i apreciate any help you all can give me, i'm new in Java programming and there are some aspects i dont know yet so maybe i'm going on the wrong direction.
my kind regards
(Edited: code tags are much better then unindented and monochrome code. -- Paul C)
Paul Clapham wrote:Okay. So far all we know is that your input is "bytes". That isn't nearly enough information to write code for.
You could certainly read in those bytes, and put them into a byte array. (Write them to a ByteArrayOutputStream if that's what you want to do.) But then what? You still need information about what the bytes mean and how they are organized. Just knowing that they are "bytes" is useless, everything is made of bytes.
Pedro Neves wrote:Well what i want is to read byte after byte and print its value on the screen. The data comes over the socket on a row format. :-/
Paul Clapham wrote:
Pedro Neves wrote:Well what i want is to read byte after byte and print its value on the screen. The data comes over the socket on a row format. :-/
That doesn't make sense, if the example you posted is a real example. Most of the bytes in that example are control characters and half of them are nulls. Or perhaps I don't understand what you mean by the "value" of a byte. What would the value of the byte you describe as "006" be? What about "206"?
And "row format" doesn't mean anything that I can see based on that example either.
Pedro Neves wrote:
Well as far as i know the the output is a bytestream i mean, i have to catch byte after byte and then represent ir. I have to read the information that a TelosB send to my app. I read bytes and the i represent them (which i supose i have to represent it as integers )
Flag (bit0=ADC0, bit1=ADC1, ..., bit11=CPUtemp)
102 003 000 019 000 003 000 032 000 002 000 002 000 255 015
102 003 000 019 000 003 000 032 000 002 000 001 000 064 000
102 003 000 019 000 003 000 032 000 002 000 002 000 048 000
How can i catch all the bytes?
Henry Wong wrote:
Pedro Neves wrote:
Well as far as i know the the output is a bytestream i mean, i have to catch byte after byte and then represent ir. I have to read the information that a TelosB send to my app. I read bytes and the i represent them (which i supose i have to represent it as integers )
Flag (bit0=ADC0, bit1=ADC1, ..., bit11=CPUtemp)
102 003 000 019 000 003 000 032 000 002 000 002 000 255 015
102 003 000 019 000 003 000 032 000 002 000 001 000 064 000
102 003 000 019 000 003 000 032 000 002 000 002 000 048 000
How can i catch all the bytes?
Yes. If you just want get and print a raw byte stream, then reading into a byte buffer would work. One issue though -- it looks like from the printouts that the byte stream are of unsigned bytes. Java supports signed bytes. So, don't forget to convert it (like cast to an int followed by ANDing out the high order bits) prior to printing.
Henry
Pedro Neves wrote:
well im finally starting to understand :)
But i still dont understand how can i convert the bytes to have some like this:
START MOBILE AGENT 1
Sent Message type
Destination Logical Node ID
Controller Message
FDS
Control Message
Agent ID
Sigma Factor (:10)
Sampling Time (sec)
ADC's
107 102 001 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
102 102 005 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
108 102 009 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
110 102 013 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
109 102 002 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
112 102 006 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
105 102 010 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
113 102 014 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
111 102 003 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
106 102 007 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
103 102 011 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
104 102 015 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
as far as i can i only got this:
102 -89 36 83 40 5 0 58 32 1 0 58 0 3 0 8 0 111 0 2 0 -1 15 -121 9 77
102 -88 36 -73 40 5 0 58 32 1 0 59 0 3 0 8 0 111 0 2 0 -1 15 -121 9 75
102 -87 36 27 41 5 0 58 32 1 0 60 0 3 0 8 0 111 0 2 0 -1 15 -111 9 97
102 -86 36 127 41 5 0 58 32 1 0 61 0 3 0 8 0 111 0 2 0 -1 15 -97 9 127
100 -85 62 -31 41 5 0 24 1 1 0 54 0 3 0 7 0 111 0 22 0 0 0 22 0 0
0 0 0 0 0 0 0 0 0 0 12 64 78 79 0 0 -112 25 0 0 0 0 104 0 15 0
95 9 -71 9 -77 9 -31 0 37 1 -39 5 119 8 -3 24 124 5 -97 9 -57 6 -66 43 5 0
73 9 -119 9 91 9 -31 0 37 1 -35 5 127 8 -4 24 123 5 -97 9 -57 6 34 44 5 0
how can i convert it well with my code? :
Thanks for all
Henry Wong wrote:To convert an unsigned byte, held in a signed byte variable, back to the original value you can do this...
Of course, this doesn't take care of the formatting which you still need to do.
Henry
Pedro Neves wrote:
well im finally starting to understand :)
But i still dont understand how can i convert the bytes to have some like this:
START MOBILE AGENT 1
Sent Message type
Destination Logical Node ID
Controller Message
FDS
Control Message
Agent ID
Sigma Factor (:10)
Sampling Time (sec)
ADC's
107 102 001 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
102 102 005 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
108 102 009 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
110 102 013 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
109 102 002 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
112 102 006 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
105 102 010 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
113 102 014 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
111 102 003 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
106 102 007 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
103 102 011 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
104 102 015 000 019 000 003 000 032 000 001 000 015 000 001 000 000 000
as far as i can i only got this:
102 -89 36 83 40 5 0 58 32 1 0 58 0 3 0 8 0 111 0 2 0 -1 15 -121 9 77
102 -88 36 -73 40 5 0 58 32 1 0 59 0 3 0 8 0 111 0 2 0 -1 15 -121 9 75
102 -87 36 27 41 5 0 58 32 1 0 60 0 3 0 8 0 111 0 2 0 -1 15 -111 9 97
102 -86 36 127 41 5 0 58 32 1 0 61 0 3 0 8 0 111 0 2 0 -1 15 -97 9 127
100 -85 62 -31 41 5 0 24 1 1 0 54 0 3 0 7 0 111 0 22 0 0 0 22 0 0
0 0 0 0 0 0 0 0 0 0 12 64 78 79 0 0 -112 25 0 0 0 0 104 0 15 0
95 9 -71 9 -77 9 -31 0 37 1 -39 5 119 8 -3 24 124 5 -97 9 -57 6 -66 43 5 0
73 9 -119 9 91 9 -31 0 37 1 -35 5 127 8 -4 24 123 5 -97 9 -57 6 34 44 5 0
how can i convert it well with my code? :
Thanks for all
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|