| 1 | #if 0
|
|---|
| 2 | Inter-driver communications tutorial - Rain Driver
|
|---|
| 3 | Copyright (C) 2007 Jasem Mutlaq (mutlaqja@ikarustech.com)
|
|---|
| 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library 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 GNU
|
|---|
| 13 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with this library; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|---|
| 18 |
|
|---|
| 19 | #endif
|
|---|
| 20 |
|
|---|
| 21 | #include <stdio.h>
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 | #include <string.h>
|
|---|
| 24 | #include <stdarg.h>
|
|---|
| 25 | #include <math.h>
|
|---|
| 26 | #include <unistd.h>
|
|---|
| 27 | #include <time.h>
|
|---|
| 28 | #include <fcntl.h>
|
|---|
| 29 | #include <errno.h>
|
|---|
| 30 | #include <sys/stat.h>
|
|---|
| 31 | #include <sys/time.h>
|
|---|
| 32 | #include <sys/types.h>
|
|---|
| 33 | #include <sys/socket.h>
|
|---|
| 34 | #include <netinet/in.h>
|
|---|
| 35 | #include <netdb.h>
|
|---|
| 36 | #include <zlib.h>
|
|---|
| 37 |
|
|---|
| 38 | #include "indidevapi.h"
|
|---|
| 39 | #include "eventloop.h"
|
|---|
| 40 | #include "indicom.h"
|
|---|
| 41 |
|
|---|
| 42 | #define mydev "Rain"
|
|---|
| 43 |
|
|---|
| 44 | #define MAIN_GROUP "Main"
|
|---|
| 45 |
|
|---|
| 46 | /* Connect/Disconnect */
|
|---|
| 47 | static ISwitch PowerS[] = {{"CONNECT" , "Connect" , ISS_OFF, 0, 0},{"DISCONNECT", "Disconnect", ISS_ON, 0, 0}};
|
|---|
| 48 | static ISwitchVectorProperty PowerSP = { mydev, "CONNECTION" , "Connection", MAIN_GROUP, IP_RW, ISR_1OFMANY, 60, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0};
|
|---|
| 49 |
|
|---|
| 50 | /* Rain Alert Property. The dome driver will listen to updates on this property.
|
|---|
| 51 | The rain driver does not need to take any action to make this property available to other driver,
|
|---|
| 52 | the INDI framework takes care of handling inter-driver communication
|
|---|
| 53 | */
|
|---|
| 54 | static ILight RainL[] = {{"Status", "", IPS_IDLE, 0, 0}};
|
|---|
| 55 | static ILightVectorProperty RainLP = { mydev, "Rain Alert", "", MAIN_GROUP, IPS_IDLE, RainL , NARRAY(RainL), "", 0};
|
|---|
| 56 |
|
|---|
| 57 | static ISwitch RainS[] = {{"On", "", ISS_OFF, 0, 0}, {"Off", "", ISS_ON, 0, 0}};
|
|---|
| 58 | static ISwitchVectorProperty RainSP = { mydev, "Control Rain", "", MAIN_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, RainS , NARRAY(RainS), "", 0};
|
|---|
| 59 |
|
|---|
| 60 | void ISGetProperties (const char *dev)
|
|---|
| 61 | {
|
|---|
| 62 | /* MAIN_GROUP */
|
|---|
| 63 | IDDefSwitch(&PowerSP, NULL);
|
|---|
| 64 | IDDefLight(&RainLP, NULL);
|
|---|
| 65 | IDDefSwitch(&RainSP, NULL);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) {}
|
|---|
| 69 | void ISSnoopDevice (XMLEle *root) {}
|
|---|
| 70 |
|
|---|
| 71 | void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
|
|---|
| 72 | {
|
|---|
| 73 | /* ignore if not ours */
|
|---|
| 74 | if (dev && strcmp (dev, mydev))
|
|---|
| 75 | return;
|
|---|
| 76 |
|
|---|
| 77 | /* Connection */
|
|---|
| 78 | if (!strcmp (name, PowerSP.name))
|
|---|
| 79 | {
|
|---|
| 80 | if (IUUpdateSwitch(&PowerSP, states, names, n) < 0)
|
|---|
| 81 | return;
|
|---|
| 82 |
|
|---|
| 83 | PowerSP.s = IPS_OK;
|
|---|
| 84 |
|
|---|
| 85 | if (PowerS[0].s == ISS_ON)
|
|---|
| 86 | IDSetSwitch(&PowerSP, "Rain Collector is online.");
|
|---|
| 87 | else
|
|---|
| 88 | {
|
|---|
| 89 | PowerSP.s = IPS_IDLE;
|
|---|
| 90 | IDSetSwitch(&PowerSP, "Rain Collector is offline.");
|
|---|
| 91 | }
|
|---|
| 92 | return;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /* rain */
|
|---|
| 96 | if (!strcmp (name, RainSP.name))
|
|---|
| 97 | {
|
|---|
| 98 | if (PowerSP.s != IPS_OK)
|
|---|
| 99 | {
|
|---|
| 100 | IDMessage(mydev, "The Rain Collector is offline!");
|
|---|
| 101 | return;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | if (IUUpdateSwitch(&RainSP, states, names, n) < 0)
|
|---|
| 105 | return;
|
|---|
| 106 |
|
|---|
| 107 | RainSP.s = IPS_OK;
|
|---|
| 108 | IDSetSwitch(&RainSP, "Rain status updated.");
|
|---|
| 109 |
|
|---|
| 110 | if (RainS[0].s == ISS_ON)
|
|---|
| 111 | {
|
|---|
| 112 | RainL[0].s = IPS_ALERT;
|
|---|
| 113 | RainLP.s = IPS_ALERT;
|
|---|
| 114 | IDSetLight(&RainLP, "Alert! Alert! Rain detected!");
|
|---|
| 115 | }
|
|---|
| 116 | else
|
|---|
| 117 | {
|
|---|
| 118 | RainL[0].s = IPS_IDLE;
|
|---|
| 119 | RainLP.s = IPS_OK;
|
|---|
| 120 | IDSetLight(&RainLP, "Rain threat passed. The skies are clear.");
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | return;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
|
|---|
| 129 | {
|
|---|
| 130 |
|
|---|
| 131 | /* ignore if not ours */
|
|---|
| 132 | if (dev && strcmp (mydev, dev))
|
|---|
| 133 | return;
|
|---|
| 134 |
|
|---|
| 135 | /* suppress warning */
|
|---|
| 136 | n=n; dev=dev; name=name; names=names; texts=texts;
|
|---|
| 137 |
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 | void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
|
|---|
| 142 | {
|
|---|
| 143 |
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|