linux串口编程 gsm,linux 中用n_gsm实现3gpp MUX协议

n_gsm 是一种tty设备上的线路规程(line discipline),来实现3gpp MUX协议

n_gsm 实现方法如下:

1. kernel配置文件中 打开 CONFIG_N_GSM=y 编译内核

2. cat /proc/device | grep gsmtty 查看gsmtty

主节点号 3. 建立虚拟串口

例如:(例子中主节点号为251)

busybox mknod /dev/ttygsm0 c 251 0

busybox mknod /dev/ttygsm1 c 251 1

busybox mknod /dev/ttygsm2 c 251 2

busybox mknod /dev/ttygsm3 c 251 3

busybox mknod /dev/ttygsm4 c 251 4

4. 打开串口,进行属性设置

5 用CMUX设置modem mux模式

6.用TIOCSETD ioctl设置串口线路规程 (line discipline )

下面是示例代码

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define N_GSM0710 21

#define DEFAULT_SPEED B115200

#define SERIAL_PORT "/dev/ttyO3"

int main()

{

int fd;

int ldisc = N_GSM0710;

int status;

struct gsm_config c;

struct termios Opt;

//struct termios configuration;

fd = open(SERIAL_PORT, O_RDWR);

printf("\ntry to set 115200\n");

tcgetattr(fd, &Opt);

//Opt.c_lflag = 0;

Opt.c_iflag = 0;

Opt.c_cflag=7346;

Opt.c_lflag=0;

Opt.c_oflag=0; // 4

tcflush(fd, TCIOFLUSH);

cfsetispeed(&Opt, B115200);

cfsetospeed(&Opt, B115200);

status = tcsetattr(fd, TCSANOW, &Opt);

if (status != 0) {

printf("\ntcsetattr error");

}

tcflush(fd,TCIOFLUSH);

printf("\nterm set ok\n");

write(fd, "AT+SCMUX=3\r", 11);

sleep(3);

ioctl(fd, TIOCSETD, &ldisc);

ioctl(fd, GSMIOC_GETCONF, &c);

c.initiator = 1;

c.encapsulation = 0;

c.mru = 127;

c.mtu = 127;

ioctl(fd, GSMIOC_SETCONF, &c);

sleep(1);

daemon(0,0);

pause();

return 0;

}

精彩博文推荐阅读:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值