]> rtime.felk.cvut.cz Git - hydro.git/blob - app/sensor/hydroponie.c
Added code for second device.
[hydro.git] / app / sensor / hydroponie.c
1 /***************************************************************************
2  *   Copyright (C) 2008 by stefic    *
3  *   stefaj1@fel.cvut.cz   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 //#define OS_POSIX
22
23 #ifdef HAVE_CONFIG_H
24     #include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <system_def.h>
31 #include <cpu_def.h>
32
33 //INCLUDE IN CURRENT DIRECTORY
34 #include "hydroponie.h"
35
36 void loop(void){
37     mstime_t ltime, l2time;
38     mstime_t ctime;
39
40     led1_time = current_time();
41     led2_time = current_time();
42
43     while(1){
44         blink();
45         send_sn();
46         ltime = current_time();
47         while(1){
48             ctime = current_time();
49             if((ctime-ltime) > 1000){
50                 break;
51             }
52             #ifdef OS_POSIX
53                 usleep(1);
54             #endif
55             accept_SDO();
56         }
57         if (ul_dyac->ul_dysa != 0) break;
58     }
59
60     ltime  = current_time();
61     l2time = current_time();
62
63     while(1){
64         blink();
65         ctime = current_time();
66
67         if (oi_period == 1){
68             if((ctime-ltime) > 1000){
69                 send_data();
70                 ltime = current_time();
71             }
72         } else {
73             if((ctime-ltime) > 1000){
74                 heartbeat();
75                 ltime = current_time();
76             }
77             if((ctime-l2time) > 1000*oi_period){
78                 send_data();
79                 l2time = current_time();
80             }
81         }
82         accept_SDO();
83         #ifdef OS_POSIX
84             usleep(1);
85         #endif
86     }
87 }
88
89 int main(int argc, char *argv[]) { 
90
91     all_init();
92
93     loop();
94
95 //     work_with();
96
97     ul_close(ul_fd);
98     ul_close(ul_fd1);
99
100     return EXIT_SUCCESS;
101 }