Пример #1
0
int simple_relayTimeout(int src,int dst,int timeout)
{	int rcc,wcc,rcc1,wcc1,nio;

	rcc = wcc = 0;
	for( nio = 0;; nio++ ){
		if( !IsWindows95() || file_ISSOCK(src) )
		if( timeout != 0 )
		if( PollIn(src,timeout) <= 0 )
			break;
		if( relay1(NULL,src,dst,&rcc1,&wcc1) <= 0 )
			break; 
		rcc += rcc1;
		wcc += wcc1;
	}
	syslog_ERROR("simple_relay [%d -> %d] = (%d -> %d) / %d\n",
		src,dst,rcc,wcc,nio);
	return rcc;
}
Пример #2
0
int ChangeRelays (double tdiff, double hdiff) {
	if ( tdiff > RFans[0] ) RFant[0] = 1;
	else if ( tdiff > RFans[1] ) RFant[0] = 2;
	else if ( tdiff > RFans[2] ) RFant[0] = 3;
	else if ( tdiff > RFans[3] ) RFant[0] = 4;
	else RFant[0] = 5;

	if ( hdiff > RFans[0] ) RFant[0] = 1;
	else if ( hdiff > RFans[1] ) RFant[0] = 2;
	else if ( hdiff > RFans[2] ) RFant[0] = 3;
	else if ( hdiff > RFans[3] ) RFant[0] = 4;
	else RFant[0] = 5;

	if ( tdiff > RFans[0] ) RHepat[0] = 1;
	else if ( tdiff > RFans[1] ) RHepat[0] = 2;
	else if ( tdiff > RFans[2] ) RHepat[0] = 3;
	else if ( tdiff > RFans[3] ) RHepat[0] = 4;
	else RHepat[0] = 5;

	if ( tdiff < RHeats[0] ) RHeatt[0] = 1;
	else if ( tdiff < RHeats[1] ) RHeatt[0] = 2;
	else if ( tdiff < RHeats[2] ) RHeatt[0] = 3;
	else if ( tdiff < RHeats[3] ) RHeatt[0] = 4;
	else RHeatt[0] = 5;

	if ( hdiff < RHums[0] ) RHumt[0] = 1;
	else if ( hdiff < RHums[1] ) RHumt[0] = 2;
	else if ( hdiff < RHums[2] ) RHumt[0] = 3;
	else if ( hdiff < RHums[3] ) RHumt[0] = 4;
	else RHumt[0] = 5;

	// tempState: 1=below minTemp, 2=above maxTemp now cooling, 3=too high turn all fans on
	// humState:  1=below minHum,  2=above maxHum now cooling
	// Relays: RHepa 1, RHum  2, RFan  3, RHeat 4
	// relayx(Y), Y: 0=Turn off, 1=Turn on, 2=Leave on, 3=Leave off 

	if ( tempState == 1 && humState == 1 ) {// Heat on, humidifier on
		// Relay 1 HEPA
		relay1(0); // Turn relay1 off
		usleep(500000);

		// Relay 2 Humidifier
		if (timestampL - RHumTS - RHumt[RHumt[0]] < RHumo[RHumt[0]]) { // If not end of off timer
			if (timestampL - RHumTS < RHumt[RHumt[0]]) { // If not at end of on timer
				relay2(2); // Leave relay2 on
			} else {
				if (RHumo[RHumt[0]] + RHumt[RHumt[0]] - (timestampL - RHumTS) <= 0) {
					relay2(1); // Turn relay2 on
				}
				else {
					relay2(3); // Leave relay2 off
				}
			}
		} else {
			relay2(1); // Turn relay2 on
		}
		usleep(500000);

		// Relay 3 Circulatory Fan
		relay3(0); // Turn relay3 off
		usleep(500000);

		// Relay 4 Heater
		if (timestampL - RHeatTS - RHeatt[RHeatt[0]] < (int)(RHeato[RHeatt[0]]*wfactor)) { // If not end of on and off timer
			if (timestampL - RHeatTS < RHeatt[RHeatt[0]]) { // If not at end of on timer
				relay4(2); // Leave relay4 on
			} else {
				if ((int)(RHeato[RHeatt[0]]*wfactor) + RHeatt[RHeatt[0]] - (timestampL - RHeatTS) <= 0) relay4(1); // Turn relay4 on
				else relay4(3); // Leave relay4 off
			}
		} else relay4(1); // Turn relay4 on
	}
	else if ( tempState == 2 && humState == 1 )
	{
		// Relay 1 HEPA
		relay1(0); // Turn relay1 off
		usleep(500000);

		// Relay 2 Humidifier
		if (timestampL - RHumTS - RHumt[RHumt[0]] < RHumo[RHumt[0]]) { // If not end of off timer
			if (timestampL - RHumTS < RHumt[RHumt[0]]) { // If not at end of on timer
				relay2(2); // Leave relay2 on
			} else {
				if (RHumo[RHumt[0]] + RHumt[RHumt[0]] - (timestampL - RHumTS) <= 0) {
					relay2(1); // Turn relay2 on
				}
				else {
					relay2(3); // Leave relay2 off
				}
			}
		} else {
			relay2(1); // Turn relay2 on
		}
		usleep(500000);

		// Relay 3 Circulatory Fan
		relay3(0); // Turn relay3 off
		usleep(500000);

		// Relay 4 Heater
		relay4(0); // Turn relay4 off until minTemp reached
	}
	else if ( tempState == 3 && humState == 1 )
	{
		// Relay 1 HEPA
		relay1(1); // Turn relay1 on
		usleep(500000);

		// Relay 2 Humidifier, Relay 3 Circulatory Fan
		if (timestampL - RHumTS - RHumt[RHumt[0]] < RHumo[RHumt[0]]) { // If not end of off timer
			if (timestampL - RHumTS < RHumt[RHumt[0]]) { // If not at end of on timer
				relay2(2); // Leave relay2 on
			} else {
				if (RHumo[RHumt[0]] + RHumt[RHumt[0]] - (timestampL - RHumTS) <= 0) {
					relay2(1); // Turn relay2 on
				}
				else {
					relay2(3); // Leave relay2 off
				}
			}
		} else {
			relay2(1); // Turn relay2 on
		}
		usleep(500000);

		// Relay 3 Circulatory Fan
		if (timestampL - RFanTS < RFano[RFant[0]]) { // If not end of off timer
			if (timestampL - RFanTS < RFant[RFant[0]]) { // If not at end of on timer
				relay3(2); // Leave relay1 on
			} else relay3(3); // Leave relay1 off
		} else relay3(1); // Turn relay1 on
		usleep(500000);

		// Relay 4 Heater
		relay4(0); // Turn relay4 off until minTemp reached
	}
	else if ( tempState == 3 && (humState == 2 || humState == 3))
	{
		// Relay 1 HEPA
		relay1(1); // Turn relay1 on
		usleep(500000);

		// Relay 2 Humidifier
		relay2(0); // Turn relay2 off
		usleep(500000);

		// Relay 3 Circulatory Fan
		if (timestampL - RFanTS < RFano[RFant[0]]) { // If not end of off timer
			if (timestampL - RFanTS < RFant[RFant[0]]) { // If not at end of on timer
				relay3(2); // Leave relay1 on
			} else relay3(3); // Leave relay1 off
		} else relay3(1); // Turn relay1 on
		usleep(500000);

		// Relay 4 Heat
		relay4(0); // Turn relay4 off
	}
	else if ( tempState == 1 && (humState == 2 || humState == 3) )
	{
		// Relay 1 HEPA
		if ( humState == 3 ) {
			if (timestampL - RHepaTS < RHepao[RHepat[0]]) { // If not end of off timer
				if (timestampL - RHepaTS < RHepat[RHepat[0]]) { // If not at end of on timer
					relay1(2); // Leave relay1 on
				} else relay1(3); // Leave relay1 off
			} else relay1(1); // Turn relay1 on
		} else relay1(0); // Turn relay1 off

		relay1(0); // Turn relay1 off
		usleep(500000);

		// Relay 2 Humidifier
		relay2(0); // Turn relay2 off
		usleep(500000);

		// Relay 3 Circulatory Fan
		if (humState == 3) {
			if (timestampL - RFanTS < RFano[RFant[0]]) { // If not end of off timer
				if (timestampL - RFanTS < RFant[RFant[0]]) { // If not at end of on timer
					relay3(2); // Leave relay1 on
				} else relay3(3); // Leave relay1 off
			} else relay3(1); // Turn relay1 on
		} else relay3(0); // Turn relay3 off
		usleep(500000);

		// Relay 4 Heater
		if (timestampL - RHeatTS - RHeatt[RHeatt[0]] < (int)(RHeato[RHeatt[0]]*wfactor)) { // If not end of on and off timer
			if (timestampL - RHeatTS < RHeatt[RHeatt[0]]) { // If not at end of on timer
				relay4(2); // Leave relay4 on
			} else {
				if ((int)(RHeato[RHeatt[0]]*wfactor) + RHeatt[RHeatt[0]] - (timestampL - RHeatTS) <= 0) relay4(1); // Turn relay4 on
				else relay4(3); // Leave relay4 off
			}
		} else relay4(1); // Turn relay4 on
	}
	else if (tempState == 2 && (humState == 2 || humState == 3))
	{
		// Relay 1 HEPA
		if ( humState == 3 ) {
			if (timestampL - RHepaTS < RHepao[RHepat[0]]) { // If not end of off timer
				if (timestampL - RHepaTS < RHepat[RHepat[0]]) { // If not at end of on timer
					relay1(2); // Leave relay1 on
				} else relay1(3); // Leave relay1 off
			} else relay1(1); // Turn relay1 on
		} else relay1(0); // Turn relay1 off
		usleep(500000);

		// Relay 2 Humidifier
		relay2(0); // Turn relay2 off
		usleep(500000);

		// Relay 3 Circulatory Fan
		if (humState == 3) {
			if (timestampL - RFanTS < RFano[RFant[0]]) { // If not end of off timer
				if (timestampL - RFanTS < RFant[RFant[0]]) { // If not at end of on timer
					relay3(2); // Leave relay1 on
				} else relay3(3); // Leave relay1 off
			} else relay3(1); // Turn relay1 on
		} else relay3(0); // Turn relay3 off
		usleep(500000);

		// Relay 4 Heater
		relay4(0); // Turn relay4 off
	}
	else printf("Something went wrong!\n");

	if (sleept <= 0) {
		printf("\nsleept <= 0 (review for errors in code!). Setting to 60.");
		sleep( 60 );
	} else {
		printf("\nRefresh in %d seconds.\n", sleept);
		sleep( sleept );
	}

	return 0;
}