
METERING AND M BUS
main()
{
int InCall = 0;
int
NumBuf[13];
int
TmpBuf[255];
prs(0);
chcrt(1); /*Create a channel for send/rcv data*/
prtf(“\n Script Created!”);
/* Setup SPI bus and Max3100 interface */
if(mxc(MAXCFGWORD)) /* Enable,Sync High, every 2 bytes*/
{
prtf(“\n
Max3100
Configured!”);
}
while
(1)
{
int
i;
/*wait for incoming call*/
if(gtb(CALL_STATUS) == RINGING)
{
mset(NumBuf,0,13); /*Clear number buffer*/
clip(NumBuf,12);
/* get incoming number*/
prtf(“\n
Number
=
%s”,NumBuf);
if(scmp(NumBuf,DATA_NUMBER,12) == 0) /*if number
matches*/
{
/*answer
call*/
chw(1,"ata\n\r",5);
/* wait for data mode */
for(i=0;
i<
CALL_COUNT;i++)
{
st
=
chsts(1);
prtf("\n
chsts
=
%d",st);
if (st & 0x02) /* check second bit of status for
DCD */
{
break; /* data carrier detect */
}
dlyms(2); /* wait 100ms */
}
/* clear AT response from channel*/
chr(1,TmpBuf,255);
if(i
<
CALL_COUNT)
{
/*if
count
hasn't
expired, set to in call*/
prtf(“\n In Call!”);
InCall = 1;
}
}
}
if(InCall)
{
DoMBUS();
st
=
chsts(1);
InCall = st & 0x02; /*Make sure still in data call*/
}
else
{
prtf(“\n waiting for Call!”);
dlys(1); /* poll every 1 second when out of call */
}
} /*end while*/
}
LZT 123 8014 R1A
10