智能家居(3) —— 串口通信(语音识别)线程控制

本文详细介绍了智能家居系统中如何通过串口进行通信,并实现了语音识别的线程控制。主要涉及mianPro.c、inputCommand.h和voiceControl.c三个文件的代码实现,以及相应的测试结果。此外,还提及了网络服务器线程控制和智能家居项目的整体目录结构。
摘要由CSDN通过智能技术生成

目录

 一、串口通信线程控制代码

mianPro.c

inputCommand.h

voiceControl.c

测试结果

二、语音控制部分


 一、串口通信线程控制代码

mianPro.c

#include <pthread.h>
#include "controlDevice.h"
#include "inputCommand.h"

struct InputCommand *pcommandHead = NULL;				              //定义指令工厂初始链表头

struct InputCommand* findCommandByName(char *name, struct InputCommand *phead)
{
    struct InputCommand *tmp =phead;
    if(phead == NULL){
        return NULL;
    }else{
        while(tmp != NULL){
            if(strcmp(tmp->commandName,name)==0){
                return tmp;
            }
            tmp = tmp->next;
        }
        return NULL;
    }
}

void *voiceControlThread(void *data)			//“语音控制线程”执行函数
{   
    int nread;
    struct InputCommand *voiceHandler = NULL;
    voiceHandler =  findCommandByName("voice", pcommandHead);

    if(voiceHandler == NULL){
        printf("find voiceHandler error\n");
        pthread_exit(NULL);
    }else{
        if(voiceHandler->Init(voiceHandler) < 0){       //“语音控制”功能初始化
            printf("voiceControl init error\n");
            pthread_exit(NULL);
        }else{
            printf("voiceControl init success\n");
        }
        while(1){
            memset(voiceHandler->command,'\0',sizeof(voiceHandler->command));
            nread = voiceHandler->getCommand(voiceHandler);
            if(nread == 0){                                 //串口没有获取到指令
                printf("No voiceCommand received\n");
            }else{											//获取到指令
                printf("Get VoiceCommand -->%s\n",voiceHandler->command);        
            }
        }   
    }
}


int main()
{
  
    if (wiringPiSetup () == -1) { 
        fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ; 
        return 1 ; 
    }

    pthread_t voiceControl_thread;

    //指令工厂初始化
    pcommandHead = addVoiceControlToInputCommandLi
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值