智能家居(4)---火灾报警线程封装

封装火灾报警线程实现智能家居中的火灾报警功能
mainPro.c(主函数)

c 复制代码
#include <stdio.h>
#include "controlDevice.h"
#include "inputCommand.h"

#include <pthread.h>

struct Devices        *pdeviceHead  = 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;   

    }

}

void* fire_pthread(void *data)					//火灾报警线程处理函数
{
    struct Devices *fire;
    struct Devices *beep;
    int status;

    fire = findDeviceByName(pdeviceHead,"fire");        //从设备链表找出火灾检测和蜂鸣器
    beep = findDeviceByName(pdeviceHead,"beep");

    fire->deviceInit(fire->pinNum);                     
    beep->deviceInit(beep->pinNum);

     while(1){                                           //检测到火灾通过蜂鸣器报警
        status = fire->readStatus(fire->pinNum);
        if(status == 0){
            beep->open(beep->pinNum);
            printf("fire warning\n");
            delay(20000);
        }else
            beep->close(beep->pinNum);
            
    } 

 
 int main()
{
    pthread_t fire_pth;

    if(wiringPiSetup()<0){//初始化wiringPi外设库

            printf("wiringPi Init failed\n");
            return -1;
        }


    //1.指令工厂初始化


    //2.设备控制工厂初始化
  
    pdeviceHead = addFireToDeviceLink(pdeviceHead);                 //将火灾检测加入设备链表
    pdeviceHead = addBeepToDeviceLink(pdeviceHead);                 //将蜂鸣器加入设备链表

   
    //3.线程池建立
   

    //3.3火灾线程
    ret = pthread_create(&fire_pth,NULL,fire_pthread,NULL);
     if (ret != 0) {
        printf("Failed to create firethread.\n");
        return -1;
    }


    //等待线程退出
    pthread_join(fire_pth,NULL);


    return 0;
}
相关推荐
吴建旭 智宅焕3 天前
智能家居全国交付中执行端能力跃迁的架构设计:从标准装调到交付专家的系统化路径
网络·网络协议·智能家居
吴建旭 智宅焕4 天前
智能家居B端客户路径诊断的系统架构设计与实现:背景采集、经验分层与交付确定性
系统架构·智能家居
吴建旭 智宅焕5 天前
智能家居全国交付中契约边界的系统架构设计与实现:前置条件锁定、非标作业分离与交付确定性
智能家居
吴建旭 智宅焕6 天前
智能家居全国交付中报价工具与交付基础设施的架构分离设计:接口化路径与交付确定性系统实现
架构·智能家居
吴建旭 智宅焕7 天前
智能家居全国交付中内容信任前置系统的架构设计与实现:筛选机制、链路闭环与交付确定性
智能家居
星野云联AIoT技术洞察8 天前
传统设备接入 Tuya:从 DP、串口联调到样机与 OTA 验收
mcu·智能家居·涂鸦智能·涂鸦开发·tuya生态接入·tuya开发·mcu sdk
吴建旭 智宅焕9 天前
智能家居全国交付中电商型B端客户的责任契约隔离架构设计与实现
智能家居
吴建旭 智宅焕11 天前
智能家居全国交付中B端委托关系的架构设计与实现:指令权归属、契约隔离与交付确定性
智能家居
HANDY0920012 天前
从“不照人”到“剂量达标”:扇叶遮挡式UV-C空气消毒的工程边界与可验证评估框架
开发语言·人工智能·嵌入式硬件·智能家居
吴建旭 智宅焕13 天前
智能家居全国交付中售后规则执行层与客户关系层的分离架构设计:从人情协商到系统判定
智能家居