GPRS-SIM900模块应用程序——发短信打电话

这篇博客展示了如何使用C语言编写程序,通过GPRS-SIM900模块执行打电话和发送短信的功能。代码包括串口初始化、号码转换、发送英文和中文短信以及拨打电话的函数实现。
摘要由CSDN通过智能技术生成

上次使用过microcom命令执行过打电话发短信之后。。就像写一个自己的C程序执行它。。

我的虚拟机是centos6.5。。开发板是fl2440跑的Linux3.0的内核。。模块是SIM900的GPRS模块。。sim卡是移动大卡

先看代码

#include<termios.h>      //save struct from serial_init tcgetattr
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>


#define len_number  16
#define len_message 128
#define len_swap    32


struct message_info{  //信息结构体。。包括号码和信息
    char cnnu[len_number];
    char phnu[len_number];
    char message[len_message];
};


struct pdu_info{ //转换号码的结构体。。中文短信用到
    char cnswap[len_swap];
    char phswap[len_swap];
};
  
void serial_init(int fd) //初始化串口
{
    struct termios options;
    tcgetattr(fd, &options);
    options.c_cflag |= (CLOCAL | CREAD);
    options.c_cflag &= ~CSIZE;
    options.c_cflag &= ~CRTSCTS;
    options.c_cflag |= CS8;
    options.c_cflag &= ~CSTOPB;
    options.c_iflag |= IGNPAR;
    options.c_oflag  = 0;
    options.c_lflag  = 0;


    cfsetispeed(&options, B115200); //根据自己的波特率进行相应更改
    cfsetospeed(&options, B115200);
    tcsetattr(fd, TCSANOW, &options);
}
 
void swap(char number[], char swap[]) //发送中文短信时用到的转换号码的函数
{
    char ch1[] = "86";
    char tmp[len_number];
    int i;


    memset(swap, 0, len_swap);
    memset(tmp, 0, len_number);
    strcpy(swap, number);
    strcat(swap, "f");    //our phnu is 11 less then 12 so add "f" in the end
    strcat(ch1, swap);
    strcpy(swap, ch1);


    for(i=0; i<strlen(swap)-1; i+=2)
    {
        tmp[i+1] = swap[i];
        tmp[i] = swap[i+1];
    }


    strcpy(swap, tmp);
}


int send(int fd, char *cmgf, char *cmgs, char *message) //发送函数
{

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值