PDA

View Full Version : Compare Data



Pesticida
- 14th February 2008, 11:46
Hi,

IŽneed a Solution for my Firmware,I must to compare Received Data,but the Problem is that the lenght of the strings are not always the same.

For Example i send $WP+CALL=12345... and I should receive this $OK:CALL or $ERR:CALL when I use this $WP+GSMINFO=1234 i should receive $MSG:GSMINFO="xxx",27,0,0.

All the answers have this first character "$" and I want to put the Answer on my LCD.

Receive:
Dummy[Input_Byte_Count] = RCREG ' Clear USART Flag by reading USART data
If Dummy[0] = 36 then ' Character $
High LCD_Light
Lcdout $fe, 1 ' Clear screen
If Dummy[Input_Byte_Count] = 10 then 'Line Feed
Pause 5
Lcdout $fe,$80,str Dummy\Input_Byte_Count+1
Pause 5
Input_Byte_Count = 0
else
Input_Byte_Count = Input_Byte_Count + 1
endif
else
Dummy[0] = $00
endif
Resume

Is this a good way to do this ?

Thanks for any answer

Regards Pesti

Dave
- 14th February 2008, 12:48
Pesticida, Is there some EOL character sent at the "End of Line"? You can use this character (ie.CR/LF) as a terminator for the input string to your LCD display...

Dave Purola
N8NTA

Pesticida
- 14th February 2008, 13:47
Hi,

Yes Feed New Line.

Regards Pesti

Pesticida
- 14th February 2008, 14:50
I think that my Problem is that if I use Dummy=RCREG with RCIF Interrupt I become a overflow.

I must to try with Hserin.

Regards

skimask
- 14th February 2008, 17:55
I think that my Problem is that if I use Dummy=RCREG with RCIF Interrupt I become a overflow.

I must to try with Hserin.

Regards

And again, just like the last bunch of posts, you answer awaits you in the PBP manual...It's all about terminating the SERIN2/HSERIN input with an optional character...
It's in the book if you just take the time to look.
I understand what you're trying to do and as soon as you read the book, really read the book, the answer will show up...right in front of you...especially since you said that each line is ended with some sort of optional character, in your case, a line feed character.

Pesticida
- 14th February 2008, 18:55
Sorry but i dont have exactly explain my Problem,I know how this work but my problem is how to make a routine that check for example if I receive this $OK:CALL, then is the call ok and so on.

How to verify Long strings?

I send this $WP+CALL=12345... and then from gsm module receive $OK:CALL.

Thanks Skimask

skimask
- 14th February 2008, 19:21
Sorry but i dont have exactly explain my Problem,I know how this work but my problem is how to make a routine that check for example if I receive this $OK:CALL, then is the call ok and so on.
How to verify Long strings?
I send this $WP+CALL=12345... and then from gsm module receive $OK:CALL.
Thanks Skimask

Yes, I know...I get it...
Ok, if you know you start out with a NULL string, and you know what messages you are supposed to be receiving, and you know each of these messages may or may not be a different length, it shouldn't be much of a problem to look at the string, starting from the end (whether it's used or not) and working your way back to the start, looking for the character/characters which may or may not identify the string you are looking for...

Pesticida
- 14th February 2008, 19:52
You mean i must do for example something like this:

Mystring var byte [24] ' maximal 24 bytes
String_Lenght var byte


But I must count how Long is my string from start $ to End Line feed.
For Example Ihave this $OK:CALL

String_Lenght for this example is 9 with Line feed

if Mystring[String_Lenght-2] = 76 then Character2 'L
Character2:
if Mystring[String_Lenght-3] = 76 then Character3 'L
Character3:
if Mystring[String_Lenght-4] = 65 then Character4 'A
Character4:
if Mystring[String_Lenght-5] = 67 then Character3 'C

and so on

but I think this is not the good way ,this is to complicated for several strings!

skimask
- 14th February 2008, 20:21
You mean i must do for example something like this:
Mystring var byte [24] ' maximal 24 bytes
String_Lenght var byte
But I must count how Long is my string from start $ to End Line feed.
For Example Ihave this $OK:CALL
String_Lenght for this example is 9 with Line feed
if Mystring[String_Lenght-2] = 76 then Character2 'L
Character2:
if Mystring[String_Lenght-3] = 76 then Character3 'L
Character3:
if Mystring[String_Lenght-4] = 65 then Character4 'A
Character4:
if Mystring[String_Lenght-5] = 67 then Character3 'C

and so on

but I think this is not the good way ,this is to complicated for several strings!

There is no String_Length function, you have to count backwards from the end to find the length of the string manually.
One easy-ish way I can think of...
You have X number of possible messages to be returned.
Add up the character values of each possible character in that message.
When a complete message is received and you have added up the individual characters, the message either may or may not match a number already in a table you have preconstructed for that purpose.
Example:
Message received is 'OK' + LF
ASCII value's are O = 79, K = 75, LF = 10, therefore the message is 79+75+10 = 164.
After you've added them all up you get 164. Go to a Select Case..... Case 164 .... blah blah blah... and there you go.
Problem is...here's another message...
Message received is 'AY' + LF
A = 65, Y = 89, LF = 10, message = 65+89+10 = 164...the code would see the same message, so you'd have to actually go 'inside' the received message to figure out which one it is...
Or you could just use a number of LOOKUP statements to figure it out.

Pesticida
- 14th February 2008, 20:40
Thank You Skimask this is a Perfect Solution, while I have just 10 Answers what I need.

I will try your example.

Regards Pesti