gprs/gsm 在linux下的应用
之前有篇随笔整理了一种在裸机下用状态机+超时的机制来操作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下的应用的更多相关文章
- linux下GPRS模块的应用程序
---------------------------------------------------------------------------------------------------- ...
- Linux下的编程实战【转】
一篇比较不错的文章, 降到了 makefile make , gcc编译器,GDB调试器, Linux文件系统,Linux文件API,.C语言库函数(C库函数的文件操作实际上是独立于具体的操作系统平台 ...
- 在Linux下用C语言实现短信收发
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lyserver/archive/2008/10/01/3007090.aspx 首先,我根据功能需要创建了几个头文件 ...
- linux下编程epoll实现将GPS定位信息上报到服务器
操作系统:CentOS 开发板:fl2440 开发模块:A7(GPS/GPRS),RT3070(无线网卡) ********************************************** ...
- 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 ...
- NodeJs在Linux下使用的各种问题
环境:ubuntu16.04 ubuntu中安装NodeJs 通过apt-get命令安装后发现只能使用nodejs,而没有node命令 如果想避免这种情况请看下面连接的这种安装方式: 拓展见:Linu ...
- Linux下服务器端开发流程及相关工具介绍(C++)
去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ...
- Linux下Nodejs安装(完整详细)
之前安装过windows下以及Mac下的node,感觉还是很方便的,不成想今天安装linux下的坑了老半天,特此记录. 首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码, ...
- (转载)linux下各个文件夹的作用
linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基 ...
随机推荐
- linux memcached安装
准备安装包: libevent-2.0.21-stable.tar.gz //Memcached服务端的依赖包 memcached-1.4.29.tar.gz //Memcached服务端 li ...
- 分布式一致性算法--Paxos
Paxos算法是莱斯利·兰伯特(Leslie Lamport)1990年提出的一种基于消息传递的一致性算法.Paxos算法解决的问题是一个分布式系统如何就某个值(决议)达成一致.在工程实践意义上来说, ...
- Sql Server 2016新功能之 Row-Level Security
Sql Server 2016 有一个新功能叫 Row-Level Security ,大概意思是行版本的安全策略(原来我是个英语渣_(:з」∠)_) 直接上例子.这个功能相当通过对表添加一个函数作为 ...
- js入门学习~ 运动应用小例
要实现的效果如下: 鼠标移入各个小方块,实现对应的效果(变宽,变高,移入透明,移出恢复)~~ (且各运动相互之前不干扰) 主要是练习多个物体的运动框架~~ --------------------- ...
- Linux下的C Socket编程 -- server端的简单示例
Linux下的C Socket编程(三) server端的简单示例 经过前面的client端的学习,我们已经知道了如何创建socket,所以接下来就是去绑定他到具体的一个端口上面去. 绑定socket ...
- 虚拟机上装uoj
前期准备: x64 ubuntu 镜像.vmware.ss账号 注意一定要有64位镜像! ss不是必须的,不过没有的话就等着下载一晚上吧... 首先先装好ubuntu,我装的是ubuntu-16.04 ...
- #id+变量
"#id"在解析的时候看成是一个整体字符串或者是一个具体的selector了,只有写成"#"+id,这是才会在解析时把id变量的值进行替换成被赋予的变量的值.链 ...
- [LeetCode] Combination Sum 组合之和
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- C#进阶系列——WebApi 身份认证解决方案:Basic基础认证
前言:最近,讨论到数据库安全的问题,于是就引出了WebApi服务没有加任何验证的问题.也就是说,任何人只要知道了接口的url,都能够模拟http请求去访问我们的服务接口,从而去增删改查数据库,这后果想 ...
- 【VS】vs修改大小写快捷键
选中一段英文 改成小写:Ctrl+U 改成大写:Ctrl+Shift+U