]> rtime.felk.cvut.cz Git - hydro.git/commitdiff
Repairs in code
authorstefic User <stefic@ubuntu.ubuntu-domain>
Wed, 7 Jan 2009 10:04:50 +0000 (11:04 +0100)
committerstefic User <stefic@ubuntu.ubuntu-domain>
Wed, 7 Jan 2009 10:04:50 +0000 (11:04 +0100)
14 files changed:
app-stefic/control/board.c
app-stefic/control/definitions.c
app-stefic/control/definitions.h
app-stefic/control/hydroponie.c
app-stefic/control/hydroponie.h
app-stefic/control/ul_idstr.c
app-stefic/control/ul_idstr.h
app-stefic/regulator/board.c
app-stefic/regulator/board.h
app-stefic/regulator/hydroponieoi.c
app-stefic/sensor/board.c
app-stefic/sensor/definitions.c
app-stefic/sensor/definitions.h
app-stefic/sensor/hydroponie.c

index 10f5e8324853cb9bf78d973e600f2de1de435e2f..f8676d4844dd6acde14709e13ad44c8d42eca2d0 100644 (file)
@@ -55,30 +55,30 @@ int oi_period_wrfnc(ULOI_PARAM_coninfo void *context){
 
 void set_fan_PIN(){
     if (oi_fan == 1) {
-        SET_OUT_PIN(OUT_PORT,P1_27_FAN);
+        SET_OUT_PIN(OUT_PORT,P1_29_FAN);
         printf("FAN PIN UP\n");
     } else {
-        CLR_OUT_PIN(OUT_PORT,P1_27_FAN);
+        CLR_OUT_PIN(OUT_PORT,P1_29_FAN);
         printf("FAN PIN DOWN\n");
     }
 }
 
 void set_humidifier_PIN(){
     if (oi_humidifier == 1) {
-        SET_OUT_PIN(OUT_PORT,P1_28_HUMIDIFIER);
+        SET_OUT_PIN(OUT_PORT,P1_30_HUMIDIFIER);
         printf("HUM PIN UP\n");
     } else {
-        CLR_OUT_PIN(OUT_PORT,P1_28_HUMIDIFIER);
+        CLR_OUT_PIN(OUT_PORT,P1_30_HUMIDIFIER);
         printf("HUM PIN DOWN\n");
     }
 }
 
 void set_light_PIN(){
     if (oi_light == 1) {
-        SET_OUT_PIN(OUT_PORT,P1_29_LIGHT);
+        SET_OUT_PIN(OUT_PORT,P1_31_LIGHT);
         printf("LIGHT PIN UP\n");
     } else {
-        CLR_OUT_PIN(OUT_PORT,P1_29_LIGHT);
+        CLR_OUT_PIN(OUT_PORT,P1_31_LIGHT);
         printf("LIGHT PIN DOWN\n");
     }
 }
@@ -131,10 +131,7 @@ void send_data() {
         cid_cnt++;
     }
 
-    if (cid_cnt == 0){
-        heartbeat();
-    } else {
-
+    if (cid_cnt != 0){
         int i;
         int buff_len;
 
@@ -152,7 +149,6 @@ void send_data() {
 
         msgsend = ul_send_query(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
         printf("[I] DATA\n");
-        free(buf);
         ul_freemsg(ul_fd);
     }
 }
@@ -172,6 +168,7 @@ void oiinit(void){
 }
 
 void check_PDO(int cid, int data){
+    printf("CID: %i\n", cid);
     if (cid == oi_slot_fan){
         oi_fan = data;
         set_fan_PIN();
@@ -199,9 +196,10 @@ void work_with(void){
 //     IO0SET = P0_21_BIT;
 //     IO0SET = P0_22_BIT;
 
-    SET_OUT_PIN(OUT_PORT, P1_27_FAN);
-    CLR_OUT_PIN(OUT_PORT, P1_28_HUMIDIFIER);
-    SET_OUT_PIN(OUT_PORT, P1_29_LIGHT);
+    SET_OUT_PIN(OUT_PORT, P1_29_FAN);
+    SET_OUT_PIN(OUT_PORT, P1_31_LIGHT);
+    SET_OUT_PIN(OUT_PORT, P1_30_HUMIDIFIER);
+
 
     IO0SET = LED1_BIT; //vypinani LED
     IO0CLR = LED2_BIT; //zapinani LED
index 3d50715029937189c814bb447e4374c36f868060..a57d9e9bc468138477a6a9619e6d24ae3270d603 120000 (symlink)
@@ -1 +1 @@
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/definitions.c
\ No newline at end of file
+../sensor/definitions.c
\ No newline at end of file
index eaff606cda0798cc57bd7b03626e3ad58a9e5261..0d0cc01c194e9953783d3fab4a1c46f77d5ef72a 120000 (symlink)
@@ -1 +1 @@
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/definitions.h
\ No newline at end of file
+../sensor/definitions.h
\ No newline at end of file
index ea64e23f91a9b0aa8ded812862338e0cbd24d65c..bd04185e12693aeb1ba15a6c17b40e62db96a59a 120000 (symlink)
@@ -1 +1 @@
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/hydroponie.c
\ No newline at end of file
+../sensor/hydroponie.c
\ No newline at end of file
index e42717e5e963435847f845a2d33ade7e063fd3ca..fbc6c4cb6cca719c4cf5f6fa5ce3efcb9fc82bab 120000 (symlink)
@@ -1 +1 @@
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/hydroponie.h
\ No newline at end of file
+../sensor/hydroponie.h
\ No newline at end of file
index d4e0135c11c675c2845d8b7aa743fdbba4c57295..01bdbd2d708a8300c902639a0619ea101f252149 120000 (symlink)
@@ -1 +1 @@
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/ul_idstr.c
\ No newline at end of file
+../sensor/ul_idstr.c
\ No newline at end of file
index 34efbc118b0876908e56970c7a933618d6525bd0..1826486688d3ea83af587ffed91d3630c27056e9 120000 (symlink)
@@ -1 +1 @@
-/home/stefic/BAP/build_ulan/ulan/embedded/hydro/app-stefic/sensor/ul_idstr.h
\ No newline at end of file
+../sensor/ul_idstr.h
\ No newline at end of file
index 6c2ce49fa155d81eefc20dde631c53a9f4256a63..373615f6aab6f4822cba0102d8788a863911688d 100644 (file)
@@ -20,6 +20,7 @@ unsigned int oi_want_dark;
 
 int hyst_temp = 1;
 int hyst_hum = 10;
+
 unsigned int fan = 0;
 unsigned int hum = 0;
 unsigned int light = 0;
@@ -57,6 +58,16 @@ int oi_period_wrfnc(ULOI_PARAM_coninfo void *context){
     return 1;
 }
 
+int oi_want_temp_wrfnc(ULOI_PARAM_coninfo void *context){
+    uloi_uint_wrfnc(ULOI_ARG_coninfo context);
+    return 1;
+}
+
+int oi_want_hum_wrfnc(ULOI_PARAM_coninfo void *context){
+    uloi_uint_wrfnc(ULOI_ARG_coninfo context);
+    return 1;
+}
+
 void send_data() {
     int msgsend;
 
@@ -85,10 +96,7 @@ void send_data() {
         cid_cnt++;
     }
 
-    if (cid_cnt == 0){
-        heartbeat();
-    } else {
-
+    if (cid_cnt != 0){
         int i;
         int buff_len;
 
@@ -106,7 +114,6 @@ void send_data() {
 
         msgsend = ul_send_query(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
         printf("[I] DATA\n");
-        free(buf);
         ul_freemsg(ul_fd);
     }
 }
@@ -121,10 +128,15 @@ void oiinit(void){
 }
 
 void check_PDO(int cid, int data){
-    if (cid == oi_slot_temp)
+    printf("CID: %i\n", cid);
+    if (cid == oi_slot_temp){
         temperature = data;
-    if (cid == oi_slot_temp)
+        printf("temperature: %i\n", temperature);
+    }
+    if (cid == oi_slot_hum){
         humidity = data;
+        printf("humidity: %i\n", humidity);
+    }
 }
 
 void regulate(void){
index e95de78dc44afb455333bfc51b2681426d3ce0f6..68b4376698b1dbd5c235c986780630d0a7d75f65 100644 (file)
 extern const ULOI_CODE uloi_objdes_array_t uloi_objdes_main;
 extern unsigned int status_val;
 extern unsigned int oi_cid_fan;
-extern unsigned int oi_fan;
 extern unsigned int oi_cid_hum;
-extern unsigned int oi_fan;
 extern unsigned int oi_cid_light;
-extern unsigned int oi_fan;
 extern unsigned int oi_slot_temp;
 extern unsigned int oi_slot_hum;
 extern unsigned int oi_period;
+extern unsigned int oi_want_temp;
+extern unsigned int oi_want_hum;
 
 typedef struct cid_data {
     int cid;
@@ -34,6 +33,8 @@ int oi_cid_light_wrfnc(ULOI_PARAM_coninfo void *context);
 int oi_slot_temp_wrfnc(ULOI_PARAM_coninfo void *context);
 int oi_slot_hum_wrfnc(ULOI_PARAM_coninfo void *context);
 int oi_period_wrfnc(ULOI_PARAM_coninfo void *context);
+int oi_want_temp_wrfnc(ULOI_PARAM_coninfo void *context);
+int oi_want_hum_wrfnc(ULOI_PARAM_coninfo void *context);
 
 void send_data();
 void oiinit(void);
index b9732ec6edb0ff35ae19b436bc39ddef3ee559d8..f6e4f2a3e2a7b3d3345c39b280eb9e1046969a7a 100644 (file)
@@ -11,6 +11,9 @@
 #define I_HUMIDITY_SLOT 910
 #define I_PERIOD 1000
 
+#define I_WANT_TEMP 1100
+#define I_WANT_HUM 1200
+
 unsigned int status_val;
 
 int status_rdfnc(ULOI_PARAM_coninfo void *context)
@@ -52,6 +55,9 @@ ULOI_GENOBJDES(HUMIDITY_SLOT,I_HUMIDITY_SLOT,"u2/slot",uloi_uint_rdfnc,&oi_slot_
 
 ULOI_GENOBJDES(PERIOD,I_PERIOD,"u2",uloi_uint_rdfnc,&oi_period,oi_period_wrfnc,&oi_period)
 
+ULOI_GENOBJDES(WANT_TEMP,I_WANT_TEMP,"u2/.1",uloi_uint_rdfnc,&oi_want_temp,oi_want_temp_wrfnc,&oi_want_temp)
+ULOI_GENOBJDES(WANT_HUM,I_WANT_HUM,"u2/.1",uloi_uint_rdfnc,&oi_want_hum,oi_want_hum_wrfnc,&oi_want_hum)
+
 const uloi_objdes_t * ULOI_CODE uloi_objdes_main_items[]={
     &uloid_objdes_DOII,
     &uloid_objdes_DOIO,
@@ -66,8 +72,9 @@ const uloi_objdes_t * ULOI_CODE uloi_objdes_main_items[]={
     &uloid_objdes_LIGHT_CID,
     &uloid_objdes_TEMPERATURE_SLOT,
     &uloid_objdes_HUMIDITY_SLOT,
-    &uloid_objdes_PERIOD
-
+    &uloid_objdes_PERIOD,
+    &uloid_objdes_WANT_TEMP,
+    &uloid_objdes_WANT_HUM
 };
 
 const ULOI_CODE uloi_objdes_array_t uloi_objdes_main={
index d84b280eaf030a09b37b911a02f9dc41dfc6e4fc..5ef7f811e0b9b9488db897b8b9951ed9227407a9 100644 (file)
@@ -47,16 +47,13 @@ void send_data() {
         cids[cid_cnt].value = oi_temperature; 
         cid_cnt++;
     }
-    if (oi_cid_hum > 0) {
+    if (oi_cid_hum > 0){
         cids[cid_cnt].cid = oi_cid_hum; 
         cids[cid_cnt].value = oi_humidity; 
         cid_cnt++;
     }
 
-    if (cid_cnt == 0){
-        heartbeat();
-    } else {
-
+    if (cid_cnt != 0){
         int i;
         int buff_len;
 
@@ -77,7 +74,6 @@ void send_data() {
 
         msgsend = ul_send_query(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
         printf("[I] DATA\n");
-        free(buf);
         ul_freemsg(ul_fd);
     }
 }
index 0f014196daae0b9acd192818bd5b279f493c6880..59da0b836a65527179fdd57b46d1e3ac3a717a01 100644 (file)
@@ -38,6 +38,13 @@ int buf2int(uchar *buf){
     return i;
 }
 
+uint buf2uint(uchar *buf){
+    uint i;
+    i = (uchar) buf[0];
+    i = ((uchar) buf[1]<<8) | i;
+    return i;
+}
+
 mstime_t current_time(){
     mstime_t ret = 0;
 
@@ -147,6 +154,8 @@ void accept_SDO(void) {
         if ((ul_inepoll(ul_fd)>0) && (ul_acceptmsg(ul_fd, &msginfo)>=0)) {
             if (msginfo.cmd == UL_CMD_PDO){
                 process_PDO();
+                ul_freemsg(ul_fd);
+                printf("accept PDO msg: sadr: %i, dadr: %i\n", msginfo.sadr, msginfo.dadr);
             } else if (msginfo.sadr != 99) {
                 if (!(msginfo.flg&(UL_BFL_PROC | UL_BFL_FAIL))) {
                     //waiting for msg from bus
@@ -160,7 +169,7 @@ void accept_SDO(void) {
                             printf("problem in uldy_process_msg\n");
                         }
                     } else {
-                        printf("ULOI message processed\n");
+                        printf("ULOI message processed: sadr: %i, dadr: %i\n", msginfo.sadr, msginfo.dadr);
                     }
                 } else {
                     ul_freemsg(ul_fd);
@@ -173,16 +182,15 @@ void process_PDO(void){
 uchar * buf;
 int buf_len = 0;
 
-int position = 0;
+int position = 3;
 
-int cid = 0;
+uint cid = 0;
 int len_data = 0;
 int data = 0;
 
     buf_len = msginfo.len;
     buf = (uchar *) malloc(buf_len*sizeof(uchar));
     ul_read(ul_fd, buf, buf_len);
-
     while(1){
         if ((position+2) > buf_len) break;
         cid = take_cid(&buf[position]);
@@ -200,8 +208,8 @@ int data = 0;
     }
 }
 
-int take_cid(uchar * buf){
-    return buf2int(buf);
+uint take_cid(uchar * buf){
+    return buf2uint(buf);
 }
 
 int take_len(uchar * buf){
index bece6063a26d5286237e8dbfff6212007fd5e6cf..61cfbf37b1a5ebbcb4b5c94e1c829b4b31e24954 100644 (file)
@@ -43,6 +43,8 @@ void long2buf(uchar *buf,unsigned long mod);
 void int2buf(uchar *buf,int mod);
 int buf2int(uchar *buf);
 
+uint buf2uint(uchar *buf);
+
 mstime_t current_time();
 void blink(void);
 
@@ -52,7 +54,7 @@ void heartbeat(void);
 void accept_SDO(void);
 void process_PDO(void);
 
-int take_cid(uchar* buf);
+uint take_cid(uchar* buf);
 int take_len(uchar* buf);
 int take_data(uchar* buf, int len);
 
index 5a3776b2b95df6e413a34471b3d7c06e67378151..21865eb14f28937afdab46843aedb77849cc6206 100644 (file)
@@ -81,7 +81,7 @@ void loop(void){
                     l2time = current_time();
                 }
             }
-        }
+        } else heartbeat();
         accept_SDO();
 
         regulate();