Index: logic/trunk/src/logics/conditions.h
===================================================================
--- logic/trunk/src/logics/conditions.h	(revision 43)
+++ logic/trunk/src/logics/conditions.h	(revision 44)
@@ -4,6 +4,12 @@
 #include "../logics/operators.h"
 #include "../init/devicelist.h"
 
+#define FUNCTION_UNKNOWN    -1
+#define FUNCTION_STATIC      0
+#define FUNCTION_LINEAR      1
+#define FUNCTION_LOGARITHMIC 2
+#define FUNCTION_QUADRATIC   3
+
 typedef struct condition_list
 {
     int                     OPERATOR_TYPE;
@@ -15,5 +21,6 @@
 
 int   evaluateAdditionalConditions(cond_lst *cl, device *dev);
 //int   evaluateAdditionalConditions(cond_lst *cl);
-float getNewWeightedMeasurement(float oldval, float newval, float alpha);
+float getNewWeightedMeasurement(float oldval, float newval, float alpha);
+int   getPowerPercentage(int a, int b, int o, float *val, int func);
 #endif // CONDITIONS_H_INCLUDED
Index: logic/trunk/src/logics/conditions.c
===================================================================
--- logic/trunk/src/logics/conditions.c	(revision 43)
+++ logic/trunk/src/logics/conditions.c	(revision 44)
@@ -1,5 +1,6 @@
 #include "conditions.h"
 #include <stdio.h>
+#include <math.h>
 
 int evaluateAdditionalConditions(cond_lst *cl, device *dev)
 {
@@ -61,9 +62,65 @@
 // TODO check this one again
 float getNewWeightedMeasurement(float oldval, float newval, float alpha)
 {
-    printf("getNewWeightedMeasurement(float oldval, float newval, float alpha)\n");
-    printf("=== buffer %f, device buffer %f, alpha %f\n", oldval, newval, alpha);
-    printf("%f\n",oldval*alpha+newval*(1-alpha));
     return oldval*alpha+newval*(1-alpha);
 }
+
+int getPowerPercentage(int a, int b, int o, float *val, int func)
+{
+    int pwr;
+    printf( "getPowerPercentage(%d, %d, %d, %.2f, %d)\n",a,b,o,*val,func);
+    if(func == FUNCTION_STATIC)
+    {
+        if(*val>o) // right
+        {
+           pwr=100;
+        }
+        else //left
+        {
+            pwr=0;
+        }
+    }
+    else if(func == FUNCTION_LINEAR)
+    {
+        if(*val>o) // right
+        {
+            pwr=(int)((*val-o)/(b-o)*100);
+        }
+        else //left
+        {
+            pwr=(int)((1-(*val-a)/(o-a))*100);
+        }
+    }
+    else if(func == FUNCTION_LOGARITHMIC)
+    {
+        if(*val>o) // right
+        {
+            pwr=(int)((*val-o)/(b-o)*100);
+        }
+        else //left
+        {
+            pwr=(int)((1-(*val-a)/(o-a))*100);
+        }
+    }
+    else if(func == FUNCTION_QUADRATIC)
+    {
+        if(*val>o) // right
+        {
+            pwr=(int)((*val-o)/(b-o)*100);
+        }
+        else //left
+        {
+            pwr=(int)((1-(*val-a)/(o-a))*100);
+        }
+    }
+    else
+    {
+        pwr=-1;
+    }
+
+    if(pwr>100)
+        pwr=100;
+
+    return pwr;
+}
 /*TODO morda dodaj preverbo pravilnosti conditionov (kot podatkov v strukturi)*/
Index: logic/trunk/src/startup/main.c
===================================================================
--- logic/trunk/src/startup/main.c	(revision 43)
+++ logic/trunk/src/startup/main.c	(revision 44)
@@ -12,6 +12,7 @@
 //#include "../logics/scenario_threads.h"
 #include <stdio.h>
 #include <pthread.h>
+#include <syslog.h>
 
 // Inter-thread shared variables
 // TODO: These variables could be configuration variables
@@ -34,7 +35,7 @@
 
     /* initialisation */
     hDevice   = setDeviceList();
-    hScenario = setNewScenarioList();
+    hScenario = setNewScenarioList(hDevice);
 
     printf("Devices present:\t%d\n",   getNumberOfDevices());
     printf("Scenarios present:\t%d\n", getNumberOfScenarios());
@@ -124,17 +125,17 @@
     scenario *scen;
     device   *inDev;
     int      active = 0;
-    float    scen_main_buff;
-    //float    alpha = 0.7f; //TODO put this in xml also
-    //printf("alpha %.2f\n", alpha);
+    float    scenarioBuffer;
+
     /*load scenario*/
     scen = getAvailableScenario(hScenario);
     if(!scen) pthread_exit(0);
 
     // TODO add pointer to this device (all of them actually) to scenario structure - problems with segfault
+    //indev = scen->inDev;
     inDev = getDevice(hDevice, scen->inDevice_id);
-    scen_main_buff=inDev->buf;
-    printf("Scenario %s buffer updated to %.2f!\n", scen->scen_id, scen_main_buff);
+    scen->buf=inDev->buf;
+    printf("Scenario %s buffer updated to %.2f!\n", scen->scen_id, inDev->buf);
     //set its value
     //*
     while(1) //TODO signal == true
@@ -146,20 +147,22 @@
         else
             sleep(scen->idleChkItv);
         //checking primary condition
-        if(scen_main_buff) // is not null
+        if(scen->buf) // is not null
         {
-            scen_main_buff = scen_main_buff*scen->alpha+inDev->buf*(1-scen->alpha);
-            printf("Scenario %s buffer updated to %f, alpha: %.2f!\n", scen->scen_id, scen_main_buff, scen->alpha);
+            scen->buf = scen->buf*scen->alpha+inDev->buf*(1-scen->alpha);
+            //printf("Scenario %s buffer updated to %f, alpha: %.2f!\n", scen->scen_id, scenarioBuffer, scen->alpha);
+            syslog(LOG_MAIL, "%s:%.2f", scen->inDevice_id, scen->buf);
             active = 1;
 
-            if((scen_main_buff > scen->optval + scen->tolval) ||
-               (scen_main_buff < scen->optval - scen->tolval))
+            if((scen->buf > scen->optval + scen->tolval) ||
+               (scen->buf < scen->optval - scen->tolval))
             {
                 if(evaluateAdditionalConditions(scen->cond_l, hDevice))
                 {
-                    printf("Scenario %s updated!\n", scen->scen_id);
-                    syslog(LOG_MAIL, "%s:%.2f", scen->inDevice_id, scen_main_buff);
-                    /*TODO calcualte parameters with given function*/
+                    // TODO syslog - "action:scen_ID:power_percentage"
+                    int power = getPowerPercentage(scen->minval, scen->maxval, scen->optval, &scen->buf, scen->func);
+                    syslog(LOG_MAIL, "%s:%s:%.2f", scen->action, scen->scen_id, power);
+                    printf("Zaganjam napravo %s z mocjo %d\n", scen->scen_id, power);
                     /*TODO execute action with parameter(s)*/
                 }
                 else
@@ -168,10 +171,12 @@
             else
                 active = 0;
         }
+        /*
         if(active)
-            printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen_main_buff, scen->actvChkItv);
+            printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen->buf, scen->actvChkItv);
         else
-            printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen_main_buff, scen->idleChkItv);
+            printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen->buf, scen->idleChkItv);
+        /**/
     }
     /**/
    	pthread_exit(0);
Index: logic/trunk/src/init/scenariolist.h
===================================================================
--- logic/trunk/src/init/scenariolist.h	(revision 43)
+++ logic/trunk/src/init/scenariolist.h	(revision 44)
@@ -8,9 +8,9 @@
     char    *scen_id;
     char    *scen_name;
     char    *inDevice_id;
-    device  *dev;
+    device  *inDev;
     char    *outDevice_id;
-    char    *func;
+    int     func;
     int     idleChkItv;
     int     actvChkItv;
     float   alpha;
@@ -23,12 +23,13 @@
     char    *param;
     struct  condition_list *cond_l;
     // control variables and pointers
+    float   buf;
     int     status; // 0 - OK, 1 - fault reason 1, 2 - fault reason 2 ... etc.
     int     running;
     struct  scenario_s *nxt;
 }scenario;
 
-scenario *setNewScenarioList(); // ony called on startup
+scenario *setNewScenarioList(device *dev); // ony called on startup
 //       TODO add update scenario list function
 char     *getScenarioId(/*arg*/);
 int      getNumberOfScenarios();
Index: logic/trunk/src/init/scenariolist.c
===================================================================
--- logic/trunk/src/init/scenariolist.c	(revision 43)
+++ logic/trunk/src/init/scenariolist.c	(revision 44)
@@ -3,6 +3,7 @@
 #include "../logics/conditions.h"
 #include <mxml.h>
 
+
 //extern device *hDevice;   //device list
 
 short NUMBER_OF_SCENARIOS = 0;
@@ -76,7 +77,7 @@
     return cl;
 }
 
-scenario *setNewScenarioList() // ony called on startup
+scenario *setNewScenarioList(device *dev) // ony called on startup
 {
     //TODO vedno preverjaj, ce so vse naprave, ki jih uporabljas, prisotne! npr. termometer mora biti v device list-u
     scenario *curr, *head;
@@ -124,8 +125,10 @@
         curr->inDevice_id = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "id")));
         curr->inDevice_id = mxmlElementGetAttr(mxml_scenarioNode, "id");
             mxml_scenarioNode = mxml_scenarioNode->next;
-        //printf("inDevice_id:\t %s\n", curr->inDevice_id );
 
+        curr->inDev = getDevice(dev, curr->inDevice_id);
+        //printf("inDev:\t %s\n", curr->inDev->name );
+
         /// char    *outDevice_id;
         curr->outDevice_id = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "id")));
         curr->outDevice_id = mxmlElementGetAttr(mxml_scenarioNode, "id");
@@ -132,9 +135,19 @@
             mxml_scenarioNode = mxml_scenarioNode->next;
         //printf("outDevice_id:\t %s\n", curr->outDevice_id );
 
-        /// char    *func;
-        curr->func = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "func")));
-        curr->func = mxmlElementGetAttr(mxml_scenarioNode, "func");
+        /// int     func;
+
+        if(0==strcmp("static",mxmlElementGetAttr(mxml_scenarioNode, "func")))
+            curr->func = FUNCTION_STATIC;
+        else if(0==strcmp("linear",mxmlElementGetAttr(mxml_scenarioNode, "func")))
+            curr->func = FUNCTION_LINEAR;
+        else if(0==strcmp("logarithmic",mxmlElementGetAttr(mxml_scenarioNode, "func")))
+            curr->func = FUNCTION_LOGARITHMIC;
+        else if(0==strcmp("quadratic",mxmlElementGetAttr(mxml_scenarioNode, "func")))
+            curr->func = FUNCTION_QUADRATIC;
+        else
+            curr->func = FUNCTION_UNKNOWN;
+
             mxml_scenarioNode = mxml_scenarioNode->next;
         //printf("func:\t %s\n", curr->func );
 
