コード例 #1
0
ファイル: mt29.c プロジェクト: jleffler/soq
static int scan_line(const char *buff, float *temp, int *month, int *year)
{
    int offset = 0;
    int nf = sscanf(buff, "%d%d%n", year, month, &offset);
    if (nf != 2)
    {
        printf("nf = %d; year = %d, month = %d\n", nf, *year, *month);
        return -1;
    }
    buff += offset;
    int days = days_in_month(*year, *month);
    for (int i = 0; i < days; i++)
    {
        if (sscanf(buff, "%f%n", &temp[i], &offset) != 1)
        {
            printf("failed: %s\n", buff + offset);
            return -1;
        }
        if (!is_valid_temp(temp[i]))
        {
            printf("invalid: %6.2f\n", temp[i]);
            return -1;
        }
        buff += offset;
    }
    return days;
}
コード例 #2
0
ファイル: thermo_starlight.c プロジェクト: schenkl/Coldipozzo
void* run_thermostat()	//ttttt
{
	int i,j,rtn,min_today,rtn1;
	time_t tt,tloc;
	char action[40],*s_rtn;
	struct tm *stm; 
	float current_temp_f,current_set_temp,temp;
	printf("Running run_thermostat!\n");
	//sleep(60);
	while (1)	//endless loop that goes through each zone and if it has a set_temp > 0, will process the data
	{
		tt = time(&tloc);
		stm=localtime(&tloc);
		//while (Running_who_has_control)
		//{
			//printf("\n\t*******Waiting for Running_who_has_control to clear\n\n");
			//sleep(2);
		//}
		for (i=0;i<THERMOSTAT;i++)
		{
			s_rtn = strstr(T->device[T->thermostat[i].out_dev].name,"_status");	//_status as output is for zwave thermostats only
			if (s_rtn != NULL) 
			{
				printf("\n\t\tFound a zwave thermostat...continue....skipped zone %d\n\n",i);
				continue;
			}
			if (T->thermostat[i].set_temp < 1) //-1 means not defined
			{
				//i = 0;
				//printf("Invalid set_temp\n\r");
				continue;
			}
			if (T->thermostat[i].out_dev == -1)
			{
				//i = 0;
				//printf("Invalid out_dev\n\r");
				continue;
			}
			if (stm->tm_hour != Old_hour)
			{
				for (j=0;j<THERMOSTAT;j++) 
				{
					Checked_control[j] = 1;
				}
				Old_hour = stm->tm_hour;
			}	
			if (Checked_control[i])
			{
				rtn = who_has_control(i);
				Checked_control[i] = 0;
			}
			printf("comparing T->thermostat[%d].set_temp = %2.1f\t",i,T->thermostat[i].set_temp);
			printf("with T->device[T->thermostat[%d].in_dev].f_state = %2.1f\n",i,T->device[T->thermostat[i].in_dev].f_state);
			//warning...no hysteresis 
			if (stm->tm_min != Old_minute)	//force writing to device every minute.....
			{
				for (j=0;j<THERMOSTAT;j++)
				{
					Update_output[j] = 1;
				}
				Old_minute = stm->tm_min;
			}
			rtn = is_valid_temp(i);
			if (rtn < 0)
			{
				printf("**********Invalid temp********** skipping thermostat for zone %d\t%s\n",i,T->device[T->thermostat[i].in_dev].name);
				continue;
			} else if (rtn==0) {
				printf("Skipping themp check for %s\n\r",T->device[T->thermostat[i].in_dev].name);
			} else {
				printf("\n\t\t%s has a valid temperture reading\n\n\r",T->device[T->thermostat[i].in_dev].name);
			}
			//here is the real thermostat...rrrrrttttt
			current_temp_f = T->device[T->thermostat[i].in_dev].f_state;
			current_set_temp = T->thermostat[i].set_temp;
			min_today = calculate_min_today();

			//now check set backs based on time ...to be done....
			temp = get_setback_temp(i);
			printf ("run_thermostat: return form get_setback_temp = %3.1f\tzone = %d\n",temp,i);
			//use setback temps NOT T->thermostat[i].set_temp
			if (temp > T->device[T->thermostat[i].in_dev].f_state)	//zone should be on
			{
				if (T->thermostat[i].state & ZONE_OFF)	//zone is off
				{
					Update_output[i] = 1;	//tell it to update.
				}
				if (Update_output[i])	//can be called by change of state OR every minute
				{
					printf("\tCalling delay_driver %s T->thermostat[i].out_dev = %d\t1\t0",T->device[T->thermostat[i].out_dev].name,T->thermostat[i].out_dev);
					delay_driver(T->thermostat[i].out_dev,1,0);
					Update_output[i] = 0;
					Old_output[i] = 1;
					T->thermostat[i].state = T->thermostat[i].state | ZONE_ON;
					T->thermostat[i].state = T->thermostat[i].state & ~ZONE_OFF;
					if (T->thermostat[i].misc > 0)
					{
						rtn = logging_zone(i,1);
					}
				} else {
					printf("skipping updating %d\n",i);
				}
				if (Old_output[i] != 1)
				{
					delay_driver(T->thermostat[i].out_dev,1,0);
					T->thermostat[i].state = T->thermostat[i].state | ZONE_ON;
					T->thermostat[i].state = T->thermostat[i].state & ~ZONE_OFF;
					Old_output[i] = 1;
					if (T->thermostat[i].misc)
					{
						rtn = logging_zone(i,1);
					}
				}
			} else {	// temp < f_state zone should be off 
				if (Update_output[i] != 0)
				{
					printf("\tCalling delay_driver %s T->thermostat[i].out_dev = %d\t0\t0",T->device[T->thermostat[i].out_dev].name,T->thermostat[i].out_dev);
					delay_driver(T->thermostat[i].out_dev,0,0);
					T->thermostat[i].state = T->thermostat[i].state | ZONE_OFF;
					T->thermostat[i].state = T->thermostat[i].state & ~ZONE_ON;
					Update_output[i] = 0;
					Old_output[i] = 0;
					if (T->thermostat[i].misc)
					{
						rtn = logging_zone(i,1);
					}
				} else {
					printf("skipping updating %d\n",i);
				}
				if (Old_output[i] != 0)
				{
					delay_driver(T->thermostat[i].out_dev,1,0);
					T->thermostat[i].state = T->thermostat[i].state | ZONE_OFF;
					T->thermostat[i].state = T->thermostat[i].state & ~ZONE_ON;
					Old_output[i] = 0;
					if (T->thermostat[i].misc)
					{
						rtn = logging_zone(i,1);
					}
				}
			}
			sleep(1);
		}	//end of for loop
		sleep(10);
		Failures_per_loop = 0;
	}	//end of while loop
}