int SendMySMS(const char* smsc,const char * mobile, const char * msg)
{
Smg sndinfo;
sprintf(SMSC,smsc);
memset( &sndinfo, 0x0, sizeof( sndinfo ) );
sprintf( sndinfo.mobile, mobile );
sprintf( sndinfo.alarmstr, msg );
printf("SendSms %s %s %s /n",smsc,mobile,msg);
return SendSms( fd, &sndinfo );
}
int SendSms( int fd, Smg *sinfo)
{
char smsstr[200];
char *dev;
int nread;
char ans[16384];
int bget=0;
int gettime=0;
GetSendInfo( sinfo );
sprintf( smsstr, "AT+CMGS=%s/r", sinfo->smslen );
printf(smsstr); printf("/r/n");
write( fd, smsstr, strlen(smsstr) );
memset(ans,0,16384);
nread= gsmGetResponse(ans,16384);
printf("nread=%d/r/n",nread);
if (strstr(ans, ">")!= NULL)
{
printf(sinfo->smsinfo); printf("/r/n");
return write( fd, sinfo->smsinfo, strlen(sinfo->smsinfo) );
}
return 0;
}
int GetSendInfo( Smg *sinfo )
{
int i,slen,len,datalen;
unsigned char msglen;
char smsc[20];
char a,b;
char out[400];
char nstr[20],hstr[6],cmsg[400],tmp[400];
char buff[400],tt[10],ll[3],omsg[400];
memset( buff,0x0, 400 );
memset( out,0x0, 400 );
memset( omsg,0x0, 400 );
memset( nstr, 0, 20 );
memset( hstr, 0, 6 );
sprintf( smsc, SMSC );
HmCovert( smsc, nstr );
slen = strlen( nstr )/2+1;
IntToHex( hstr, slen );
sprintf( sinfo->smsinfo, "%s91%s1100", hstr, nstr );
memset( nstr, 0, 20 );
memset( hstr, 0, 6 );
HmCovert( sinfo->mobile, nstr );
len = strlen( nstr )-1;
IntToHex( hstr, len );
sprintf( tmp, "%s81%s", hstr, nstr );
strcat( sinfo->smsinfo, tmp );
memset( cmsg, 0, 400 );
memset( hstr, 0, 6 );
msglen = ctou( sinfo->alarmstr, cmsg );
memcpy( buff, cmsg, msglen );
printf("msglen=%d/r/n",msglen);
for( i=0; i<msglen; i++ )
{
sprintf( tt, "%02x", buff[i] );
if( strlen( tt ) > 2 )
sprintf( ll, "%.2s", tt+strlen(tt)-2 );
else
sprintf( ll, "%.2s", tt );
strcat( omsg, ll );
}
for( i=0; i<strlen( omsg ); i+=4 )
{
a = omsg[i];
b = omsg[i+1];
omsg[i] = omsg[i+2];
omsg[i+1] = omsg[i+3];
omsg[i+2] = a;
omsg[i+3] = b;
}
len = strlen( omsg )/2;
IntToHex( hstr, len );
sprintf( tmp, "0008A7%s%s", hstr, omsg );
strcat( sinfo->smsinfo, tmp );
sinfo->smsinfo[strlen(sinfo->smsinfo)] = 0x1a;
TouAlpha( sinfo->smsinfo );
printf("smsinfolen=%d/r/n",strlen( sinfo->smsinfo ));
datalen = strlen( sinfo->smsinfo )/2-1-slen;
sprintf( sinfo->smslen, "%d", datalen );
}