stm32中AT發(fā)送可變短信
* 文件名 :main.c
* 描述 :使用方法: p為要發(fā)送的短信內(nèi)容
* center為手機(jī)卡的短信中心
* tel為要發(fā)送的手機(jī)號的號碼
* 串口會打印AT操作的內(nèi)容
**********************************************************************************/
#include "stm32f10x.h"
#include "usart1.h"
#include "wchar.h"
#include
/*
* 函數(shù)名:main
* 描述 :主函數(shù)
* 輸入 :無
* 輸出 :無
*/
//0891683110101605F011000D91687100275510F0000800
//pdu模式數(shù)據(jù):0891683108200205F031000D91683157121468F00008AA 04 4F60597D
//0891
//683108200205F0
//31----------TPDU頭部
//00
//0D
//91
//683157121468F0
//00----------協(xié)議標(biāo)識
//08----------編碼方案 08中文編碼 00為英文或者數(shù)字
//AA----------有效期
//04----------用戶數(shù)據(jù)長度 用戶數(shù)據(jù)長度除2格式化為2位16進(jìn)制數(shù)即可。
//4F60597D
u8 messageContent[500];
u16 ATCMGSLen = 0;
//短信內(nèi)容長度:
u16 MessageLen = 0;
u16 ContentLen = 0;
int main(void)
{
int i = 0;
//這個可以靈活配置
wchar_t p[] = L"報警:車載設(shè)備00002溫濕度異常:當(dāng)前時間:2014年10月16日14時59分00秒,溫度:+23.3℃,濕度:73.2%RH。";
//短信中心需要從手機(jī)卡中獲取
u8 center[] = "3110101605F0";
//手機(jī)號碼需要設(shè)置
u8 tel[] = "7100275510F0";
//串口IO基本配置
USART1_Config();
ATCMGSLen += strlen("11000D91");
ATCMGSLen += 14;
ATCMGSLen += strlen("000800");
ATCMGSLen += 2;
MessageLen = (sizeof(p)/sizeof(wchar_t) - 1) * 4;
strncpy(&messageContent[0],"0891683110101605F0",strlen("0891683110101605F0"));
strncpy(&messageContent[0],"089168",strlen("089168"));
strncpy(&messageContent[0 + strlen("089168")],center,strlen(center));
strncpy(&messageContent[0 + strlen("0891683110101605F0")],"11000D9168",strlen("11000D9168"));
strncpy(&messageContent[0 + strlen("0891683110101605F0") + strlen("11000D9168")],tel,strlen(tel));
strncpy(&messageContent[0 + strlen("0891683110101605F0") + strlen("11000D9168") + strlen("7100275510F0")],
"000800",strlen("000800"));
ATCMGSLen += MessageLen;
ATCMGSLen = ATCMGSLen/2;
ContentLen = MessageLen / 2;
sprintf(&messageContent[0 + strlen("0891683110101605F0") + strlen("11000D9168") + strlen("7100275510F0") + strlen("000800")],
"%02x",ContentLen);
{
int len = strlen("0891683110101605F0") + strlen("11000D9168") + strlen("7100275510F0") + strlen("000800") + 2;
for(i = 0; i < sizeof(p)/sizeof(wchar_t) - 1 ; i ++)
sprintf(&messageContent[len + i * 4],"%04x",p[i]);
}
printf(" AT+CMGS=%drn",ATCMGSLen);
printf("%srn",messageContent);
for(;;)
{
}
}
/******************* (C) COPYRIGHT 2015 *****END OF FILE************/
評論