📄 smsdrive.c
字号:
DelayMs(250); //延时,等待TC35的反馈信息
DelayMs(250);
DelayMs(250);
DelayMs(250);
if(flag == 1 && count == 24)
{
if(rec[22]==0x3E && rec[23]==0x20)
{
deal_with_right();
flag=0;
count=0;
break;
}//如果第23和第24个字符分别是“>"和“空格”,那说明正确,直接退出,否则就说明出错了
else
{
deal_with_error();
flag=0;
count=0;
} //出错,进入下一次循环
}
}
}
/*===========================================
*函数名:TC35 文本内容填装 子函数
*参 数:U8 data2_buffer[] ,U8 User_ID
*功 能:把data2_buffer[]中的内容加为短信内容,如果装填内容失败,重给User_ID用户发送短信
*返回值:
*作 者:weishao2401 2009/4/29
*============================================*/
/*===========================================
* U8 code Content_warning[30] = "warning:gas leakage!\x1a";
*发送:77 61 72 6E 69 6E 67 3A 67 61 73 20 6C 65 61 6B 61 67 65 21 1A
*接收到:77 61 72 6E 69 6E 67 3A 67 61 73 20 6C 65 61 6B 61 67 65 21 1A
* 0D 0A 2B 43 4D 47 53 3A 20 32 30 32 0D 0A 0D 0A 4F 4B 0D 0A
*对应字符:
* warning:gas leakage!
* +CMGS: 202
*
* OK
*============================================*/
void TC35_ContentLoad(U8 data2_buffer[],U8 User_ID) // 文本内容填装 子函数
{
U8 len,i;
len = strlen(data2_buffer);
while(1)
{
uart_send(data2_buffer,len); //导入短信内容,发送
deal_with_attention();
for(i=0;i<18;i++) //长延时,发送短信时等待时间很长
{ DelayMs(250); DelayMs(250); }
if(flag == 1)
{
if(rec[(len+2)]==0x2B && rec[(len+3)]==0x43)
{
deal_with_right();
flag=0;
count=0;
sendflag=1;
break;
}//如果第23和第24个字符分别是“>"和“空格”,那说明正确,直接退出,否则就说明出错了
else
{
deal_with_error();
flag=0;
count=0;
sendflag=0;
TC35_AtCmgsT(User_ID);
DelayMs(250);
DelayMs(250);
DelayMs(250);
} //出错,进入下一次循环
}
else
{
deal_with_error();
flag=0;
count=0;
sendflag=0;
//TC35_AtCmgsT(User_ID);
DelayMs(250);
DelayMs(250);
DelayMs(250);
} //出错,进入下一次循环
}
}
//******************************* 用户指令接收与处理**************************
/*===========================================
设置来消息提示后,
接收到:0D 0A 2B 4D 43 54 49 3A 20 22 53 4D 22 2C 36 0D 0A
对应字符:
+CMTI: "SM",6<CR>
*=============================================*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************
* C51中字符串函数的扩充 *
*********************************************************************/
/*
int strsearch(U8 ptr2[])
//查字符串*ptr2在*ptr1中的位置
//本函数是用来检查字符串*ptr2是否完全包含在*ptr1中
//返回: 0 没有找到
// 1-255 从第N个字符开始相同
{
//、 uchar max_length;
/* U8 i,j,k;
U8 flag;
if(ptr2[0]==0) return(0);
flag=0;
for(i=0,j=0;i<MAX_TM-2;i++)
{
if(rec[i]==ptr2[j])
{//第一个字符相同
for(k=i;k<MAX_TM-2;k++,j++)
{
if(ptr2[j]==0)//比较正确
return(i+1); //返回值是整数,不含0
if(rec[k]!=ptr2[j])
{
}
}
j=0;
}
}
return(0);
int i=0,j=0;
int k=0;
for(i=0,j=0;i<1000;i++)
{
if(rec[i]==ptr2[j])
{led2=0;
if(k>=strlen(ptr2))
{
return 1;
}
j++;
k++;
}
else
{
j=0;
}
}
return 0;
}*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
U8 strsearch(U8 *ptr2,U8 *ptr1_at)//查字符串*ptr2在*ptr1中的位置
//本函数是用来检查字符串*ptr2是否完全包含在*ptr1中
//返回: 0 没有找到
// 1-255 从第N个字符开始相同
{
//、 uchar max_length;
U8 i,j,k;
U8 flag;
if(ptr2[0]==0) return(0);
flag=0;
for(i=0,j=0;i<MAX_TM-2;i++)
{
if(ptr1_at[i]==ptr2[j])
{//第一个字符相同
k=i;
//for(k=i;k<MAX_TM-2;k++,j++)
do {
if(ptr2[j]==0)//比较正确
return(i+1); //返回值是整数,不含0
if(ptr1_at[k]!=ptr2[j]) break;
k++;j++ ;
} while(k<MAX_TM-2) ;
j=0;
}
}
return(0);
}
/*********************************************************************
* C51中字符串函数的扩充 *
** 函数名称 : strsearch1()
** 函数功能 : 在指定的数组里连续找到相同的内容
** 入口参数 : ptr2=要找的内容, ptr1 当前数组, id 数组开始的第一个位置
**** 出口参数 : 0-没有 找到 >1 查找到
*********************************************************************/
//------在指定移态的数组里连续找到相同的内容---------------------------------------
//i=传来的指令, *ptr2=要找的内容, uchar *ptr1 当前数组
U8 strsearch1(U8 i,U8 *ptr2,U8 *ptr1)
{ U8 j=0,k;
k=i;
do{
if(ptr1[k]==ptr2[j])
{j++;k++;}
else return(0);
if(ptr2[j]==0) return(k);
}while(j<=60);
return(0xff);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************************************************
** 函数名称 read_sms()
** 函数功能 进行SIM卡的电话本读
** 全局变量或数组: receive_count 接收指针
** 入口参数 : AT指令 字符串str_code -para_temp str_at- uart_buff
*str_at=要复制的内容/转AT指令
str_code 短信内容
*ptr_tel 电话号码
** 出口参数 : 1-成功 0-失败
*********************************************************************************************************
*/
//====================================================
U8 read_sms(char* ptr1_at,char* ptr1_code,char* ptr_tel)
{
U16 i;
U8 idata j;
U8 idata PDU_TEXT;
// 英文模式
//+CMGR: "REC READ","8613818120592",,"09/06/25,14:16:33+32",145,4,0,0,"8613800210500",
//145,3
//END 0
// 2B 43 4D 47 52 3A 20 22 52 45 43 20 52 45 41 44 22 2C 22 38 36 31 33 38 31 38 31 32 30 35 39 32 22
//2C 2C 22 30 39 2F 30 36 2F 32 35 2C 31 34 3A 31 36 3A 33 33 2B 33 32 22 2C 31 34 35 2C 34 2C 30 2C 30
// 2C 22 38 36 31 33 38 30 30 32 31 30 35 30 30 22 2C
//31 34 35 2C 33 0D 0A 45 4E 44 0D 0A 30 0D
//READ","
if((i=strsearch("READ\",\"",ptr1_at)))
{ i=i+6;
for(j=0;j<20;j++)
{
ptr_tel[j]=rec[i++];
if(rec[i]==0x22) break;
}
ptr_tel[j+1]=0; ptr_tel[j+2]=0x00;
}
//AT_CMGF1
timercount=0; while(timercount<8) ;
//从短信代码中找到维一代码与内容间的字符
if((i=strsearch("\x0d\x0a",ptr1_at)))
{ i=i+1;//指针移动两位,指向内容的第一个字符
//----内容复制-将内容放到para_temp里------------
for(j=0;j<=MAX_T-3;j++)
{
ptr1_code[j]=ptr1_at[i++];
//大小写转换
toupper(ptr1_code[j]);
if(ptr1_at[i]==0x0d)
{ ptr1_code[++j]=0; break;
}
if(i>=MAX_TM) break;
}
//---------------------
}
PDU_TEXT=1;//文本
//------------------------------------------------------------
i=0;
if(strsearch1(i,"START",ptr1_code))
{
IO_OUT=0; //继电器吸合
strcpy(ptr1_code,"OUT ON OK\x1a");
return(1);
}
else if(strsearch1(i,"END",ptr1_code))
{
IO_OUT=1; // 继电器断开
strcpy(ptr1_code,"OUT OFF OK\x1a");
return(1);
}
//-------------------------------------------------------------------
else {
IO_OUT=1;
}
return(0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void RuleProcess(void)
{
while(1)
{
if(count>=15)
{
//if(rec[3]=='C'&&rec[4]=='M'&&rec[5]=='T'&&rec[6]=='I')
//{//ydl++;
if(rec[count-5]=='S'&&rec[count-4]=='M')
{int ll=0;
//
TC35_AtCmgr();
read_sms(rec,para_temp,TEL_temp);
flag=0;
count=0;
DelayMs(250);
DelayMs(250);
DelayMs(250);
DelayMs(250);
//ll=strsearch(Content_rule); // TC35读取短消息,rec[14]中存放的是新短信在SIM卡中所处地址
//if(ll)
// {
// led1=0;
//}
TC35_AtCmgd();
}
}
}
ReceiveFlag=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -