基于linux串口实现语音刷抖音

news2025/2/4 12:51:07

目录

1.开发逻辑图及模块

2.编程实现语音和开发板通信

3.手机接入Linux热拔插相关,打开手机开发者模式允许USB调试

4.用shell指令来操作手机屏幕,模拟手动滑屏幕

5.最终主程序代码


1.开发逻辑图及模块

逻辑图:

模块

(1)语音模块: SU-03T

(2)开发板全志H616

(3)一部手机

接线语音模块TX(B7)接RX,VCC接VCC,GND接GND

配置好语音模块

2.编程实现语音和开发板通信

通配符编译

代码示例:

vi uartTool.c

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "wiringSerial.h"

char myserialGetchar (const int fd)
{
        char x;

        if(read (fd,&x,1) != 1)
                return -1;

        return x;
}

int myserialOpen (const char *device, const int baud)
{
	struct termios options ;
	speed_t myBaud ;
	int status, fd ;
	switch (baud){
	case 9600: myBaud = B9600 ; break ;
	case 115200: myBaud = B115200 ; break ;
	}
	if ((fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1)
	return -1 ;
	fcntl (fd, F_SETFL, O_RDWR) ;
	// Get and modify current options:
	tcgetattr (fd, &options) ;
	cfmakeraw (&options) ;
	cfsetispeed (&options, myBaud) ;
	cfsetospeed (&options, myBaud) ;
	options.c_cflag |= (CLOCAL | CREAD) ;
	options.c_cflag &= ~PARENB ;
	options.c_cflag &= ~CSTOPB ;
	options.c_cflag &= ~CSIZE ;
	options.c_cflag |= CS8 ;
	options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
	options.c_oflag &= ~OPOST ;
	options.c_cc [VMIN] = 0 ;
	options.c_cc [VTIME] = 100 ; // Ten seconds (100 deciseconds)
	tcsetattr (fd, TCSANOW, &options) ;
	ioctl (fd, TIOCMGET, &status);
	status |= TIOCM_DTR ;
	status |= TIOCM_RTS ;
	ioctl (fd, TIOCMSET, &status);
	usleep (10000) ; // 10mS
	return fd ;
}

void serialSendstring (const int fd, const char *s)
{
	int ret;
	ret = write (fd, s, strlen (s));
	if (ret < 0)
	printf("Serial Puts Error\n");
}
int serialGetstring (const int fd, char *buffer)
{
	int n_read;
	n_read = read(fd, buffer,32);
	return n_read;
}

vi uartTool.h

int myserialOpen (const char *device, const int baud);
void serialSendstring (const int fd, const char *s);
int serialGetstring (const int fd, char *buffer);
char myserialGetchar (const int fd);

vi uartTest.c

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pthread.h>
#include "uartTool.h"


int fd;

void* readSerial()
{
	char cmd;
	while(1){
		cmd = myserialGetchar(fd);
		switch(cmd){
		case 'N':
		printf("next\n");
		break;
		case 'P':
		printf("pre\n");
		break;
		case 'Z':
		printf("zan\n");
		break;
		case 'Q':
		printf("qu\n");
		break;
	}
	}
}
int main(int argc, char **argv)
{
	char deviceName[32] = {'\0'};
	pthread_t readt;
	if(argc < 2){
		printf("uage:%s /dev/ttyS?\n",argv[0]);
		return -1;
	}
	strcpy(deviceName, argv[1]);
	if( (fd = myserialOpen(deviceName, 115200)) == -1){
		printf("open %s error\n",deviceName);
		return -1;
	}
	pthread_create(&readt, NULL, readSerial,NULL);
	while(1){sleep(10);}
}

3.手机接入Linux热拔插相关,打开手机开发者模式允许USB调试

a. 把手机接入开发板

b. 安装adb工具,在终端输入adb安装指令: sudo apt-get install adb

c. 输入命令dmesg能查看到手机接入的信息,但是输入adb devices会出现提醒 dinsufficient permissions for device: user in plugdev group; are your udev rules wrong?

d. 配置文件,以支持USB设备的热拔插,支持UDEV的机制 在/etc/udev/rules.d 文件夹下创建规则文件 cd /etc/udev/rules.d/ sudo vim 51-android.rules 在文件中添加内容 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0666"

e. 在手机开发者选项中,打开USB调试,重新拔插手机

f. 手机弹出调试提醒,点确认手机调试模式

重新拔插一下输入命令 adb devices显示SerialNumber

4.用shell指令来操作手机屏幕,模拟手动滑屏幕

adb shell input swipe 540 1300 540 500 100 向下滑动  540是水平的,1300是竖直方向,下是500

adb shell input swipe 540 500 540 1300 100 向上滑动

adb shell "seq 3 | while read i;do input tap 350 1050 & input tap 350 1050 & sleep 0.05;done;" 双击屏幕(实现点赞功能)

adb shell input keyevent 26 锁屏

5.最终主程序代码

vi uartTest.c

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pthread.h>
#include "uartTool.h"


int fd;

void* readSerial()
{
	char cmd;
	while(1){
		cmd = myserialGetchar(fd);
		switch(cmd){
		case 'N':
			printf("next\n");
			system("adb shell input swipe 540 1300 540 500 100");
		break;
		case 'P':
			printf("pre\n");
			system("adb shell input swipe 540 500 540 1300 100");
		break;
		case 'Z':
			printf("zan\n");
			system("adb shell \"seq 3 | while read i;do input tap 350 1050 &
			input tap 350 1050 & sleep 0.05;done;\"");
		break;
		case 'Q':
			printf("qu\n");
			system("adb shell input keyevent 26");
		break;
	}
	}
}
int main(int argc, char **argv)
{
	char deviceName[32] = {'\0'};
	pthread_t readt;
	if(argc < 2){
		printf("uage:%s /dev/ttyS?\n",argv[0]);
		return -1;
	}
	strcpy(deviceName, argv[1]);
	if( (fd = myserialOpen(deviceName, 115200)) == -1){
		printf("open %s error\n",deviceName);
		return -1;
	}
	pthread_create(&readt, NULL, readSerial,NULL);
	while(1){sleep(10);}
}

编译:

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/761883.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

读kafka生产端源码,窥kafka设计之道(上)

1. kafka 高吞吐之道-------异步提交批量发送 简约的发送接口----后面隐藏着并不简单的设计 kafka发送消息的接口非常简约&#xff0c;在简约的表面上&#xff0c;其背后却并不简单。先看下发送接口 kafkaProducer.send(new ProducerRecord(topic,msg), new Callback() {Ove…

8、链路层以太网协议,ARP协议32

网络层IP协议描述了通信中的起点到终点&#xff0c;但是数据不是飞过去的&#xff0c;是经过了大量的中间节点转发完成的。 一、以太网协议 1、MAC地址 物理硬件地址&#xff0c;是每一块网卡在出厂时设定的地址&#xff0c;固定且不可修改&#xff08;早期&#xff0c;现在可…

当DevOps遇到AI,黑马迎来3.0时代丨IDCF

随着GhatGPT的爆火&#xff0c;人工智能和研发效能&#xff0c;无疑成为了2023的两个最重要的关键词。大规模语言模型LLM和相关应用的快速发展正在对研发团队的工作方式产生深远影响&#xff0c;这几乎象征着新的生产力革命的到来。 那么&#xff0c;作为一名工程师&#xff0…

Chat GPT是什么,初学者怎么使用Chat GPT,需要注意些什么

目录 Chat GPT是什么 初学者怎么使用Chat GPT 使用Chat GPT需要注意什么 一些简单的prompt示例 Chat GPT是什么 Chat GPT是由OpenAI开发的一种大型语言模型&#xff0c;它基于GPT&#xff08;Generative Pre-trained Transformer&#xff09;架构。GPT是一种基于深度学习的…

【Matlab】智能优化算法_遗传算法GA

【Matlab】智能优化算法_遗传算法GA 1.背景介绍2.数学模型3.文件结构4.详细代码及注释4.1 crossover.m4.2 elitism.m4.3 GeneticAlgorithm.m4.4 initialization.m4.5 Main.m4.6 mutation.m4.7 selection.m4.8 Sphere.m 5.运行结果6.参考文献 1.背景介绍 遗传算法&#xff08;Ge…

(学习笔记)TCP 为什么是三次握手?不是两次、四次?

常规回答&#xff1a;“因为三次握手才能保证双方具有接收和发送的能力” 原因一&#xff1a;避免历史连接 三次握手的首要原因是为了防止旧的重复连接初始化造成混乱。 假设&#xff1a;客户端先发送了SYN(seq90)报文&#xff0c;然后客户端宕机了&#xff0c;而且这个SYN报…

一种电动汽车智能充电及收费云平台管理方案

摘要&#xff1a;对于电动汽车来说&#xff0c;主要是借助电力作为能源&#xff0c;有着多方面的优点。但是也存在着一定的问题&#xff0c;尤其在续航能力上相对较差。因此&#xff0c;在实际工作中要正确利用现代科学技术&#xff0c;让电动汽车实现智能充电。在研究中所涉及…

JavaScript中的let、const和var

在 JavaScript 中&#xff0c;let、const 和 var 是用于声明变量的关键字&#xff0c;在使用时有以下区别&#xff1a; 作用域&#xff1a;let 和 const 声明的变量具有块级作用域&#xff0c;只能在声明它的块中访问。而 var 声明的变量则是函数作用域或全局作用域&#xff0…

MS31001低压 5V DC 电机驱动

MS31001 是一款低压 5V 直流电机驱动芯片&#xff0c;为摄像机、 消费类产品、玩具和其他低压或者电池供电的运动控制类应用 提供了集成的电机驱动解决方案。 MS31001 能提供高达 0.8A 的输出电流。可以工作在 2.0~5.5V 的电源电压上。 MS31001 具有 PWM &#xff08…

NSSCTF随机一题

[GXYCTF 2019]Ping Ping Ping 应该是命令注入的题目&#xff0c;直接先ping一下本地&#xff0c;发现url栏有ip传参变化 接着就是利用命令注入符&#xff0c;尝试注入 它好像真的在ping&#xff0c;执行得特别慢&#xff0c;利用ls&#xff0c;查询到了flag文件 发现空格过…

LeetCode·每日一题·415. 字符串相加·模拟

作者&#xff1a;小迅 链接&#xff1a;https://leetcode.cn/problems/add-strings/solutions/2347085/mo-ni-zhu-shi-chao-ji-xiang-xi-by-xun-ge-fges/ 来源&#xff1a;力扣&#xff08;LeetCode&#xff09; 著作权归作者所有。商业转载请联系作者获得授权&#xff0c;非商…

自适应巡航控制系统研究(Matlab代码实现)

目录 &#x1f4a5;1 概述 &#x1f4da;2 运行结果 &#x1f389;3 参考文献 &#x1f468;‍&#x1f4bb;4 Matlab代码 &#x1f4a5;1 概述 据统计, 我国交通事故造成的伤亡人数每年超过10万人, 其中驾驶员人为原因 (疲劳、酒驾、误操作等) 所致事故逐渐升高.汽车交通…

Python多线程同步编程Event使用方法

一、Event简介 Event是Python多线程同步编程中的一种同步原语&#xff0c;它可以帮助我们协调多个线程的操作&#xff0c;以达到线程间传递信号、同步操作等目的。 Event主要有两种状态&#xff1a;已设置和未设置。当Event被设置时&#xff0c;所有等待该Event的线程都会被唤…

数据结构-Java逆天操作

本文章会对Java线性表的相关知识进行讲解&#xff0c;也会以Java代码示例来进行解释 这里写目录标题 本文章会对Java线性表的相关知识进行讲解&#xff0c;也会以Java代码示例来进行解释对线性表的讲解分析定义可以表示为线性表可以用多种方式来表示和实现&#xff0c;常见的实…

数据结构与算法——什么是单链表,链式存储结构详解

前面详细地介绍了顺序表&#xff0c;本节给大家介绍另外一种线性存储结构——链表。 链表&#xff0c;别名链式存储结构或单链表&#xff0c;用于存储逻辑关系为 "一对一" 的数据。与顺序表不同&#xff0c;链表不限制数据的物理存储状态&#xff0c;换句话说&#…

基于 SpringBoot 的高校宿舍管理系统设计与开发

1.引言 宿舍是大学生学习与生活的主要场所之一&#xff0c;宿舍管理是高校学工管理事务中 尤为重要的一项。随着我国高校招生规模的进一步扩大&#xff0c;学生总体人数的不断增加&#xff0c; 宿舍管理工作变得愈加沉重和琐碎&#xff0c;学生宿舍信息的采集、汇总、统计与分析…

火山引擎A/B测试“广告投放实验”基础能力重构实践 (DataFunTalk渠道)

更多技术交流、求职机会&#xff0c;欢迎关注字节跳动数据平台微信公众号&#xff0c;回复【1】进入官方交流群 企业在进行营销推广时&#xff0c;广告投放通常是必备环节之一。为了避免投放“乱烧钱”&#xff0c;在大规模投放前&#xff0c;企业和广告优化师都会希望在多种广…

Web3时代来临:你准备好了吗?

如果你正在浏览本文&#xff0c;那么很可能你已经是Web3时代的一部分了&#xff0c;或者至少是将要成为其中的一员。因为Web3时代即将来临&#xff0c;它将彻底改变我们对互联网的认识和使用方式。 那么&#xff0c;什么是Web3时代呢&#xff1f;简单来说&#xff0c;它是指基于…

uniapp微信小程序中使用echarts及修改报错代码

一、下载依赖 1.1、获取mpvue-echarts组件 可以先随便建个文件夹&#xff0c;然后 npm init。运行下面的命令行&#xff0c;下载依赖 npm install echarts mpvue-echarts找到node_modules\mpvue-echarts\下的文件&#xff0c;保留src文件夹&#xff0c;其他删除&#xff0c;复…

Xcode上传App Store Connect流程

一、上传前配置 1、配置好发布证书描述文件&#xff08;dis&#xff09; 2、配置好Version和Build的值&#xff0c;不配置上传过程会失败。 二、编译上传 1、菜单栏选择【Product】——【Archive】&#xff0c;开始编译&#xff0c;然后等待编译完成后&#xff0c;Xcode弹出编…