Why not leave all the bytes in and just use the index for whatever you need.
That is easier to debug if things don't work out immediately.
regards peter
It's look like i can't go into this part of the readgsm fonction:
if ( GSMdata.charAt(2) == '+' || GSMdata.charAt(2) == '~' ) { // answer to a command
GSMret = GSMdata.indexOf( ":" ); // Start position of the answer
GSMdata.subString( GSMret+2, GSMindex-2, GSMcode );
System.out.println( GSMcode.toString() );
return 1;
}
even when I got an answer like that :
GSMdata in hexbytes
0D 0A 2B 43 52 45 47 3A 20 31 2C 30 0D 0A 0D 0A 4F 4B 0D 0A
GSMdata in ascii bytes
..+CREG: 1,0....OK..
what is wrong with my test ?
Wha I wan't is remove the CR/LF at the start, put the answer (what is after the [noparse]:)[/noparse] to GSMcode
Did you install the corrected StringBuffer and String class?
Those classes installed from the downloaded installer have an error.
See earlier post.
regards peter
Use GSMdata.toString().toChar()
Also note that GSMindex is not set to end of string
as it is not used in the code above.
Replace it by GSMdata.length()
Note that the Format class also has a bscanf() method,
to parse strings.
So if GSMdata holds
0D 0A 2B 43 52 45 47 3A 20 31 2C 30 0D 0A 0D 0A 4F 4B 0D 0A
which is "\r\n+CREG: 1,0\r\n\r\nOK\r\n" which has a known format for a specific command
then you can use
int k=0;
int[noparse]/noparse pReg = new int[noparse][[/noparse]1];
int[noparse]/noparse pValue = new int[noparse][[/noparse]1];
k = Format.bscanf(GSMdata.toString(),k,"\r\n+CREG: %d",pReg); //make pReg[noparse][[/noparse]0] integervalue at %d position
k = Format.bscanf(GSMdata.toString(),k,",%d",pValue); //make pValue[noparse][[/noparse]0] integervalue at %d position
regards peter
Post Edited (Peter Verkaik) : 6/5/2006 2:43:47 PM GMT
Hmm yes that's good.
thank you very much for all your help.
I will look tomorrow for the next step:
GSP part and SMS
By the way I don't to make a bscanf for the +CREG message, since I have other message that will givbe me an answer. so I
try to make as universal as possible.
Comments
That is easier to debug if things don't work out immediately.
regards peter
if ( GSMdata.charAt(2) == '+' || GSMdata.charAt(2) == '~' ) { // answer to a command
GSMret = GSMdata.indexOf( ":" ); // Start position of the answer
GSMdata.subString( GSMret+2, GSMindex-2, GSMcode );
System.out.println( GSMcode.toString() );
return 1;
}
even when I got an answer like that :
GSMdata in hexbytes
0D 0A 2B 43 52 45 47 3A 20 31 2C 30 0D 0A 0D 0A 4F 4B 0D 0A
GSMdata in ascii bytes
..+CREG: 1,0....OK..
what is wrong with my test ?
Wha I wan't is remove the CR/LF at the start, put the answer (what is after the [noparse]:)[/noparse] to GSMcode
Those classes installed from the downloaded installer have an error.
See earlier post.
regards peter
So now my program dosen't crash any more (thank you very mutch for your help)
but it dosen't enter into this test.
Also note that GSMindex is not set to end of string
as it is not used in the code above.
Replace it by GSMdata.length()
regards peter
And how should define wich char I want ?
to parse strings.
So if GSMdata holds
0D 0A 2B 43 52 45 47 3A 20 31 2C 30 0D 0A 0D 0A 4F 4B 0D 0A
which is "\r\n+CREG: 1,0\r\n\r\nOK\r\n" which has a known format for a specific command
then you can use
int k=0;
int[noparse]/noparse pReg = new int[noparse][[/noparse]1];
int[noparse]/noparse pValue = new int[noparse][[/noparse]1];
k = Format.bscanf(GSMdata.toString(),k,"\r\n+CREG: %d",pReg); //make pReg[noparse][[/noparse]0] integervalue at %d position
k = Format.bscanf(GSMdata.toString(),k,",%d",pValue); //make pValue[noparse][[/noparse]0] integervalue at %d position
regards peter
Post Edited (Peter Verkaik) : 6/5/2006 2:43:47 PM GMT
regards peter
thank you very much for all your help.
I will look tomorrow for the next step:
GSP part and SMS
By the way I don't to make a bscanf for the +CREG message, since I have other message that will givbe me an answer. so I
try to make as universal as possible.
best regards
arno