之前有篇随笔整理了一种在裸机下用状态机+超时的机制来操作gprs/gsm,linux下就不需要了,本身有完善的调度机制,在等待的流程中直接sleep就行了。

下面是飞凌OK6410下的 demo, 其他基于linux的硬件平台都是一样操作,与前面那篇裸机状态下的处理作个对比。

main.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <termios.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <string.h>

#ifndef  __TTY_H__
#define __TTY_H__

int tty_init();
int tty_end();
int tty_write(char *buf,int nbytes);
int tty_writecmd(char *buf,int nbytes);
int tty_read(char *buf,int nbytes);
#endif

#ifndef __GPRS_H__
#define __GPRS_H__

void gprs_init();
void gprs_msg();
void gprs_read();
#endif

#define BAUDRATE B9600
#define COM0 "/dev/ttySAC0"
#define COM1 "/dev/ttySAC1"
#define COM2 "/dev/ttySAC2"

static int fd;
static struct termios oldtio,newtio;

#define ENDMINITERM 27
#define FALSE    0
#define TRUE      1
volatile int STOP=FALSE;
int GET_GPRS_OK=FALSE;
int baud=B9600;

int tty_end()
{
      tcsetattr(fd,TCSANOW,&oldtio);
      close(fd);
}
int tty_read(char *buf,int nbytes)
{
    return read(fd,buf,nbytes);
}

int tty_write(char *buf,int nbytes)
{
    int i;
    ; i<nbytes; i++) {
        write(fd,&buf[i],);
        usleep();
    }
    return tcdrain(fd);
}

int tty_writecmd(char *buf,int nbytes)
{
    int i;
    ; i<nbytes; i++) {
        write(fd,&buf[i],);
        usleep();
    }
    write(fd,);
    sleep();
    return tcdrain(fd);
}

int tty_init()
{
    fd = open(COM1, O_RDWR ); //| O_NONBLOCK);//
    ) {
            perror(COM1);
            exit(-);
      }

      tcgetattr(fd,&oldtio); /* save current modem settings */
    bzero(&newtio, sizeof(newtio)); 

    newtio.c_cflag = baud | /*CRTSCTS |*/ CS8 /*| CLOCAL | CREAD */;
    newtio.c_iflag = IGNPAR | ICRNL;
    newtio.c_oflag = ;
    newtio.c_lflag = ICANON;

     newtio.c_cc[VINTR]    = ;     /* Ctrl-c */
     newtio.c_cc[VQUIT]    = ;     /* Ctrl-\ */
     newtio.c_cc[VERASE]   = ;     /* del */
     newtio.c_cc[VKILL]    = ;     /* @ */
     newtio.c_cc[VEOF]     = ;     /* Ctrl-d */
     newtio.c_cc[VTIME]    = ;
     newtio.c_cc[VMIN]     = ;
     newtio.c_cc[VSWTC]    = ;     /* '\0' */
     newtio.c_cc[VSTART]   = ;     /* Ctrl-q */
     newtio.c_cc[VSTOP]    = ;     /* Ctrl-s */
     newtio.c_cc[VSUSP]    = ;     /* Ctrl-z */
     newtio.c_cc[VEOL]     = ;     /* '\0' */
     newtio.c_cc[VREPRINT] = ;     /* Ctrl-r */
     newtio.c_cc[VDISCARD] = ;     /* Ctrl-u */
     newtio.c_cc[VWERASE]  = ;     /* Ctrl-w */
     newtio.c_cc[VLNEXT]   = ;     /* Ctrl-v */
     newtio.c_cc[VEOL2]    = ;     /* '\0' */ 

    tcflush(fd, TCIFLUSH);
    tcsetattr(fd,TCSANOW,&newtio);/*set attrib      */
    ;
}

void gprs_msg()
{
    char a;
    };
    char text[]="Hello!Witech!";
    tty_write("at", strlen("at"));
    sleep();
    write(fd,);
    sleep();
    tty_write("at+cmgf=1", strlen("at+cmgf=1"));
    sleep();
    write(fd,);
    sleep();
    tty_write("at+cmgs=13730191959", strlen("at+cmgs=13730191959"));
    sleep();
    write(fd,);
    sleep();
    tty_write("Hello!Witech!", strlen("Hello!Witech!"));
    sleep();
    tty_write(ctl, );
    sleep();
    printf("sending is end!!\n");
}

int main(void)
{
    void * retval;
    tty_init();
    printf("wait for sending a message!\n");
    fflush(stdout);
    printf("sending......\n");
    gprs_msg();
    printf("Bye-Bye!\n");
    tty_end();
    exit(); }

很久以前收集的几个demo,附件打包下载http://files.cnblogs.com/files/dong1/Linux_gprs.rar

end

gprs/gsm 在linux下的应用的更多相关文章

  1. linux下GPRS模块的应用程序

    ---------------------------------------------------------------------------------------------------- ...

  2. Linux下的编程实战【转】

    一篇比较不错的文章, 降到了 makefile make , gcc编译器,GDB调试器, Linux文件系统,Linux文件API,.C语言库函数(C库函数的文件操作实际上是独立于具体的操作系统平台 ...

  3. 在Linux下用C语言实现短信收发

     本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lyserver/archive/2008/10/01/3007090.aspx 首先,我根据功能需要创建了几个头文件 ...

  4. linux下编程epoll实现将GPS定位信息上报到服务器

    操作系统:CentOS 开发板:fl2440 开发模块:A7(GPS/GPRS),RT3070(无线网卡) ********************************************** ...

  5. UMTSkeeper: keep your UMTS/GPRS/GSM connection alive automatically

    UMTSkeeper: keep your UMTS/GPRS/GSM connection alive automatically by Elias from Mintaka This page i ...

  6. NodeJs在Linux下使用的各种问题

    环境:ubuntu16.04 ubuntu中安装NodeJs 通过apt-get命令安装后发现只能使用nodejs,而没有node命令 如果想避免这种情况请看下面连接的这种安装方式: 拓展见:Linu ...

  7. Linux下服务器端开发流程及相关工具介绍(C++)

    去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ...

  8. Linux下Nodejs安装(完整详细)

    之前安装过windows下以及Mac下的node,感觉还是很方便的,不成想今天安装linux下的坑了老半天,特此记录. 首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码, ...

  9. (转载)linux下各个文件夹的作用

    linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基 ...

随机推荐

  1. IT软件的编程方向 - 进阶者系列 - 学习者系列文章

    IT软件经过了这么些年的发展,已经形成了很多的软件公司和开发团队,而且当前编程语言也有很多种,让开发人员能够有很大的选择.现在国际上的开发阵营基本分为ASP.NET.JAVA和PHP三种,但是每种开发 ...

  2. 用Retrofit发送请求中添加身份验证

    用Retrofit发送请求中添加身份验证====================在安卓应用开发中, retrofit可以极大的方便发送http网络请求,不管是GET, POST, 还是PUT, DEL ...

  3. 用批处理脚本一键安装 MongoDB

    下载MongoDB安装文件,解压到D:\MongoDB: 运行脚本: @echo off set mongobin=D:\MongoDB ::在mongodb文件夹下建立data,log文件夹 md ...

  4. OpenWRT镜像爬虫搭建本地源

    网上的爬虫不能用,还是先表达谢意,不过我比较懒不喜欢重复写别人写的教程,只贴出修改,怎么用自己看教程吧. 我自己改了一版可以正常爬: #!/usr/bin/env python #coding=utf ...

  5. webpack入门——webpack的安装与使用

    一.简介 1.什么是webpack webpack是近期最火的一款模块加载器兼打包工具,它能把各种资源,例如JS(含JSX).coffee.样式(含less/sass).图片等都作为模块来使用和处理. ...

  6. [LeetCode] Paint House II 粉刷房子之二

    There are a row of n houses, each house can be painted with one of the k colors. The cost of paintin ...

  7. CheungSSH国产自动化运维工具开源Web界面

    CheungSSH web2.0 发布文档 CheungSSH 简介 CheungSSH是一款国人自主研发的Linux运维自动化管理服务器软件,秉着为企业降低运营成本,解放管理员双手和自动化生产的理念 ...

  8. C#网络编程——IPHostEntry

    using System; using System.Net; namespace study { class IPHostEntrySample { public static void func( ...

  9. [开源].NET高性能框架Chloe.ORM-完美支持SQLite

    扯淡 这是一款轻量.高效的.NET C#数据库访问框架(ORM).查询接口借鉴 Linq(但不支持 Linq).借助 lambda 表达式,可以完全用面向对象的方式就能轻松执行多表连接查询.分组查询. ...

  10. java 分页功能

    1.分页工具类 package com.bw.shop.util; import java.util.List; import com.sun.org.apache.regexp.internal.r ...