]> rtime.felk.cvut.cz Git - hydro.git/blob - app-stefic/sensor/hydroponie.c
5a3776b2b95df6e413a34471b3d7c06e67378151
[hydro.git] / app-stefic / 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) > 3000){
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     l3time = current_time();
63
64     while(1){
65         blink();
66         ctime = current_time();
67
68         if (oi_period != 0){
69             if (oi_period == 1){
70                 if((ctime-ltime) > 1000){
71                     send_data();
72                     ltime = current_time();
73                 }
74             } else {
75                 if((ctime-ltime) > 1000){
76                     heartbeat();
77                     ltime = current_time();
78                 }
79                 if((ctime-l2time) > 1000*oi_period){
80                     send_data();
81                     l2time = current_time();
82                 }
83             }
84         }
85         accept_SDO();
86
87         regulate();
88
89         #ifdef OS_POSIX
90             usleep(1);
91         #endif
92     }
93 }
94
95 int main(int argc, char *argv[]) { 
96
97     all_init();
98
99     loop();
100
101 //     work_with();
102
103     ul_close(ul_fd);
104     ul_close(ul_fd1);
105
106     return EXIT_SUCCESS;
107 }