File: tutorial_rain.c

package info (click to toggle)
libindi 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,232 kB
  • sloc: ansic: 17,921; cpp: 17,821; xml: 260; makefile: 12
file content (145 lines) | stat: -rw-r--r-- 4,118 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#if 0
    Inter-driver communications tutorial - Rain Driver 
    Copyright (C) 2007 Jasem Mutlaq (mutlaqja@ikarustech.com)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <zlib.h>

#include "indidevapi.h"
#include "eventloop.h"
#include "indicom.h"

#define mydev           "Rain"

#define MAIN_GROUP	"Main"

/* Connect/Disconnect */
static ISwitch PowerS[]          	= {{"CONNECT" , "Connect" , ISS_OFF, 0, 0},{"DISCONNECT", "Disconnect", ISS_ON, 0, 0}};
static ISwitchVectorProperty PowerSP	= { mydev, "CONNECTION" , "Connection", MAIN_GROUP, IP_RW, ISR_1OFMANY, 60, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0};

/* Rain Alert Property. The dome driver will listen to updates on this property. 
   The rain driver does not need to take any action to make this property available to other driver,
   the INDI framework takes care of handling inter-driver communication
*/
static ILight RainL[]			= {{"Status", "", IPS_IDLE, 0, 0}};
static ILightVectorProperty RainLP	= { mydev, "Rain Alert", "", MAIN_GROUP, IPS_IDLE, RainL , NARRAY(RainL), "", 0};

static ISwitch RainS[]           	= {{"On", "", ISS_OFF, 0, 0}, {"Off", "", ISS_ON, 0, 0}};
static ISwitchVectorProperty RainSP	= { mydev, "Control Rain", "", MAIN_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, RainS , NARRAY(RainS), "", 0};

void ISGetProperties (const char *dev)
{ 
  /* MAIN_GROUP */
  IDDefSwitch(&PowerSP, NULL);
  IDDefLight(&RainLP, NULL);
  IDDefSwitch(&RainSP, NULL);
}

void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) {}
void ISSnoopDevice (XMLEle *root) {}
  
void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
	/* ignore if not ours */
	if (dev && strcmp (dev, mydev))
	    return;

	/* Connection */
	if (!strcmp (name, PowerSP.name))
	{
	  if (IUUpdateSwitch(&PowerSP, states, names, n) < 0)
		return;

   	  PowerSP.s = IPS_OK;

	  if (PowerS[0].s == ISS_ON)
		IDSetSwitch(&PowerSP, "Rain Collector is online.");
	  else
	  {
		PowerSP.s = IPS_IDLE;
		IDSetSwitch(&PowerSP, "Rain Collector is offline.");
	  }
	  return;
	}

	/* rain */
	if (!strcmp (name, RainSP.name))
	{
		if (PowerSP.s != IPS_OK)
		{
			IDMessage(mydev, "The Rain Collector is offline!");
			return;
		}
		
	  if (IUUpdateSwitch(&RainSP, states, names, n) < 0)
		return;

	 RainSP.s = IPS_OK;
	 IDSetSwitch(&RainSP, "Rain status updated.");
	 
	 if (RainS[0].s == ISS_ON)
	 {
		 RainL[0].s = IPS_ALERT;
		 RainLP.s   = IPS_ALERT;
		 IDSetLight(&RainLP, "Alert! Alert! Rain detected!");
	 }
	 else
	 {
		 RainL[0].s = IPS_IDLE;
		 RainLP.s   = IPS_OK;
		 IDSetLight(&RainLP, "Rain threat passed. The skies are clear.");
	 }
	 
	   return;
	}
			
}

void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
{
 
       /* ignore if not ours */ 
       if (dev && strcmp (mydev, dev))
         return;

	/* suppress warning */
	n=n; dev=dev; name=name; names=names; texts=texts;
	
}


void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
{
       
}