linux树莓派3b智能家居(二) 语音模块控制继电器

修改cmdline(略)

语音识别模块二次开发

识别口令后串口发送的信息
在这里插入图片描述
识别操作语音发送的信息(开所有灯,开红灯……)
在这里插入图片描述

核心思想

取指->译码->执行

为什么不让串口直接发送与继电器驱动对应的指针???
语音识别模块不好发送16进制格式的指针!!!!
一丶通过read串口读取指令(ascll形式)
二丶将读取到的指令转化为继电器驱动规定的输入指令格式
三丶将转化后的指令write到内核驱动

语音模块控制程序(删的只剩框架)

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <wiringPi.h>
#include <wiringSerial.h>

int decoding(char *code)//将串口指令转化为16进制指令
{
	return -1;
}

void speakControl()
{
	int fd_Serial = serialOpen("/dev/ttyAMA0",9600);
	if(fd_Serial == -1){
		printf("open serial fail\n");
		exit(-1);
	}

	int fd_Relay = open("/dev/relay",O_RDWR);
	if(fd_Relay == -1){
		perror("open");
		exit(-1);
	}

	int cmd = 0x01;
	char code[4] = {0};
	
	while(1){

		memset(code,'\0',4);
		read(fd_Serial,code,4);
		cmd = decoding(code);
				
		if(cmd == -1){
			printf("cmd not exist\n");
			continue;
		}
		//十六进制指令处理
		if(cmd == 0x0f){

		}else{
			
		}
	}			
}


int main(int argc,char **argv)
{

	if(-1 == wiringPiSetup())
	{
		printf("set up error\n");
		exit(-1);
	}	

	speakControl();


	return 0;
}

测试过程

1、语音识别模块测试

2、语音模块控制程序测试

2.1、使用串口助手测试

2.2、使用语音模块测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值