📄 main.bak
字号:
delay_s(1);
}
if(ucResult==FALSE) return FALSE;
u6.SndPtr += len;
}
//InitUart6Rec();
return TRUE;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for deleting the specified msg.
**
** Parameters:
** None
**
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
uchar DeleteOneMsg( uchar idx )
{
uchar ucResult;
//send: at+cmgd=n (n--index)
ucResult = sms_at_cmgd( idx );
return (ucResult);
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for deleting the specified msg.
**
** Parameters:
** None
**
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
uchar DeleteAllMsg( void )
{
if(gCHIPTYPE == _SIEMENS){ //delete first 5 msg.
send_at_cmd("AT+CMGD=1\r");
send_at_cmd("AT+CMGD=2\r");
send_at_cmd("AT+CMGD=3\r");
send_at_cmd("AT+CMGD=4\r");
send_at_cmd("AT+CMGD=5\r");
send_at_cmd("AT+CMGD=6\r");
send_at_cmd("AT+CMGD=7\r");
send_at_cmd("AT+CMGD=8\r");
send_at_cmd("AT+CMGD=9\r");
send_at_cmd("AT+CMGD=10\r");
}
else if(gCHIPTYPE == _HUAWEI){
send_at_cmd("AT+CMGD=1,4\r"); //delete all msg.
}
else{
send_at_cmd("AT+CMGD=1,4\r"); //delete all msg.
}
return TRUE;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for reading the specified msg.
**
** Parameters:
** None
**
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
uchar ReadOneMsg( uchar idx )
{
uchar i,ucResult;
uint phone_len,txt_len;
int pos1,pos2,pos3,pos4;
//send: at+cmgd=n (n--index)
ucResult = sms_at_cmgr( idx );
//error occurs
if(ucResult!=TRUE) return FALSE;
if(gSTATE==SEND) return FALSE;
//analayze the msg.
if(u6.Buf[0]!=':'||u6.Buf[1]!=' ') return FALSE;
if(gPROTOCOL==_PDU){
if(u6.Buf[3]!=','||u6.Buf[4]!=',') return FALSE;
pos1 = strpos(u6.Buf,1,0x0A); //search for 0x0a.
if(pos1>=0)
{
pos1++;
i = (uchar)(A2H(u6.Buf[pos1]));
i *= 16;
i = i+A2H(u6.Buf[pos1+1]); //get smsc number length.
pos1+=2*i+2; //pointer to Message Type Indicator: 04
pos1+=2; //pointer to Originating Address Length: 0D
i = (uchar)(A2H(u6.Buf[pos1]));
i *= 16;
i = i+A2H(u6.Buf[pos1+1]); //Originating Address Length
pos1+=2; //pointer to Originating Address type
pos1+=2; //pointer to Originating Address
//arrange phone number and phone length.
tempBuf[0]='+';
if(i%2!=0) i++;
phone_len = gsmSerializeNumbers(u6.Buf+pos1,tempBuf+1, i);
phone_len++;
//arrange context and length.
pos1 = pos1+i+18; //pointer to User Data Length
txt_len = A2H(u6.Buf[pos1]);
if(txt_len < 0) return FALSE;
txt_len *= 16;
txt_len = txt_len+A2H(u6.Buf[pos1+1]); //User Data Length
txt_len=txt_len*2;
pos4 = pos1+2;
}
else return FALSE;
}
else{ //default text mode
if(u6.Buf[2]!='"'||u6.Buf[3]!='R') return FALSE;
//search the first ','
pos1 = strpos(u6.Buf,1,',');
if(pos1>=0)
{
pos2 = strpos(u6.Buf,pos1+1,',');
pos3 = strpos(u6.Buf,pos2+1,',');
pos4 = strpos(u6.Buf,pos3+1,'+');
//redraw the phone number
phone_len = pos2-pos1-3;
memcpy(tempBuf,u6.Buf+pos1+2,phone_len);
tempBuf[phone_len]=0;
//redraw msg's context.
txt_len = IN_LEN-pos4-10;
//pointer move right 5.
pos4 = pos4 + 5;
}
else return FALSE;
}
//when sending,then quit reading,return false.
if(gSTATE==SEND) return FALSE;
//is equal to data center number?
// if(phone_len>=gPHONENUM_LEN){
// if(StrFind(tempBuf,gPHONENUM)>=0){
//when sending,then quit reading,return false.
if(gSTATE==SEND) return FALSE;
UART6_SendData(u6.Buf+pos4,txt_len);
//wait for u6 sending over.
u6WaitSndOver();
// }
// }
//when sending,then quit reading,return false.
// if(gSTATE==SEND) return FALSE;
return (TRUE);
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for reading the specified msg.
**
** Parameters:
** None
**
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
uchar ReadMsg( void )
{
uchar i,idx;
for(i=0;i<10;i++){
if(RIDX_BUF[i]>0){
idx = RIDX_BUF[i]; //msg index
//read msg.
if(ReadOneMsg( idx )==TRUE){
DeleteOneMsg( idx ); //delete msg.
RIDX_BUF[i] = 0;
}
}
}
//reset the flag: READ_FLG = FALSE
for(i=0;i<10;i++){
if(RIDX_BUF[i]>0) return TRUE;
}
READ_FLG = FALSE;
RIDX_LEN = 0;
return TRUE;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for UART6 data transfering.
**
** Parameters:
** txbuf: transfer buffer pointer
** txnum: buffer size
**
** Returns:
** MD_OK
** MD_ERROR
**
**-----------------------------------------------------------------------------
*/
void UART6_SendData( uchar* txbuf, uint txnum )
{
//---below------modified by wy. 080928 15:22----------------
if( txnum > 0 )
{
UART6_TX_ADDRESS = txbuf;
UART6_TX_CNT = txnum;
if((ASIF6 & 0x02) == 0)
{
TXB6 = *UART6_TX_ADDRESS++;
//while((ASIF6 & 0x02) == 1); // wait //
}
}
//--------------above---------------------------------------
/*
if( txnum < 1 ){
return; // 1 frame data at least //
}
UART6_TX_ADDRESS = txbuf;
UART6_TX_CNT = txnum;
*/
/*
if( txnum == 1) // only 1 frame data to transfer doesn't need contiously transfer //
{
if((ASIF6 & 0x02) == 0)
{
TXB6 = *UART6_TX_ADDRESS++;
}
else
{
//return MD_DATAEXISTS;
}
}
else
{
if((ASIF6 & 0x02) == 0)
{
TXB6 = *UART6_TX_ADDRESS++;
while((ASIF6 & 0x02) == 1); // wait //
UART6_TX_CNT--;
TXB6 = *UART6_TX_ADDRESS++;
}
else
{
//return MD_DATAEXISTS;
}
}
*/
}
/**-----------------------------------------------------------------------------
**
** Abstract:
** This function is the UART0 transfer end interrupt handler.
**
** Parameters:
** None
**
** Returns:
** None
**
**----------------------------------------------------------------------------*/
__interrupt void MD_INTST0( void )
{
u0scnt=0;
if(UART0_TX_CNT>0) UART0_TX_CNT--;
if( UART0_TX_CNT > 0 )
{
TXS0 = *UART0_TX_ADDRESS++;
}
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is the UART6 transfer end interrupt handler.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
__interrupt void MD_INTST6( void )
{
u6scnt=0;
//---below------modified by wy. 080928 15:22----------------
if(UART6_TX_CNT>0) UART6_TX_CNT--;
if( UART6_TX_CNT > 0 )
{
if(((ASIF6 & 0x02) == 0) && ((ASIM6 & 0x80) == 0x80))
{
TXB6 = *UART6_TX_ADDRESS++;
}
}
//----------above--------------------------------------------
/*
if( UART6_TX_CNT == 0 ){ // send data complete //
return;
}
if(((ASIF6 & 0x02) == 0) && ((ASIM6 & 0x80) == 0x80))
{
UART6_TX_CNT--;
if( UART6_TX_CNT > 0 ){
TXB6 = *UART6_TX_ADDRESS++;
}
}
*/
}
/****************************************************************************
**
** Abstract:
** UART0 interrupt when received data send out via UART0.
**
** Parameters:
** None
**
** Returns:
** None
**
****************************************************************************/
__interrupt void MD_INTSR0( void )
{
if( ASIS0 != 0 )
{
if(gDEBUG==_DEBUG){
SendRetInfo("\r\nu0err\r\n");
}
ch0 = RXB0;
ch0 = ASIS0;
return;
}
u0rcnt=0;
tm50cnt=0;
tm50Flag = FALSE;
tm51cnt=0;
tm51Flag = FALSE;
ch0 = RXB0;
if(gDEBUG==_DEBUG||gMODE==_CMDMODE){
UART6_SendData( &ch0, 1);
}
//---------------------------online---------------------
if(gMODE == _SMSMODE)
{
//system is not ready.
// if(gSYSTEM == FALSE) return;
//+CMTI: "ME",19
if(cmtiMatchFlag==FALSE){ //not match
if(cmtiflag==FALSE){
if(ch0==CMTI_BUF[0]){
cmtiidx = 1;
cmtiflag = TRUE;
}
}
else{
if(cmtiidx==8||cmtiidx==9){ //no compare SM or ME.
cmtiidx++;
}
else{
if(ch0 == CMTI_BUF[cmtiidx]){
cmtiidx++;
if(cmtiidx >= 12){
cmtiidx = 0;
cmtiMatchFlag = TRUE;
}
}
else{
cmtiidx = 0;
cmtiflag = FALSE;
cmtiMatchFlag = FALSE;
}
}
}
}
else{
//receive the msg index.
CMTI_BUF[14+cmtiidx] = ch0;
if(cmtiidx+1>=10) cmtiidx=-1;
if(++cmtiidx>=3){
if(CMTI_BUF[14+1]==0x0D){
RIDX_BUF[RIDX_LEN++] = CMTI_BUF[14]-'0';
}
else if(CMTI_BUF[14+2]==0x0D){
RIDX_BUF[RIDX_LEN++] = (CMTI_BUF[14]-'0')*10 + CMTI_BUF[15]-'0';
}
else{
RIDX_BUF[RIDX_LEN++] = (CMTI_BUF[14]-'0')*100 + (CMTI_BUF[15]-'0')*10 + CMTI_BUF[16]-'0';
}
READ_FLG = TRUE;
cmtiidx = 0;
cmtiflag = FALSE;
cmtiMatchFlag = FALSE;
}
}
}
//---------------------------off line ------------------
//no respone data to match
if(RESP_LEN==0)
{
Rsp1MatchFlag = TRUE;
return;
}
if(gCMDSTATE == CMD_RUN) //auto run at cmds
{
//save to u6.Buf[].
if(gSTATE!=SEND && gINFLAG==HOLD && IN_LEN<BUF_LEN){
//if(ch0!=0x0D && ch0!=0x0A ){
if(ch0!=0x0D){
if(IN_LEN>0 || ch0==':'){
u6.Buf[IN_LEN++] = ch0;
}
}
}
//not match
if(Rsp1MatchFlag==FALSE){
if(Rsp1Idx==0){
if(ch0 == RESP_BUF[0]){
if(RESP_LEN==1){
Rsp1MatchFlag=TRUE;
Rsp1Idx = 0;
}
else{
Rsp1Idx = 1;
}
}
}
else{
if(ch0 == RESP_BUF[Rsp1Idx]){
Rsp1Idx++;
if(Rsp1Idx >= RESP_LEN){
Rsp1MatchFlag = TRUE;
Rsp1Idx = 0;
}
}
else{
Rsp1Idx = 0;
Rsp1MatchFlag = FALSE;
}
}
}
//---------------addedy by wy .08/10/09.---------------------------------------
//If need to chcek the disconnect respone info.
if(Rsp2MatchFlag==FALSE){
if(Rsp2Idx==0){
if(ch0 == RESP2_BUF[0]){
if(RESP2_LEN==1){
Rsp2MatchFlag=TRUE;
Rsp2Idx = 0;
}
else{
Rsp2Idx = 1;
}
}
}
else{
if(ch0 == RESP2_BUF[Rsp2Idx]){
Rsp2Idx++;
if(Rsp2Idx >= RESP2_LEN){
Rsp2MatchFlag = TRUE;
Rsp2Idx = 0;
}
}
else{
Rsp2Idx = 0;
Rsp2MatchFlag = FALSE;
}
}
}
//-------------above-----------------------------------------
}
}
/****************************************************************************
**
** Abstract:
** UART6 interrupt receiption server function.
**
** Parameters:
** None
**
** Returns:
** None
**
****************************************************************************/
__interrupt void MD_INTSR6( void )
{
if( ASIS6 != 0 ) /*Error Occur*/
{
if(gDEBUG==_DEBUG){
SendRetInfo("\r\nu6err\r\n");
}
ch6 = ASIS6;
ch6 = RXB6;
return;
}
u6rcnt = 0;
tm51cnt = 0;
tm51Flag = FALSE;
ch6 = RXB6;
//--------------------------online----------------------
if(gMODE == _SMSMODE)
{
gSTATE = SEND;
//detect "@@@", return to cmd mode.
if(CMD_MODE_FLG==FALSE){
if(modeIdx==0){
if(ch6 == '@'){
modeIdx = 1;
}
}
else{
if(ch6 == '@'){
modeIdx ++;
if(modeIdx >=3){
CMD_MODE_FLG = TRUE;
modeIdx = 0;
}
}
else{
modeIdx = 0;
CMD_MODE_FLG = FALSE;
}
}
}
if(CMD_MODE_FLG==FALSE){
//too longer.
if(u6.Length>=BUF_LEN) return;
u6.Buf[u6.Length++]=ch6;
}
return;
}
//-------------off line---------------------------------
//at cmd is receiving not over.
if(u6.Finish==FALSE)
{
//the beginning o
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -