新手上路
- 积分
- 20
- 金钱
- 20
- 注册时间
- 2018-4-24
- 在线时间
- 3 小时
|
楼主 |
发表于 2018-4-24 17:42:57
|
显示全部楼层
uint8_t sendMessage(void)
{
uint8_t send_number_1[16] = {0};//
uint8_t send_number_2[16] = {0};
uint8_t index, i,j;
uint8_t endInputFlag = 0;
uint8_t message[128] = {0};//
uint8_t reply[128] = {0};
uint8_t ATCommand[128]= "at+cmgs=\"+86";
uint8_t ATCommand2[128]= "at+cmgs=\"+86";
uint32_t WaitTick;
UserAckKeyValueType keyval;
SendMessage_menu();
//第一个手机号
index = 0;
while((index < 16)&&(endInputFlag==0))
{
keyval = keyValueToUserAck();
if(keyval != NOKEY)
{
Delay_nms(100);
if(keyval < 10)
{
send_number_1[index++] = (uint8_t)keyval + 0x30; //dec2ascii
showMessageData_menu(send_number_1,send_number_2,message);
}
else if(keyval == KEY_OK)
{
endInputFlag = 1;
}
else if(keyval == CANCEL)
{
for(i = 0;i<index;i++)
{
send_number_1[i] = 0;
}
SendMessage_menu();
index = 0;
}
else if(keyval == LEFT)
{
if(index > 0)
{
send_number_1[index-1] = 0;
index--;
SendMessage_menu();
showMessageData_menu(send_number_1,send_number_2,message);
}
}
else
{
//nothing
}
}
}
if(index>11)
{
return 1;
}
//第二个手机号
index = 0;
endInputFlag=0;
while((index < 16)&&(endInputFlag==0))
{
keyval = keyValueToUserAck();
if(keyval != NOKEY)
{
Delay_nms(100);
if(keyval < 10)
{
send_number_2[index++] = (uint8_t)keyval + 0x30; //dec2ascii ¶ÁÈ¡ÊÖ»úºÅ
showMessageData_menu(send_number_1,send_number_2,message);
}
else if(keyval == KEY_OK)
{
endInputFlag = 1;
}
else if(keyval == CANCEL)
{
for(i = 0;i<index;i++)
{
send_number_2[i] = 0;
}
SendMessage_menu();
index = 0;
}
else if(keyval == LEFT)
{
if(index > 0)
{
send_number_2[index-1] = 0;
index--;
SendMessage_menu();
showMessageData_menu(send_number_1,send_number_2,message);
}
}
else
{
//nothing
}
}
}
if(index>12)
{
return 1;
}
//内容
index = 0;endInputFlag = 0;
while((index < 128)&&(endInputFlag==0))
{
keyval = keyValueToUserAck();
if(keyval != NOKEY)
{
Delay_nms(100);
if(keyval < 10)
{
message[index++] = (uint8_t)keyval + 0x30; //dec2ascii
showMessageData_menu(send_number_1,send_number_2,message);
}
else if(keyval == KEY_OK)
{
endInputFlag = 1;
}
else if(keyval == CANCEL)
{
for(i = 0;i<index;i++)
{
message[i] = 0;
}
index = 0;
}
else if(keyval == LEFT)
{
if(index > 0)
{
message[index-1] = 0;
index--;
SendMessage_menu();
showMessageData_menu(send_number_1,send_number_2,message);
}
}
else
{
//nothing to do
}
}
}
if(index>126)
{
return 1;
}
///////////
strcat((char*)message,"\x1a");
if(endInputFlag == 1)
{
//发送第一条短信
strcat((char*)ATCommand,(char*)send_number_1);
strcat((char*)ATCommand,"\"\r");
uartSendFrame2Phone((char*)ATCommand, strlen((char*)ATCommand));
WaitTick = local_ticktime();
while( !timeout( WaitTick, 3000 ) )
{
if(message_Send_Response==1)
{
getDataFromPhoneData(reply);
if(strstr((char*)reply, ">"))
{
uartSendFrame2Phone((char*)message, strlen((char*)message));
break;
}
}
if(error_reply == 1)
{
error_menu();
break;
}
}
//发送第二条短信
//Delay_nms(200);
strcat((char*)ATCommand2,(char*)send_number_2);
strcat((char*)ATCommand2,"\"\r");
uartSendFrame2Phone((char*)ATCommand2, strlen((char*)ATCommand2));
WaitTick = local_ticktime();
while( !timeout( WaitTick, 3000 ) )
{
if(message_Send_Response==0)
{
getDataFromPhoneData(reply);
if(strstr((char*)reply, ">"))
{
uartSendFrame2Phone((char*)message, strlen((char*)message));
break;
}
}
if(error_reply == 1)
{
error_menu();
break;
}
}
WaitTick = local_ticktime();
while( !timeout( WaitTick, 2000 ) )
{
if(AT_Is_Ok == 1)
{
break;
}
}
if(AT_Is_Ok == 1)
{
showMessageSuccess_menu();
}
else
{
showMessageError_menu();
}
}
return 0;
}
|
|