File: tutorial_client.cpp

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 (169 lines) | stat: -rw-r--r-- 4,782 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#if 0
    Simple Client Tutorial
    Demonstration of libindi v0.7 capabilities.

    Copyright (C) 2010 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 <string>
#include <iostream>

#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <unistd.h>
#include <time.h>
#include <memory>
#include <sys/types.h>
#include <sys/stat.h>

#include <config.h>

#include "indibase/baseclient.h"
#include "indibase/basedriver.h"

/* INDI Common Library Routines */
#include "indicom.h"

#include "tutorial_client.h"

using namespace std;

#define MYCCD "CCD Simulator"

/* Our client auto pointer */
auto_ptr<MyClient> camera_client(0);

int main(int argc, char *argv[])
{

    if (camera_client.get() == 0)
        camera_client.reset(new MyClient());


  camera_client->setServer("localhost", 7624);

  camera_client->watchDevice(MYCCD);

  camera_client->connectServer();

  cout << "Press any key to terminate the client.\n";
  string term;
  cin >> term;


}


/**************************************************************************************
**
***************************************************************************************/
MyClient::MyClient()
{
    ccd_simulator = NULL;
}

/**************************************************************************************
**
***************************************************************************************/
MyClient::~MyClient()
{

}

/**************************************************************************************
**
***************************************************************************************/
void MyClient::setTemperature()
{
   INumberVectorProperty *ccd_temperature = NULL;

   ccd_temperature = ccd_simulator->getNumber("CCD_TEMPERATURE");

   if (ccd_temperature == NULL)
   {
       IDLog("Error: unable to find CCD Simulator CCD_TEMPERATURE property...\n");
       return;
   }

   ccd_temperature->np[0].value = -20;
   sendNewNumber(ccd_temperature);
}

/**************************************************************************************
**
***************************************************************************************/
void MyClient::newDevice(const char *device_name)
{
    if (!strcmp(device_name, "CCD Simulator"))
    {
        IDLog("Receiving CCD Simulator Device...\n");

        ccd_simulator = getDriver(MYCCD);

        if (ccd_simulator == NULL)
        {
            IDLog("Error: unable to find CCD Simulator device...\n");
            return;
        }
    }
}

/**************************************************************************************
**
***************************************************************************************/
void MyClient::newProperty(const char *device_name, const char *property_name)
{
     if (!strcmp(device_name, "CCD Simulator") && !strcmp(property_name, "CCD_TEMPERATURE"))
     {
             IDLog("CCD_TEMPERATURE standard property defined. Attempting connection to CCD...\n");
             setDriverConnection(true, MYCCD);
     }
}

/**************************************************************************************
**
***************************************************************************************/
void MyClient::newSwitch(ISwitchVectorProperty *svp)
{
    // Let's check if we're ON
    if (!strcmp(svp->name, "CONNECTION"))
    {
        if (svp->sp[0].s == ISS_ON)
        {
            IDLog("CCD is connected. Setting temperature to -20 C.\n");
            setTemperature();
        }
    }
}

/**************************************************************************************
**
***************************************************************************************/
void MyClient::newNumber(INumberVectorProperty *nvp)
{
    // Let's check if we get any new values for CCD_TEMPERATURE
    if (!strcmp(nvp->name, "CCD_TEMPERATURE"))
    {
       IDLog("Receving new CCD Temperature: %g C\n", nvp->np[0].value);

       if (nvp->np[0].value == -20)
           IDLog("CCD temperature reached desired value!\n");
   }
}