|
|
View previous topic :: View next topic |
Author |
Message |
mmanisse Guest
|
Decode serial messages |
Posted: Mon Jul 28, 2003 3:52 am |
|
|
Hi,
I'm searching a suggest to implement a decode serial ascii message on my firmware.
I have a modem connect on pic 16f877 uart and i have to decode the answer messages.
Example:
I sent a command to the modem with a printf string 'AT' and i must decode the answer 'OK'.
This message always end with 'return ascii char'
How can i do?
Thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516420 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: Decode serial messages |
Posted: Mon Jul 28, 2003 5:55 am |
|
|
Read the data into a buffer until you recieve the 'return char'. Then process the buffer using a string compare function:
char string1[]="OK";
if (stricmp(buffer, string1) == 0)
{
//The strings are equal so do whatever
}
or
char string1[3]; // This must be big enough including the NULL terminator
strcpy(string1, "OK");
if (stricmp(buffer, string1) == 0)
{
//The strings are equal so do whatever
}
:=Hi,
:=I'm searching a suggest to implement a decode serial ascii message on my firmware.
:=I have a modem connect on pic 16f877 uart and i have to decode the answer messages.
:=Example:
:=I sent a command to the modem with a printf string 'AT' and i must decode the answer 'OK'.
:=This message always end with 'return ascii char'
:=
:=How can i do?
:=Thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516427 |
|
|
Steve H. Guest
|
What I do.... |
Posted: Mon Jul 28, 2003 7:54 am |
|
|
I have similar code posted on my website at the link below.
Steve H.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516432 |
|
|
jpt@tayloredge.com Guest
|
Re: Decode serial messages |
Posted: Mon Jul 28, 2003 8:24 pm |
|
|
<a href="http://www.tayloredge.com/utilities/scmd.c.txt" TARGET="_blank">http://www.tayloredge.com/utilities/scmd.c.txt</a>
from
<a href="http://www.tayloredge.com/utilities/index.html" TARGET="_blank">http://www.tayloredge.com/utilities/index.html</a>
This is my command processor, all interrupt level message decode.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516450 |
|
|
mmanisse Guest
|
Re: Decode serial messages |
Posted: Sat Aug 02, 2003 3:16 am |
|
|
ok Mark
i untherstood what do you mean, but i have a little difficoult to do this.
My strategy to decode message is this:
my modem message always is:
'CR' 'LF' 'MESSAGE' 'CR' 'LF'.
With this information i'm working in this mode:
I'm looking for the CR and LF than i buffered the chars to next CR.
Now i have a buffer, how can i compare it?
Tnx
I'm attach the function:
=============================================================
gsm_rx_string()
//Rx string from gsm: 'CR' 'LF' 'XXXXXXXXXX' 'CR' 'LF'
{
MESSAGE_READ=0;
buffer_gsm=0;
buffer_gsm[0] = getc();
if (buffer_gsm[0] != 'CR') // Find Carriage Return.
goto exit;
buffer_gsm[0] = getc();
if (buffer_gsm[0] != 'LF') // Find Line Feed.
goto exit;
i=0; // Buffered the string to next CR
do {
buffer_gsm[i] = getc();
++i;
} while ((buffer_gsm[i-1] != 'CR') || (i<35));
if ((buffer_gsm[i-1] == 'CR') && (i>0))
{
MESSAGE_READ=1;
i=i-1; // Delete CR from string.
}
exit:
}
=============================================================
:=Read the data into a buffer until you recieve the 'return char'. Then process the buffer using a string compare function:
:=
:=char string1[]="OK";
:=
:=if (stricmp(buffer, string1) == 0)
:={
:= //The strings are equal so do whatever
:=}
:=
:=or
:=
:=char string1[3]; // This must be big enough including the NULL terminator
:=
:=strcpy(string1, "OK");
:=if (stricmp(buffer, string1) == 0)
:={
:= //The strings are equal so do whatever
:=}
:=
:=:=Hi,
:=:=I'm searching a suggest to implement a decode serial ascii message on my firmware.
:=:=I have a modem connect on pic 16f877 uart and i have to decode the answer messages.
:=:=Example:
:=:=I sent a command to the modem with a printf string 'AT' and i must decode the answer 'OK'.
:=:=This message always end with 'return ascii char'
:=:=
:=:=How can i do?
:=:=Thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516588 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: Decode serial messages |
Posted: Sat Aug 02, 2003 9:36 am |
|
|
Try this out:
enum message
{
MSG_OK,
MSG_TEST,
MSG_3,
MSG_4,
MSG_5,
MSG_6,
INVALID_MSG
}
gsm_rx_string()
//Rx string from gsm: 'CR' 'LF' 'XXXXXXXXXX' 'CR' 'LF'
{
MESSAGE_READ=0;
buffer_gsm[0]=0;
buffer_gsm[0] = getc();
if (buffer_gsm[0] != '\r') // Find Carriage Return.
return;
buffer_gsm[0] = getc();
if (buffer_gsm[0] != '\n') // Find Line Feed.
return;
i=0;
while(i<35)
{
buffer_gsm[i] = getc();
if (buffer_gsm[i] == '\r')
{
// terminate our string
buffer_gsm[i] = 0
MESSAGE_READ=1;
break;
}
i++;
}
return;
}
enum message Check_GSM_String(char *s1)
{
enum message msg;
char s2[10]; // This must be big enough including the NULL terminator
for (msg=0;msg
{
switch (msg)
{
case MSG_OK:
strcpy(s2, "OK");
break;
case MSG_TEST:
strcpy(s2, "TEST");
break;
case MSG_MSG3:
strcpy(s2, "MSG3");
break;
case MSG_MSG4:
strcpy(s2, "MSG4");
break;
case MSG_MSG5:
strcpy(s2, "MSG5");
break;
case MSG_MSG6:
strcpy(s2, "MSG6");
break;
default:
// we shouldn't ever get here! But if we do return invalid message
return(INVALID_MSG);
}
if (stricmp(s1, s2) == 0)
{
//The strings are equal so return which one
return(msg);
}
}
// We didn't find a valid message so return an invalid one
return(INVALID_MSG);
}
:=ok Mark
:=i untherstood what do you mean, but i have a little difficoult to do this.
:=My strategy to decode message is this:
:=my modem message always is:
:='CR' 'LF' 'MESSAGE' 'CR' 'LF'.
:=With this information i'm working in this mode:
:=I'm looking for the CR and LF than i buffered the chars to next CR.
:=Now i have a buffer, how can i compare it?
:=
:=Tnx
:=
:=I'm attach the function:
:=
:==============================================================
:=gsm_rx_string()
:=//Rx string from gsm: 'CR' 'LF' 'XXXXXXXXXX' 'CR' 'LF'
:={
:= MESSAGE_READ=0;
:= buffer_gsm=0;
:=
:= buffer_gsm[0] = getc();
:= if (buffer_gsm[0] != 'CR') // Find Carriage Return.
:= goto exit;
:=
:= buffer_gsm[0] = getc();
:= if (buffer_gsm[0] != 'LF') // Find Line Feed.
:= goto exit;
:=
:=
:= i=0; // Buffered the string to next CR
:= do {
:= buffer_gsm[i] = getc();
:= ++i;
:= } while ((buffer_gsm[i-1] != 'CR') || (i<35));
:=
:=
:= if ((buffer_gsm[i-1] == 'CR') && (i>0))
:= {
:= MESSAGE_READ=1;
:= i=i-1; // Delete CR from string.
:= }
:=
:=exit:
:=
:=}
:=
:==============================================================
:=
:=
:=
:=
:=
:=:=Read the data into a buffer until you recieve the 'return char'. Then process the buffer using a string compare function:
:=:=
:=:=char string1[]="OK";
:=:=
:=:=if (stricmp(buffer, string1) == 0)
:=:={
:=:= //The strings are equal so do whatever
:=:=}
:=:=
:=:=or
:=:=
:=:=char string1[3]; // This must be big enough including the NULL terminator
:=:=
:=:=strcpy(string1, "OK");
:=:=if (stricmp(buffer, string1) == 0)
:=:={
:=:= //The strings are equal so do whatever
:=:=}
:=:=
:=:=:=Hi,
:=:=:=I'm searching a suggest to implement a decode serial ascii message on my firmware.
:=:=:=I have a modem connect on pic 16f877 uart and i have to decode the answer messages.
:=:=:=Example:
:=:=:=I sent a command to the modem with a printf string 'AT' and i must decode the answer 'OK'.
:=:=:=This message always end with 'return ascii char'
:=:=:=
:=:=:=How can i do?
:=:=:=Thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516592 |
|
|
mmanisse Guest
|
Re: Decode serial messages |
Posted: Sun Aug 03, 2003 6:29 am |
|
|
Ok Mark,
I have introducted you suggest in my firmware, but the compiler tell me that there is an error on :
'enum message msg;'
It espect a {
This is the first time that i use enum, do you think that there is an error?
I have counted the {} but all opened are closed.
Can you help me?
:=Try this out:
:=
:=enum message
:={
:= MSG_OK,
:= MSG_TEST,
:= MSG_3,
:= MSG_4,
:= MSG_5,
:= MSG_6,
:= INVALID_MSG
:=}
:=gsm_rx_string()
:=
:=//Rx string from gsm: 'CR' 'LF' 'XXXXXXXXXX' 'CR' 'LF'
:={
:= MESSAGE_READ=0;
:= buffer_gsm[0]=0;
:=
:= buffer_gsm[0] = getc();
:= if (buffer_gsm[0] != '\r') // Find Carriage Return.
:= return;
:=
:= buffer_gsm[0] = getc();
:= if (buffer_gsm[0] != '\n') // Find Line Feed.
:= return;
:= i=0;
:= while(i<35)
:= {
:= buffer_gsm[i] = getc();
:= if (buffer_gsm[i] == '\r')
:= {
:= // terminate our string
:= buffer_gsm[i] = 0
:= MESSAGE_READ=1;
:= break;
:= }
:= i++;
:= }
:= return;
:=}
:=
:=enum message Check_GSM_String(char *s1)
:={
:= enum message msg;
:= char s2[10]; // This must be big enough including the NULL terminator
:=
:= for (msg=0;msg
:= {
:= switch (msg)
:= {
:= case MSG_OK:
:= strcpy(s2, "OK");
:= break;
:= case MSG_TEST:
:= strcpy(s2, "TEST");
:= break;
:= case MSG_MSG3:
:= strcpy(s2, "MSG3");
:= break;
:= case MSG_MSG4:
:= strcpy(s2, "MSG4");
:= break;
:= case MSG_MSG5:
:= strcpy(s2, "MSG5");
:= break;
:= case MSG_MSG6:
:= strcpy(s2, "MSG6");
:= break;
:= default:
:= // we shouldn't ever get here! But if we do return invalid message
:= return(INVALID_MSG);
:= }
:= if (stricmp(s1, s2) == 0)
:= {
:= //The strings are equal so return which one
:= return(msg);
:= }
:= }
:= // We didn't find a valid message so return an invalid one
:= return(INVALID_MSG);
:=}
:=
:=:=ok Mark
:=:=i untherstood what do you mean, but i have a little difficoult to do this.
:=:=My strategy to decode message is this:
:=:=my modem message always is:
:=:='CR' 'LF' 'MESSAGE' 'CR' 'LF'.
:=:=With this information i'm working in this mode:
:=:=I'm looking for the CR and LF than i buffered the chars to next CR.
:=:=Now i have a buffer, how can i compare it?
:=:=
:=:=Tnx
:=:=
:=:=I'm attach the function:
:=:=
:=:==============================================================
:=:=gsm_rx_string()
:=:=//Rx string from gsm: 'CR' 'LF' 'XXXXXXXXXX' 'CR' 'LF'
:=:={
:=:= MESSAGE_READ=0;
:=:= buffer_gsm=0;
:=:=
:=:= buffer_gsm[0] = getc();
:=:= if (buffer_gsm[0] != 'CR') // Find Carriage Return.
:=:= goto exit;
:=:=
:=:= buffer_gsm[0] = getc();
:=:= if (buffer_gsm[0] != 'LF') // Find Line Feed.
:=:= goto exit;
:=:=
:=:=
:=:= i=0; // Buffered the string to next CR
:=:= do {
:=:= buffer_gsm[i] = getc();
:=:= ++i;
:=:= } while ((buffer_gsm[i-1] != 'CR') || (i<35));
:=:=
:=:=
:=:= if ((buffer_gsm[i-1] == 'CR') && (i>0))
:=:= {
:=:= MESSAGE_READ=1;
:=:= i=i-1; // Delete CR from string.
:=:= }
:=:=
:=:=exit:
:=:=
:=:=}
:=:=
:=:==============================================================
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=:=Read the data into a buffer until you recieve the 'return char'. Then process the buffer using a string compare function:
:=:=:=
:=:=:=char string1[]="OK";
:=:=:=
:=:=:=if (stricmp(buffer, string1) == 0)
:=:=:={
:=:=:= //The strings are equal so do whatever
:=:=:=}
:=:=:=
:=:=:=or
:=:=:=
:=:=:=char string1[3]; // This must be big enough including the NULL terminator
:=:=:=
:=:=:=strcpy(string1, "OK");
:=:=:=if (stricmp(buffer, string1) == 0)
:=:=:={
:=:=:= //The strings are equal so do whatever
:=:=:=}
:=:=:=
:=:=:=:=Hi,
:=:=:=:=I'm searching a suggest to implement a decode serial ascii message on my firmware.
:=:=:=:=I have a modem connect on pic 16f877 uart and i have to decode the answer messages.
:=:=:=:=Example:
:=:=:=:=I sent a command to the modem with a printf string 'AT' and i must decode the answer 'OK'.
:=:=:=:=This message always end with 'return ascii char'
:=:=:=:=
:=:=:=:=How can i do?
:=:=:=:=Thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516620 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: Decode serial messages |
Posted: Sun Aug 03, 2003 8:20 am |
|
|
Typo, you need a ; after the }
enum message
{
MSG_OK,
MSG_TEST,
MSG_3,
MSG_4,
MSG_5,
MSG_6,
INVALID_MSG
};
:=Ok Mark,
:=I have introducted you suggest in my firmware, but the compiler tell me that there is an error on :
:='enum message msg;'
:=It espect a {
:=This is the first time that i use enum, do you think that there is an error?
:=
:=I have counted the {} but all opened are closed.
:=Can you help me?
:=
:=:=Try this out:
:=:=
:=:=enum message
:=:={
:=:= MSG_OK,
:=:= MSG_TEST,
:=:= MSG_3,
:=:= MSG_4,
:=:= MSG_5,
:=:= MSG_6,
:=:= INVALID_MSG
:=:=}
:=:=gsm_rx_string()
:=:=
:=:=//Rx string from gsm: 'CR' 'LF' 'XXXXXXXXXX' 'CR' 'LF'
:=:={
:=:= MESSAGE_READ=0;
:=:= buffer_gsm[0]=0;
:=:=
:=:= buffer_gsm[0] = getc();
:=:= if (buffer_gsm[0] != '\r') // Find Carriage Return.
:=:= return;
:=:=
:=:= buffer_gsm[0] = getc();
:=:= if (buffer_gsm[0] != '\n') // Find Line Feed.
:=:= return;
:=:= i=0;
:=:= while(i<35)
:=:= {
:=:= buffer_gsm[i] = getc();
:=:= if (buffer_gsm[i] == '\r')
:=:= {
:=:= // terminate our string
:=:= buffer_gsm[i] = 0
:=:= MESSAGE_READ=1;
:=:= break;
:=:= }
:=:= i++;
:=:= }
:=:= return;
:=:=}
:=:=
:=:=enum message Check_GSM_String(char *s1)
:=:={
:=:= enum message msg;
:=:= char s2[10]; // This must be big enough including the NULL terminator
:=:=
:=:= for (msg=0;msg
:=:= {
:=:= switch (msg)
:=:= {
:=:= case MSG_OK:
:=:= strcpy(s2, "OK");
:=:= break;
:=:= case MSG_TEST:
:=:= strcpy(s2, "TEST");
:=:= break;
:=:= case MSG_MSG3:
:=:= strcpy(s2, "MSG3");
:=:= break;
:=:= case MSG_MSG4:
:=:= strcpy(s2, "MSG4");
:=:= break;
:=:= case MSG_MSG5:
:=:= strcpy(s2, "MSG5");
:=:= break;
:=:= case MSG_MSG6:
:=:= strcpy(s2, "MSG6");
:=:= break;
:=:= default:
:=:= // we shouldn't ever get here! But if we do return invalid message
:=:= return(INVALID_MSG);
:=:= }
:=:= if (stricmp(s1, s2) == 0)
:=:= {
:=:= //The strings are equal so return which one
:=:= return(msg);
:=:= }
:=:= }
:=:= // We didn't find a valid message so return an invalid one
:=:= return(INVALID_MSG);
:=:=}
:=:=
:=:=:=ok Mark
:=:=:=i untherstood what do you mean, but i have a little difficoult to do this.
:=:=:=My strategy to decode message is this:
:=:=:=my modem message always is:
:=:=:='CR' 'LF' 'MESSAGE' 'CR' 'LF'.
:=:=:=With this information i'm working in this mode:
:=:=:=I'm looking for the CR and LF than i buffered the chars to next CR.
:=:=:=Now i have a buffer, how can i compare it?
:=:=:=
:=:=:=Tnx
:=:=:=
:=:=:=I'm attach the function:
:=:=:=
:=:=:==============================================================
:=:=:=gsm_rx_string()
:=:=:=//Rx string from gsm: 'CR' 'LF' 'XXXXXXXXXX' 'CR' 'LF'
:=:=:={
:=:=:= MESSAGE_READ=0;
:=:=:= buffer_gsm=0;
:=:=:=
:=:=:= buffer_gsm[0] = getc();
:=:=:= if (buffer_gsm[0] != 'CR') // Find Carriage Return.
:=:=:= goto exit;
:=:=:=
:=:=:= buffer_gsm[0] = getc();
:=:=:= if (buffer_gsm[0] != 'LF') // Find Line Feed.
:=:=:= goto exit;
:=:=:=
:=:=:=
:=:=:= i=0; // Buffered the string to next CR
:=:=:= do {
:=:=:= buffer_gsm[i] = getc();
:=:=:= ++i;
:=:=:= } while ((buffer_gsm[i-1] != 'CR') || (i<35));
:=:=:=
:=:=:=
:=:=:= if ((buffer_gsm[i-1] == 'CR') && (i>0))
:=:=:= {
:=:=:= MESSAGE_READ=1;
:=:=:= i=i-1; // Delete CR from string.
:=:=:= }
:=:=:=
:=:=:=exit:
:=:=:=
:=:=:=}
:=:=:=
:=:=:==============================================================
:=:=:=
:=:=:=
:=:=:=
:=:=:=
:=:=:=
:=:=:=:=Read the data into a buffer until you recieve the 'return char'. Then process the buffer using a string compare function:
:=:=:=:=
:=:=:=:=char string1[]="OK";
:=:=:=:=
:=:=:=:=if (stricmp(buffer, string1) == 0)
:=:=:=:={
:=:=:=:= //The strings are equal so do whatever
:=:=:=:=}
:=:=:=:=
:=:=:=:=or
:=:=:=:=
:=:=:=:=char string1[3]; // This must be big enough including the NULL terminator
:=:=:=:=
:=:=:=:=strcpy(string1, "OK");
:=:=:=:=if (stricmp(buffer, string1) == 0)
:=:=:=:={
:=:=:=:= //The strings are equal so do whatever
:=:=:=:=}
:=:=:=:=
:=:=:=:=:=Hi,
:=:=:=:=:=I'm searching a suggest to implement a decode serial ascii message on my firmware.
:=:=:=:=:=I have a modem connect on pic 16f877 uart and i have to decode the answer messages.
:=:=:=:=:=Example:
:=:=:=:=:=I sent a command to the modem with a printf string 'AT' and i must decode the answer 'OK'.
:=:=:=:=:=This message always end with 'return ascii char'
:=:=:=:=:=
:=:=:=:=:=How can i do?
:=:=:=:=:=Thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516623 |
|
|
mmanisse Guest
|
Re: Decode serial messages |
Posted: Mon Aug 04, 2003 1:51 pm |
|
|
There is another compiler error
enum message Check_GSM_String(char *s1)
{
enum message msg; //Compiler error espect {????
char s2[10];
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516661 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: Decode serial messages |
Posted: Mon Aug 04, 2003 5:33 pm |
|
|
Look at the for statement. This board doesn't like the less than sign it should read
for(msg=0;msg "less than" INVALID_MSG;msg++)
Also note that there are some typo's in the switch statement. For example, MSG_MSG3 should have been MSG_3 but it doesn't really matter since you are writing your own enums. There was another ';' missing in there also.
Regards
Mark
:=There is another compiler error
:=
:=enum message Check_GSM_String(char *s1)
:={
:= enum message msg; //Compiler error espect {????
:=
:= char s2[10];
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516663 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|