#include"TcPch.h"
#pragma hdrstop
 
#include"DEVICE.h"
#include"EV.h"
#include"OP.h"
#include"SC.h"
#include"BoatModule.h"
#include"debug.h"
BaseDevice* CDEVICE::getDevice(const char* moduleDotName){
	//name should be module.name
	BaseDevice** device = devices.get(moduleDotName);
	if (device == NULL) {
		return NULL;
	}
	return  *device;
 
}
BaseDevice* CDEVICE::getDevice(const char* module,const char *name) {
	//name should be module.name
	char moduleDotName[MAX_NAME_LEN];
	sprintf(moduleDotName, "%s.%s", module, name);
	BaseDevice** device = devices.get(moduleDotName);
	if (device == NULL) {
		return NULL;
	}
	return  *device;

}
BaseDevice* CDEVICE::getDeviceByIndex(int index) {
	BaseDevice** device = devices.getByIndex(index);
	if (device == NULL) {
		return NULL;
	}
	return  *device;
	

}
void CDEVICE::addDevice(BaseDevice * device){
	if (device == NULL){
		return;
	}
	char name[MAX_NAME_LEN];
	sprintf(name, "%s.%s", device->module, device->name);

	devices.set(name, device,__FILE__,__LINE__);

}
int CDEVICE::getDeviceCount() {
	return devices.length;
}

CDEVICE::CDEVICE() {
	//initAllDeviceAttr();
	//initIoVariableMap();
}
 
void CDEVICE::create() {
	
}
CDEVICE* DEVICE;

char MODULE_NAME[MAX_NAME_LEN];
void initDEVICE();
void initEnvironment() {
	strcpy(MODULE_NAME, "PM1");
	//TODO:未来支持多腔体时可以用参数覆盖MODULE_NAME
	static CEV staticEV;
	
	EV = &staticEV;

	static CSC staticSC;
	SC = &staticSC;
	
	static COP staticOP;
	OP = &staticOP;
	OP->subscribe("default", []()->OperatorStatusEnum {
		logger->error("Found a undefine OP:%s", OP->current->params.get(0));
		return OperatorStatusEnum::SUCCESS;
		});

	static CDEVICE staticDEVICE;
	DEVICE = &staticDEVICE;
	initDEVICE();

	static BoatModule staticBoatModule;
	boatModule = &staticBoatModule;
	

}
void closeDEVICE() {

}
//AUTOIO_BEGIN
void initDEVICE(){
	void initIoHeater();
	initIoHeater();
	void initIoAlarmSignal();
	initIoAlarmSignal();
	void initIoShutter();
	initIoShutter();
	void initIoDoor();
	initIoDoor();
	void initFurnaceSignalTower();
	initFurnaceSignalTower();
	void initIoPressureMeter();
	initIoPressureMeter();
	void initIoAlarmSignal();
	initIoAlarmSignal();
	void initIoSensor();
	initIoSensor();
	void initIoTrigger();
	initIoTrigger();
	void initIoFIMS();
	initIoFIMS();
	void initIoStocker();
	initIoStocker();
	void initIoLP();
	initIoLP();
	void initIoBufferMotor();
	initIoBufferMotor();
	void initIoFFU();
	initIoFFU();
	void initIoWaferRobot();
	initIoWaferRobot();
	void initIoFurnaceMotor();
	initIoFurnaceMotor();
	void initIoAPC();
	initIoAPC();
	void initIoMFC();
	initIoMFC();
	void initIoMFM();
	initIoMFM();
	void initIoValve();
	initIoValve();
}
//AUTOIO_END
