老手网

erlang之短信猫驱动【超级精品】

授权形式: 免费版
更新时间: 2013-04-23 21:10:09
软件语言: 英文
软件平台: Linux
软件类别:
文件大小: δ֪
评论等级:
浏览次数: (今日:,本周:,本月:
软件简介
erlang之短信猫驱动【超级精品】
Linux环境下使用,可以适当修改在windows下环境下运行
使用AT指令
解决中文编码问题
解决超长短信问题,使用多条短信拼合技术

int smsinit(const char* smsc,const char* phone,const char* msg,const com_attr_t *ca)
{	
	//sp = (SM_PARAM *)malloc(sizeof(SM_PARAM));
	memset(sp.TP_SCTS,0,16);
	strcpy(sp.SCA,smsc);
	strcpy(sp.TP_UD,msg);
	strcpy(sp.TPA,phone); 
	sp.TP_PID = 0;
	sp.TP_DCS = GSM_UCS2;
	//sp->TP_DCS = GSM_7BIT;
	sp.index = (short)0;
		
	int fd;
	if((fd=openComm(ca)) < 0)
	{
		printf("can Not Open device!\r\n");
		return -1;
	}
	char ans[2048]={0}; 	 
	writeComm("AT\r", 3);
	readComm(ans, 128);
	if (strstr(ans, "OK") == NULL)
	{
		printf("can not connet modem device!\r\n");
		closeComm();
		return -1;   //return FALSE
	}
	
	// ECHO OFF    
	writeComm("ATE0\r", 5);   
	readComm(ans, 128); 
	// PDU    
	writeComm("AT+CMGF=0\r", 10);   
	readComm(ans, 128); 
	
	return 0;  
	//return TRUE
	
}
int send_sms(const char* smsc, const char* phone, 
			 const char* msg,const com_attr_t * ca)
{
	if((smsinit(smsc,phone,msg,ca))<0 )
	{
		//fprintf(stderr,"GSM init failed!\n");
		printf("GSM init failed!\r\n");
		return -1;
	}

	    int result = 0;
	    int i=0;
	    int nPduLength;         
	    unsigned char nSmscLength;     
	    int nLength;           
	    char cmd[4096]={0};	        
	    char pdu[4096]={0};	         
	    char ans[4096]={0};
	    char sendpdu[10][4096];
	    
	    printf("Ready to send SMS ,Please standby!\r\n");
	    
	    nPduLength = gsmEncodePdu(&sp, pdu); 
	    printf("MSG=[%d][%s]\r\n",strlen(msg),msg);	
	    printf("PDU=[%d][%s]\r\n",nPduLength,pdu);
	    
	   
	    
	    int sendlength = 0;
	    int count = 0;	   
	    while(sendlength < nPduLength)
	    {
		    memset(sendpdu[count],0,4096);
		    if((nPduLength-sendlength) > 268)
		    {
			strncpy(sendpdu[count],pdu+sendlength,268); 
			sendlength += 268;
			count++;		    
		   }	
		    else	
		    {
			strncpy(sendpdu[count],pdu+sendlength,nPduLength-sendlength);
			sendlength = nPduLength;
			count++;			    
		    }			  
	    }
	    		   
	   printf("count=[%d]\r\n",count);	    
	    
	   for(i=0;i ", 4) == 0)   
		   {   	
			writeComm(buf, strlen(buf));
			readComm(ans, 1024);
			printf("ans=[%s]\r\n",ans);
			if (strstr(ans, "+CMGS:") == NULL) result = -2;			    
		    }
	    
	   }	    
	    
	    writeComm("ATE1\r", 5);   
	    readComm(ans, 128); 

	    printf("SMS send Complete![%d]\r\n",result);
	    closeComm();
	    return result; 

}

 

下载地址
-

Copyright © 2012 - 2014 oldhand.cn All Rights Reserved. 粤ICP备13025864号