主流程设计和浴室灯框架编写
1.首先编写mainPro.c,写出大概的业务框架
#include <stdio.h>
int main()
{
//1.指令工厂初始化
//2.设备控制工厂初始化
//3.线程池建立
// 3.1语音线程
// 3.2socket线程
// 3.3摄像头线程
// 3.4火灾线程
return 0;
}
2.编写控制工厂和指令工厂
inputCommand.h:
struct InputCommander
{
//指令名称、指令
char commandName[128];
char command[32];
//操作函数:语音等,要有打开函数
int (*Init)(char *name, char *ipAdress, char *port);
int (*getCommand)(struct InputCommander *voicer);
//日志
char log[1024];
struct InputCommander *next;
};
controlDevices.h:
struct Devices
{
char deviceName[128]; //设备名称
int status; //设备状态
//设备的开、关、初始化
int (*open)();
int (*close)();
int (*deviceInit)();
//如果是火灾的话需要读取状态
int (*readStatus)();
int (*changeStatus)(int status);
//指向下一个设备
struct Devices *next;
};
3.写出浴室灯的框架
bathroomLight.c:
#include "controlDevices.h"
int bathroomLightOpen()
{
}
int bathroomLightClose()
{
}
int bathroomLightInit()
{
}
int bathroomLightStatus(int status)
{
}
struct Devices bathroomLight = {
.deviceName = "bathroomLight",
.open = bathroomLightOpen,
.close = bathroomLightClose,
.deviceInit = bathroomLightInit,
.changeStatus = bathroomLightStatus
}
struct Devices* addBathroomLightToDeviceLink(struct Devices *phead)
{
if(phead == NULL){
return &bathroomLight;
}else{
bathroomLight.next = phead;
phead = &bathroomLight;
return phead;
}
}