⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 中文短信的编解码
💻 C
字号:
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#include "include/sms.h"

static SMS_INFO * m_wavecom = NULL;
#if 0
int sms_open_uart(void)
{
	int fd;
	struct termio 	New_Term_IO;

	if(0 > (fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK)))
	{
		printf("dbg_Open_UART: ERROR, errno %08x\r\n", errno);
		return fd;
	}

#if 1
	ioctl(fd, TCGETA, &New_Term_IO);

	//newtio.c_cflag = B115200 | CS8 | CREAD|HUPCL|CLOCAL;// | CLOCAL		
	//New_Term_IO.c_cflag 		=  B115200 | CRTSCTS | CS8 | CREAD;
	New_Term_IO.c_cflag 		=  B115200 | CS8 | CREAD;
	New_Term_IO.c_iflag 		= 1;
	New_Term_IO.c_oflag 		= 0;
	New_Term_IO.c_lflag 		= 0;
	New_Term_IO.c_cc[VMIN]		= 1;
	New_Term_IO.c_cc[VTIME]		= 0;

	ioctl(fd, TCSETAF, &New_Term_IO);
#endif
	return fd;
}
#endif
int main(int argc, char ** argv)
{
	int fd;
	
	printf("sms: Entry! para-%d\n",argc);
	fd = 1;/* sms_open_uart(); */
	if(0 > fd)
	{
		return ERROR;
	}
	m_wavecom = SMS_Init(fd);
	if(m_wavecom == NULL)
	{
		return ERROR;
	}
	while(1)
	{
		char s[1024];

		printf("\n/** SMS MENU **/\n");		
		printf("AT command for modem\n");		
		printf("P--set sms Para->\n");		
		printf("S--Send sms->\n");		
		printf("R.XX--Read sms(XX:index)\n");		
		printf("X--eXit sms entry\n>");
		scanf("%s",s);
		switch(s[0])
		{
		case 'a':
		case 'A':
			{
				AT_CMD 	at_send = {
					3,100000,NULL,(ATR_OK)
				};
				int len;
				
				at_send.at_str = &s[0];
				len = strlen(s);
				s[len++] = 0x0D;
				s[len] = 0;
				at_set(m_wavecom->modem,&at_send);
			}
			break;
		case 'P':
			{
				printf("\n/** SET SMS PARA **/\n");
				printf("X.XX   string for set(X:0-9,A-F)\n");
				printf("0.copy 1.SMSC 2.Octet 3.MR 4.DA 5.PID 6.DCS 7.VP\n>");
				scanf("%s",s);
				if((s[0]>='0') && (s[0]<='7'))
				{
					int key;

					key = (int)s[0]&0x0f;
					SMS_pdu_ctl(m_wavecom,(s[0]-'0'),&s[2]);
				}
			}
			break;
		case 'S':
			{
				int retval;
				
				retval = ERROR;
				printf("\n/** SEND SMS **/\n");
				printf("X.string   string for set(X:0-2)\n");
				printf("0.english 1.bytes 2.bg2312\n>");
				scanf("%s",s);
				if(s[0]=='0')
				{
					retval = SMS_Send_text(m_wavecom,NULL,&s[2]);
				}
				else if(s[0]=='1')
				{
					retval = SMS_Send_data(m_wavecom,NULL,&s[2],strlen(&s[2]));
				}
				else if(s[0]=='2')
				{
					retval = SMS_Send_gb2312(m_wavecom,NULL,&s[2]);
				}
				if(OK == retval)
				{
					printf("Send sms OK!");
				}
				else
				{
					printf("Send sms ERROR!");
				}
			}
			break;
		case 'R':
			if(SMS_check_recv(m_wavecom))
			{
				SMS_RECV_DATA msg;
				int len;
				
				len = atoi(&s[2]);
				if(OK == SMS_Recv(m_wavecom,&msg,len))
				{
					printf("\nget sms content:");
					printf("\nSMSC:");
					printf(msg.SMSC);
					printf("\nOA:");
					printf(msg.OA);
					printf("\nSCTS:");
					printf(msg.SCTS);
					printf("\nUD:");
					printf(msg.UD);
				}
			}
			else
			{
				printf("\nno sms!\n");
			}
			break;
		case 'X':
			return OK;
		default:
			break;
		}
	}
	
	SMS_Exit(m_wavecom);
	return OK;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -