#include "SIM900A.h"
#include "main.h"
#include "usart.h"
 
uint8_t number_control=0;

uint8_t ByteSend=0x1A;//短信发送
 
//发送指令
void Sim900A_SendAtCmd(char* pCmd)
{
	char c;
	while(*pCmd!='\0')
	{
		c = *pCmd;
		HAL_UART_Transmit(&huart5, (uint8_t *)&c, 1,0xFFFF);
		pCmd++;
	}
}
 
//常规指令
void Sim900A_SendAT(void)
{
	Sim900A_SendAtCmd("AT+CPIN?\r\n");//查询 SIM 卡的状态
	HAL_Delay(1000);
	Sim900A_SendAtCmd("AT+CSQ\r\n");//查询信号质量
	HAL_Delay(1000);
	Sim900A_SendAtCmd("AT+COPS?\r\n");//查询当前运营商
	HAL_Delay(1000);
}
 
//拨打电话
void Sim900A_SendMsg1(void)
{
	Sim900A_SendAtCmd("ATD+\"00310033003100390032003400360030\";\r\n");//电话号码的unicode码
	HAL_Delay(1000);
}
 
//发送短信
void Sim900A_SendMsg2(char* pSam)
{
	Sim900A_SendAtCmd("AT+CMGF=1\r\n");//设置为文本模式
	HAL_Delay(2000);
	Sim900A_SendAtCmd("AT+CSCS=\"UCS2\"\r\n");//设置为 UCS2 编码字符集
	HAL_Delay(2000);
	Sim900A_SendAtCmd("AT+CSCA?\r\n");
	HAL_Delay(2000);
	Sim900A_SendAtCmd("AT+CSMP=17,167,0,8\r\n");//设置文本模式参数
	HAL_Delay(2000);
	if(number_control)
	{
	Sim900A_SendAtCmd("AT+CMGS=\"00310037003300300033003000330033003300300032 \"\r\n");//电话号码的unicode码
	}
	else
	{
	 Sim900A_SendAtCmd("AT+CMGS=\"00310033003100390032003400360030003500350032\"\r\n");//电话号码的unicode码
	}
	HAL_Delay(2000);
  Sim900A_SendAtCmd(pSam);//发送短信内容unicode码
	HAL_Delay(2000);
	HAL_UART_Transmit(&huart5, &ByteSend, 1,0xFFFF);
}



