当前位置: 首页 > news >正文

接外包的平台seo培训赚钱

接外包的平台,seo培训赚钱,西安做网站找缑阳建,医药企业网站设计制作封装语音线程&#xff08;语音通过串口和主控设备进行交流&#xff09;实现对智能家居中各种灯光的控制 mainPro.c(主函数) #include <stdio.h> #include "controlDevice.h" #include "inputCommand.h" #include <pthread.h>struct Devices …

封装语音线程(语音通过串口和主控设备进行交流)实现对智能家居中各种灯光的控制

mainPro.c(主函数)

#include <stdio.h>
#include "controlDevice.h"
#include "inputCommand.h"
#include <pthread.h>struct Devices        *pdeviceHead  = NULL;         //设备工厂链表头
struct InputCommander *pcommandHead = NULL;         //指令工厂链表头struct Devices* findDeviceByName(struct Devices *phead,char *name)          //在设备链表中查找设备(语音和socket均可使用)
{struct Devices *tmp = phead;if(tmp == NULL){printf("The devicesLink is NULL");return NULL;}else{while(tmp != NULL){if(strcmp(tmp->deviceName,name) == 0){return tmp;}tmp = tmp->next;}return NULL;   }}struct InputCommander* findCommanderByName(struct InputCommander *phead,char *name)     //在控制链表中查找相关控制
{struct InputCommander *tmp = phead;if(tmp == NULL){printf("The commanderLink is NULL");return NULL;}else{while(tmp != NULL){if(strcmp(tmp->commandName,name) == 0){return tmp;}tmp = tmp->next;}return NULL;   }}void doCommand(struct InputCommander *cmd)                              //根据传入的命令控制相关设备
{struct Devices *tmp = NULL;if(strstr(cmd->command,"START")){                                   //初始化所有设备tmp = findDeviceByName(pdeviceHead,"bathroomLight");if(tmp != NULL) tmp->deviceInit(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"bedroomLight");if(tmp != NULL) tmp->deviceInit(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"livingroomLight");if(tmp != NULL) tmp->deviceInit(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"restaurantLight");if(tmp != NULL) tmp->deviceInit(tmp->pinNum);printf("The devices all init success\n");}else if(strstr(cmd->command,"OL1")){                               //打开卫生间灯tmp = findDeviceByName(pdeviceHead,"bathroomLight");if(tmp != NULL) tmp->open(tmp->pinNum);printf("The bathroomLight already open\n");}else if(strstr(cmd->command,"CL1")){                               //关闭卫生间灯tmp = findDeviceByName(pdeviceHead,"bathroomLight");if(tmp != NULL) tmp->close(tmp->pinNum);printf("The bathroomLight already close\n");}else if(strstr(cmd->command,"OL2")){                               //打开卧室灯tmp = findDeviceByName(pdeviceHead,"bedroomLight");if(tmp != NULL) tmp->open(tmp->pinNum);printf("The bedroomLight already open\n");}else if(strstr(cmd->command,"CL2")){                               //关闭卧室灯tmp = findDeviceByName(pdeviceHead,"bedroomLight");if(tmp != NULL) tmp->close(tmp->pinNum);printf("The bedroomLight already close\n");}else if(strstr(cmd->command,"OL3")){                               //打开客厅灯tmp = findDeviceByName(pdeviceHead,"livingroomLight");if(tmp != NULL) tmp->open(tmp->pinNum);printf("The livingroomLight already open\n");}else if(strstr(cmd->command,"CL3")){                               //关闭客厅灯tmp = findDeviceByName(pdeviceHead,"livingroomLight");if(tmp != NULL) tmp->close(tmp->pinNum);printf("The livingroomLight already close\n");}else if(strstr(cmd->command,"OL4")){                               //打开餐厅灯tmp = findDeviceByName(pdeviceHead,"restaurantLight");if(tmp != NULL) tmp->open(tmp->pinNum);printf("The restaurantLight already open\n");}else if(strstr(cmd->command,"CL4")){                               //关闭餐厅灯tmp = findDeviceByName(pdeviceHead,"restaurantLight");if(tmp != NULL) tmp->close(tmp->pinNum);printf("The restaurantLight already close\n");}else if(strstr(cmd->command,"ALL1")){                              //打开所有的灯tmp = findDeviceByName(pdeviceHead,"bathroomLight");if(tmp != NULL) tmp->open(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"bedroomLight");if(tmp != NULL) tmp->open(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"livingroomLight");if(tmp != NULL) tmp->open(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"restaurantLight");if(tmp != NULL) tmp->open(tmp->pinNum);printf("The Light all open success\n");}else if(strstr(cmd->command,"ALL0")){                              //关闭所有的灯tmp = findDeviceByName(pdeviceHead,"bathroomLight");if(tmp != NULL) tmp->close(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"bedroomLight");if(tmp != NULL) tmp->close(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"livingroomLight");if(tmp != NULL) tmp->close(tmp->pinNum);tmp = findDeviceByName(pdeviceHead,"restaurantLight");if(tmp != NULL) tmp->close(tmp->pinNum);printf("The Light all close success\n");}}void* voice_pthread(void *data)				//语音识别(串口通信)处理线程函数
{struct InputCommander *voiceHandler;int n_read;voiceHandler = findCommanderByName(pcommandHead,"voice");if(voiceHandler == NULL){printf("find voice error\n");pthread_exit(NULL);}else{if(voiceHandler->Init(voiceHandler) < 0 ){printf("%s init error\n",voiceHandler->commandName);pthread_exit(NULL);}elseprintf("%s init success\n",voiceHandler->commandName);while(1){n_read = voiceHandler->getCommand(voiceHandler);if(n_read == 0){printf("no command from voice\n");}else{//根据指令进行控制printf("read %d message-->:%s",n_read,voiceHandler->command);doCommand(voiceHandler);                //执行命令}}}}int main()
{pthread_t voice_pth;if(wiringPiSetup()<0){//初始化wiringPi外设库printf("wiringPi Init failed\n");return -1;}//1.指令工厂初始化pcommandHead = addVoiceToCommandLink(pcommandHead);             //将语音控制加入命令控制链表//2.设备控制工厂初始化pdeviceHead = addBathroomLightToDeviceLink(pdeviceHead);        //将卫生灯加入设备链表pdeviceHead = addbedroomLightToDeviceLink(pdeviceHead);         //将卧室灯加入设备链表pdeviceHead = addRestaurantLightToDeviceLink(pdeviceHead);      //将餐厅灯加入设备链表pdeviceHead = addLivingroomLightToDeviceLink(pdeviceHead);      //将客厅灯加入设备链表pdeviceHead = addFireToDeviceLink(pdeviceHead);                 //将火灾检测加入设备链表pdeviceHead = addBeepToDeviceLink(pdeviceHead);                 //将蜂鸣器加入设备链表//3.线程池建立//3.1语音线程int ret = pthread_create(&voice_pth,NULL,voice_pthread,NULL);if (ret != 0) {printf("Failed to create voicethread.\n");return -1;}//等待线程退出pthread_join(voice_pth,NULL);return 0;
}

inputCommand.h(控制类)

#include <wiringPi.h>
#include <stddef.h>
#include <wiringSerial.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>          
#include <sys/socket.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>struct InputCommander
{char commandName[128];      //命令名字char command[32];           //具体命令char deviceName[128];       //打开的设备名,比如串口char port[12];              //端口号char ipAddress[32];         //ip地址int (*Init)(struct InputCommander *commder);int (*getCommand)(struct InputCommander *commder);int fd;     //文件描述符int baud;   //波特率int s_fd;   //socket服务端文件描述符int c_fd;   //客户端文件描述符char log[1024]; //日志struct InputCommander *next;
};struct InputCommander *addVoiceToCommandLink(struct InputCommander *phead);				//语音控制加入命令控制链表

voiceControl.c(语音)

#include "inputCommand.h"int voiceInit(struct InputCommander *voiceMes)
{int fd;fd =serialOpen(voiceMes->deviceName,voiceMes->baud);//打开串口if(fd<0){printf("open serial fail!\r\n");//判断串口打开是否成功return -1;}elsevoiceMes->fd = fd;//传回串口文件描述符return fd;}int voiceGetCommand(struct InputCommander *voiceMes){int nread = 0;memset(voiceMes->command,0,sizeof(voiceMes->command));nread = read(voiceMes->fd,voiceMes->command,sizeof(voiceMes->command));return nread;}struct InputCommander voiceControl = {.commandName = "voice",.command = {'\0'},.deviceName = "/dev/ttyAMA0",.baud = 9600,.Init = voiceInit,.getCommand = voiceGetCommand,.log = {'\0'},.next = NULL,};struct InputCommander *addVoiceToCommandLink(struct InputCommander *phead)
{if(phead == NULL){return &voiceControl;}else{voiceControl.next=phead;phead = &voiceControl;return phead;}
}
http://www.ds6.com.cn/news/60532.html

相关文章:

  • 手机怎么制作图片网站自然优化
  • 自己做的网站和ie不兼容网站怎样优化seo
  • 中小型网站建设与管理设计总结权威seo技术
  • 修改wordpress 2m整站优化是什么意思
  • 可以做兼职的网站宁波seo搜索排名优化
  • 南京移动网站建设seo课程在哪培训好
  • 做动态网站的app关键词排名 收录 查询
  • 企业网站后台管理系统简述搜索引擎优化
  • 兰州新区农投建设网站柳州网站建设哪里有
  • 青岛设计网站的公司哪家好免费发帖推广的平台
  • 台州网站制作价格今日热点头条新闻
  • 网站不用了 怎么关闭学网络运营需要多少钱
  • 北京做网站商标的公司发布软文的平台有哪些
  • MATLAB 做网站b站在哪付费推广
  • 怎么做自助交易网站开展网络营销的企业
  • 西安手机网站定制网站建设武汉大学人民医院
  • 企业网站托管收费标准网络推广平台有哪些渠道
  • wordpress 主题名称浙江seo
  • 中国网站建设第一品牌百度开户代理商
  • 住友官方网站建设搜索引擎优化排名工具
  • 英文网站制作公司哪家好关键词seo资源
  • axure可以做网站seo顾问是干什么
  • 国人在线做网站怎么样seo服务价格表
  • 网上免费做网站朋友圈推广
  • 宣城市住房和城乡建设委员会网站代发qq群发广告推广
  • 国外做电子元器件在哪个网站怎么做网络销售
  • 注册免费微网站网络口碑营销的成功案例
  • java做简易网站沪深300指数基金排名
  • 企业网站seo方案石家庄seo代理商
  • 高端网站建设哪里好seo优化团队