RCM3700 GSM

Hi I am a new user trying to use an RCM3700 to monitor remote I/O . I am note sure what the problem is with this code . I have changed it a couple of times , such that i am loosing track of where i’m going. can someone help

#define CINBUFSIZE 255
#define COUTBUFSIZE 255
#define TIMEOUT 500
char modembuf[160];
const char hpnum[] = {“+6142”};

void INIT(void)
{
serCopen(19200);
//serDflowcontrolOff();
//serDparity(PARAM_NOPARITY);
serCwrFlush();
serCrdFlush();
}

void clrbuf(void)
{
serCwrFlush();
serCrdFlush();
memset(modembuf, 0x00, 160);
}

int fnMsDelay ( unsigned long iDelay )
{
unsigned long ul0;
ul0 = MS_TIMER; // get current timer value
while ((MS_TIMER - ul0)< iDelay);
return 0;
}

void GSM_INIT(void)
{
int looping;
looping = 0;
puts("
GSM_INIT");

tryagain:
clrbuf();
serCputs(“AT\r”); //waking modem from sleep
fnMsDelay(500);
serCread(modembuf, 255, TIMEOUT);
//printf("
Ready to accept command: %s", modembuf);
if((strstr(modembuf,“OK”))
{
clrbuf();
serCputs(“ATEO\r”); //no echo
fnMsDelay(TIMEOUT);
serCread(modembuf, 255, TIMEOUT);
//printf("
No Echo:%s", modembuf);
/* if(strstr(modembuf,“OK”))
{
clrbuf();
serDputs(“AT$NOSLEEP=1\r”); //N0 Sleep
fnMsDelay(TIMEOUT);
serDread(modembuf, 255, TIMEOUT);
printf("
Nosleep: %s ",modembuf);
*/ }
if(strstr(modembuf,“OK”))
{
clrbuf();
serCputs(“AT+CMGF=1\r”);// Text mode
fnMsDelay(TIMEOUT);
serCread(modembuf, 100, TIMEOUT);

                           printf("

GSM_INIT OK");
return;

                           }
                           looping++;
                           printf("

Looping: %d
“,looping);
if(looping == 20)
{
printf(”
GSM_INIT FAILED");
return;
}
goto tryagain;

int sendsms(char type)
{
clrbuf();
serCputs(“AT+CMGS="”);
serCputs(hpnum);
serCputs(“"\r”);
puts("
AT+CMGS="“);
puts(hpnum);
puts(”"\r");
while(serCwrFree() != COUTBUFSIZE);
fnMsDelay(250);
memset(moedmbuf);
if(strstr(modembuf, “+CMG”))
return 1;
if(strstr(modembuf, “>”));
{
serCrdFlush();

                if(type)
                {
                        serCputs("NORMAL");
                        puts("NORMAL");
                        }

                        else
                        {
                            serCputs("ALARM");
                            puts("ALARM");
                            }

fnMsDelay(500);
serCputc(0x1A);

fnMsDelay(3000);
memset(modembuf, 0x00, 25);
serCread(modembuf, 25, 100);
puts(modembuf);
if(strstr(modembuf, “+CMG”))
{
return 1;
}
serCputs(“\r”);
serCputc(0x1A);
return 0;
}
}

itn sendsms1(char type)
{
clrbuf();
serCputs(“AT+CMGS="”);
serCputs(hpnum1);
serCputs(“"\r”);
puts("
AT+CMGS="“);
puts(hpnum1);
puts(”"\r");
while(serCwrFree() != COUTBUFSIZE);
fnMsDelay(250);
memset(modembuf, 0x00, 25);
serCread(modembuf, 25, 500);
puts(modembuf);
if(strstr(moembuf, “+CMG”))
return 1;
if(strstr(modembuf, “>”))
{
serCrdFlush();
if(type)
{
serCputs(“NORMAL”);
puts(“NORMAL”);
}

                            else
                            }
                            serCputs("ALARM");
                            puts("ALARM");
                            }
                            fnMsDelay(500);
                            serCputc(0x1A);

                            fnMsDelay(3000);
                            memset(modembuf, 0x00, 25);
                            serCread(modembuf, 25, 100);
                            puts(modembuf);
                            if(strstr(modembuf, "+CMG"))
                            {
                            return 1;
                            }
                            serCputs("\r");
                            serCputc(0x1A);
                            return 0;
                            }
                            }

void main(void)
{
char DI, last_DI;
INIT()
GSM_INIT();
last_DI = 1;
while(1)
{
DI = BitRdPortI(PBDR, 2);
if(DI != last_DI)
{
while(!sendsms(DI));
while(!sendsms(DI));
last_DI = DI;
}
}
}