Subversion Repositories heizung

Rev

Rev 5 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 7
Line 279... Line 279...
279
	      sz.tm_year = zeit->tm_year;
279
	      sz.tm_year = zeit->tm_year;
280
	      sz.tm_isdst = zeit->tm_isdst;
280
	      sz.tm_isdst = zeit->tm_isdst;
281
	      tstart = mktime(&sz);
281
	      tstart = mktime(&sz);
282
	      loctm = t - tstart;	// Seconds since midnight
282
	      loctm = t - tstart;	// Seconds since midnight
283
	      act = HeizFirst;
283
	      act = HeizFirst;
284
syslog(LOG_INFO,"wday: %d, loctm: %lu", wday, loctm);
-
 
-
 
284
 
285
	      while(act)
285
	      while(act)
286
	      {
286
	      {
287
		 if (act->heizung->wday == wday && loctm >= act->heizung->start && loctm <= act->heizung->end)
287
		 if (act->heizung->wday == wday && loctm >= act->heizung->start && loctm <= act->heizung->end)
288
		 {
288
		 {
289
syslog(LOG_INFO,"wday: %d, loctm: %lu, endt: %lu, solltemp: %.1f", wday, loctm, act->heizung->start, act->heizung->temp);
-
 
290
		    if (ActTemperature == 9999.0)
289
		    if (ActTemperature == 9999.0)
291
		       SwitchOff();		// No temperature, no heating
290
		       SwitchOff();		// No temperature, no heating
292
		    else if (ActTemperature < 5.0)
291
		    else if (ActTemperature < 5.0)
293
		       SwitchOn();		// Make sure it will not freeze
292
		       SwitchOn();		// Make sure it will not freeze
294
		    else if (ActTemperature > 30.0)
293
		    else if (ActTemperature > 30.0)
Line 312... Line 311...
312
}
311
}
313
 
312
 
314
void *pthr_parser( void *pV_data )
313
void *pthr_parser( void *pV_data )
315
{
314
{
316
int i;
315
int i;
317
char ch, buf[128];
316
char ch, buf[128], str[INET_ADDRSTRLEN];
318
// socket structure
317
// socket structure
319
struct sockaddr_in client1, server1;
318
struct sockaddr_in client1, server1;
320
struct servent *serviceInfo;
319
struct servent *serviceInfo;
321
int s1,s;
320
int s1,s;
322
socklen_t length;
321
socklen_t length;
Line 335... Line 334...
335
	server1.sin_family = AF_INET;
334
	server1.sin_family = AF_INET;
336
	server1.sin_addr.s_addr = INADDR_ANY;
335
	server1.sin_addr.s_addr = INADDR_ANY;
337
	s = socket(AF_INET,SOCK_STREAM,0);
336
	s = socket(AF_INET,SOCK_STREAM,0);
338
 
337
 
339
	if (s < 0)
338
	if (s < 0)
-
 
339
	{
340
	   syslog (LOG_DAEMON, "Error in socket");
340
	   syslog (LOG_DAEMON, "Error in socket: %s",strerror(errno));
-
 
341
	   exit(EXIT_FAILURE);
-
 
342
	}
341
 
343
 
342
	if (bind (s, (struct sockaddr *)&server1, sizeof (server1)) < 0)
344
	if (bind (s, (struct sockaddr *)&server1, sizeof (server1)) < 0)
-
 
345
	{
343
	   syslog (LOG_DAEMON, "Error in bind");
346
	   syslog (LOG_DAEMON, "Error in bind: %s", strerror(errno));
-
 
347
	   exit(EXIT_FAILURE);
-
 
348
	}
344
 
349
 
345
	if (listen (s, 5) < 0)
350
	if (listen (s, 5) < 0)
-
 
351
	{
346
	   syslog (LOG_DAEMON, "Error in listen");
352
	   syslog (LOG_DAEMON, "Error in listen: %s", strerror(errno));
-
 
353
	   exit(EXIT_FAILURE);
-
 
354
	}
347
 
355
 
348
	length = sizeof(client1);
356
	length = sizeof(client1);
349
        syslog (LOG_DEBUG, "Server ready: %d",s);
357
        syslog (LOG_DEBUG, "Server ready: %d",s);
350
 
358
 
351
	while (1)
359
	while (1)
Line 354... Line 362...
354
	   // version (User may change it at every time)
362
	   // version (User may change it at every time)
355
	   if (!readHeizPlan())
363
	   if (!readHeizPlan())
356
	   {
364
	   {
357
	      if (!HeizFirst)
365
	      if (!HeizFirst)
358
	      {
366
	      {
359
	         syslog(LOG_DAEMON, "Error reading table with plan!");
367
	         syslog(LOG_DAEMON, "Error reading table %s with plan!", configs.HeizPath);
360
	         return NULL;
368
	         exit(EXIT_FAILURE);
361
	      }
369
	      }
362
	      else
370
	      else
363
		 syslog(LOG_DAEMON, "Error reading table with plan! Will work with old one.");
371
		 syslog(LOG_DAEMON, "Error reading table with plan! Will work with old one.");
364
	   }
372
	   }
365
 
373
 
366
	   if ((s1 = accept (s, (struct sockaddr *)&client1, &length)) < 0)
374
	   if ((s1 = accept (s, (struct sockaddr *)&client1, &length)) < 0)
367
	      syslog (LOG_DAEMON, "Error in accept: %d", s1);
375
	      syslog (LOG_DAEMON, "Error in accept: %d: %s", s1, strerror(errno));
368
 
376
 
369
	   pthread_mutex_lock (&fastmutex);
377
	   pthread_mutex_lock (&fastmutex);
-
 
378
	   inet_ntop(AF_INET, &(client1.sin_addr), str, INET_ADDRSTRLEN);
370
	   syslog (LOG_INFO, "Connected to client");
379
	   syslog (LOG_INFO, "Connected to client %s", str);
371
	   memset(&buf[0], 0, sizeof(buf));
380
	   memset(&buf[0], 0, sizeof(buf));
372
	   i = 0;
381
	   i = 0;
373
 
382
 
374
	   while (read(s1,&ch,1) > 0)
383
	   while (read(s1,&ch,1) > 0)
375
	   {
384
	   {
Line 497... Line 506...
497
	   write(s1, &hv0[0], strlen(hv0));
506
	   write(s1, &hv0[0], strlen(hv0));
498
	}
507
	}
499
 
508
 
500
	if (!strcasecmp(bef, "GET PRESSURE"))	// Return the actual air pressure
509
	if (!strcasecmp(bef, "GET PRESSURE"))	// Return the actual air pressure
501
	{
510
	{
502
	   sprintf(&hv0[0], "PRESSURE:%.3f;", ActPressure);
511
	   sprintf(&hv0[0], "PRESSURE:%.1f;", ActPressure);
503
	   write(s1, &hv0[0], strlen(hv0));
512
	   write(s1, &hv0[0], strlen(hv0));
504
	}
513
	}
505
 
514
 
506
	// SET DAY:<count>:<day>:<end1>:<temp>[:<end2>:<temp>[:...]];
515
	// SET DAY:<count>:<day>:<end1>:<temp>[:<end2>:<temp>[:...]];
507
	// <count>   number of entries following
516
	// <count>   number of entries following
Line 912... Line 921...
912
ulong tim;
921
ulong tim;
913
char line[512];
922
char line[512];
914
char *p, *xp;
923
char *p, *xp;
915
char hv0[64], hv1[128];
924
char hv0[64], hv1[128];
916
float temperature;
925
float temperature;
917
long offset = 0;
926
int counter = 0;
918
HEIZINDEX *act, *prev;
927
HEIZINDEX *act, *prev;
919
 
928
 
920
	fd = -1;
929
	fd = -1;
921
 
930
 
922
	if (access(configs.HeizPath, R_OK))
931
	if (access(configs.HeizPath, R_OK))
Line 951... Line 960...
951
	      close(fd);
960
	      close(fd);
952
	      syslog(LOG_DAEMON,"Error allocating memory for a temperature line! Stopped reading file %s.", configs.HeizPath);
961
	      syslog(LOG_DAEMON,"Error allocating memory for a temperature line! Stopped reading file %s.", configs.HeizPath);
953
	      return 0;
962
	      return 0;
954
	   }
963
	   }
955
 
964
 
-
 
965
	   counter++;
956
	   memset(act->heizung, 0, sizeof(HEIZUNG));
966
	   memset(act->heizung, 0, sizeof(HEIZUNG));
957
	   // Parse a line. The line has the format:
967
	   // Parse a line. The line has the format:
958
	   // <wday>,<end>,<temperature>
968
	   // <wday>,<end>,<temperature>
959
	   p = strtok(line, ",");
969
	   p = strtok(line, ",");
960
	   i = 1;
970
	   i = 1;
Line 1018... Line 1028...
1018
	      p = strtok(NULL, ",");
1028
	      p = strtok(NULL, ",");
1019
	      i++;
1029
	      i++;
1020
	   }
1030
	   }
1021
	}
1031
	}
1022
 
1032
 
-
 
1033
	syslog(LOG_INFO,"Found %d entries in %s", counter, configs.HeizPath);
1023
	close (fd);
1034
	close (fd);
1024
	return 1;
1035
	return 1;
1025
}
1036
}
1026
 
1037
 
1027
/*
1038
/*