Subversion Repositories heizung

Rev

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

Rev 1 Rev 2
Line 66... Line 66...
66
int writeHeizPlan(void);
66
int writeHeizPlan(void);
67
void readConf(void);
67
void readConf(void);
68
 
68
 
69
char *readLine(int fd, long *offset, char *buf, int bufLen);
69
char *readLine(int fd, long *offset, char *buf, int bufLen);
70
char *trim(char *str);
70
char *trim(char *str);
-
 
71
char *remove_string(char *str, char *search, char *ret);
71
 
72
 
72
static pthread_mutex_t fastmutex = PTHREAD_MUTEX_INITIALIZER;
73
static pthread_mutex_t fastmutex = PTHREAD_MUTEX_INITIALIZER;
73
 
74
 
74
/*
75
/*
75
 * The main program, initializing everything and start the daemon.
76
 * The main program, initializing everything and start the daemon.
Line 387... Line 388...
387
	{
388
	{
388
	   sprintf(&hv0[0], "PRESSURE:%f;", ActPressure);
389
	   sprintf(&hv0[0], "PRESSURE:%f;", ActPressure);
389
	   write(s1, &hv0[0], strlen(hv0));
390
	   write(s1, &hv0[0], strlen(hv0));
390
	}
391
	}
391
 
392
 
-
 
393
	// SET DAY:<count>:<day>:<end1>:<temp>[:<end2>:<temp>[:...]];
-
 
394
	// <count>   number of entries following
-
 
395
	// <day>     The day of the week
-
 
396
	// <end1>    The end time
-
 
397
	// <temp>    The temperature wanted until end time is reached
-
 
398
	//
392
	if (strcasecmp(bef, "SET DAY"))		// Set the plan for a particular day
399
	if (strcasecmp(bef, "SET DAY"))		// Set the plan for a particular day
393
	{
400
	{
-
 
401
	int count, wday, i;
-
 
402
	long endt;
-
 
403
	float temp;
-
 
404
 
-
 
405
	   remove_string(bef, "SET DAY:", &hv0[0]);
-
 
406
	   count = atoi(bef);
-
 
407
 
-
 
408
	   if (count > 0)
-
 
409
	   {
-
 
410
	      for (i = 0; i < count; i++)
-
 
411
	      {
-
 
412
		 remove_string(bef, ":", &hv0[0]);
-
 
413
		 wday = atoi(bef);
-
 
414
		 remove_string(bef, ":", &hv0[0]);
-
 
415
		 endt = atol(bef);
-
 
416
		 remove_string(bef, ":", &hv0[0]);
-
 
417
		 temp = atof(bef);
-
 
418
 
-
 
419
		 act = HeizFirst;
-
 
420
 
-
 
421
		 while(act)
-
 
422
		 {
-
 
423
		    if (act->heizung->wday == wday)
-
 
424
	      }
-
 
425
	   }
394
	}
426
	}
395
 
427
 
396
	if (strcasecmp(bef, "SET PLAN"))	// Set the complete plan
428
	if (strcasecmp(bef, "SET PLAN"))	// Set the complete plan
397
	{
429
	{
398
	}
430
	}
399
 
431
 
-
 
432
	// SET TEMP:<wday>:<end>:<temp>;
400
	if (strcasecmp(bef, "SET TEMP"))	// Set the temperature for a particular day and line
433
	if (strcasecmp(bef, "SET TEMP"))	// Set the temperature for a particular day and line
401
	{
434
	{
402
	int wday, line;
435
	int wday, line;
403
	float tmp;
436
	float tmp;
404
 
437
 
Line 441... Line 474...
441
 
474
 
442
	return 1;
475
	return 1;
443
}
476
}
444
 
477
 
445
/*
478
/*
-
 
479
 * Remove a complete day
-
 
480
 */
-
 
481
void freeDay(int wday)
-
 
482
{
-
 
483
HEIZINDEX *act, *next, *prev;
-
 
484
 
-
 
485
	act = HeizFirst;
-
 
486
	prev = NULL;
-
 
487
 
-
 
488
	while(act)
-
 
489
	{
-
 
490
	   if (act->heizung->wday == wday)
-
 
491
	   {
-
 
492
	      act = freeChainMember(act);
-
 
493
	      continue;
-
 
494
	   }
-
 
495
 
-
 
496
	   act = act->next;
-
 
497
	}  
-
 
498
}
-
 
499
 
-
 
500
/*
-
 
501
 * Insert a new entry
-
 
502
 */
-
 
503
void insertMember(int wday, long endt, float temp)
-
 
504
{
-
 
505
HEIZINDEX *act;
-
 
506
 
-
 
507
	act = HeizFirst;
-
 
508
 
-
 
509
	while(act)
-
 
510
	{
-
 
511
	   if (act->heizung->wday == wday && act->heizung->end == endt)
-
 
512
	   {
-
 
513
	      act->heizung->temp = temp;
-
 
514
	      return;
-
 
515
	   }
-
 
516
 
-
 
517
	   act = act->next;
-
 
518
	}
-
 
519
 
-
 
520
	if ((act = allocateMemory()) != NULL)
-
 
521
	{
-
 
522
	   act->heizung->wday = wday;
-
 
523
	   act->heizung->end = endt;
-
 
524
	   act->heizung->temp = temp;
-
 
525
	}
-
 
526
}
-
 
527
 
-
 
528
/*
446
 * Free the memory for the actual heizung plan.
529
 * Free the memory for the actual heizung plan.
447
 */
530
 */
448
void freeMemory()
531
void freeMemory()
449
{
532
{
450
HEIZINDEX *act, *next;
533
HEIZINDEX *act, *next;
Line 466... Line 549...
466
}
549
}
467
 
550
 
468
/*
551
/*
469
 * Free only one entry in the chain
552
 * Free only one entry in the chain
470
 */
553
 */
471
void freeChainMember(HEIZINDEX *member)
554
HEIZINDEX *freeChainMember(HEIZINDEX *member)
472
{
555
{
473
HEIZINDEX *act,*prev;
556
HEIZINDEX *act,*prev;
474
 
557
 
475
	act = HeizFirst;
558
	act = HeizFirst;
476
	prev = NULL;
559
	prev = NULL;
Line 482... Line 565...
482
	}
565
	}
483
 
566
 
484
	if (act == member)
567
	if (act == member)
485
	{
568
	{
486
	   if (prev)
569
	   if (prev)
487
	      prev->next = NULL;
570
	      prev->next = act->next;
488
 
571
 
489
	   if (act->heizung)
572
	   if (act->heizung)
490
	      free(act->heizung);
573
	      free(act->heizung);
491
 
574
 
492
	   free(act);
575
	   free(act);
-
 
576
	   return prev->next;
493
	}
577
	}
-
 
578
 
-
 
579
	return NULL;
494
}
580
}
495
 
581
 
496
/*
582
/*
497
 * Allocate the memory for the actual heizung plan,
583
 * Allocate the memory for the actual heizung plan,
498
 */
584
 */
Line 834... Line 920...
834
	   free (buf);
920
	   free (buf);
835
	}
921
	}
836
 
922
 
837
	return str;
923
	return str;
838
}
924
}
-
 
925
 
-
 
926
char *remove_string(char *str, char *search, char *ret)
-
 
927
{
-
 
928
char *p;
-
 
929
 
-
 
930
	if (!strlen(str) || !strlen(search))
-
 
931
	   return NULL;
-
 
932
 
-
 
933
	if ((p = strstr(str, search)) != NULL)
-
 
934
	{
-
 
935
	int len = strlen(search);
-
 
936
 
-
 
937
	   strcpy(ret, str, p - str + len);
-
 
938
	   memmove(str, p + len + 1, strlen(p+len));
-
 
939
	   return ret;
-
 
940
	}
-
 
941
 
-
 
942
	return NULL;
-
 
943
}
839
 
944