• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • indi
indilistener.cpp
Go to the documentation of this file.
1 /* INDI Listener
2  Copyright (C) 2012 Jasem Mutlaq (mutlaqja@ikarustech.com)
3 
4  This application is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  Handle INDI Standard properties.
10  */
11 
12 #include <QDebug>
13 
14 #include <KMessageBox>
15 #include <KStatusBar>
16 
17 #include <baseclient.h>
18 #include <basedevice.h>
19 
20 #include "indilistener.h"
21 #include "indicommon.h"
22 #include "inditelescope.h"
23 #include "indifocuser.h"
24 #include "indiccd.h"
25 #include "indifilter.h"
26 #include "clientmanager.h"
27 #include "driverinfo.h"
28 #include "deviceinfo.h"
29 #include "fitsviewer/fitsviewer.h"
30 
31 #include "kstars.h"
32 #include "Options.h"
33 
34 #define NINDI_STD 26
35 
36 /* INDI standard property used across all clients to enable interoperability. */
37 const char * indi_std[NINDI_STD] =
38  {"CONNECTION", "DEVICE_PORT", "TIME_UTC", "TIME_LST", "GEOGRAPHIC_COORD", "EQUATORIAL_COORD",
39  "EQUATORIAL_EOD_COORD", "EQUATORIAL_EOD_COORD_REQUEST", "HORIZONTAL_COORD", "TELESCOPE_ABORT_MOTION", "ON_COORD_SET",
40  "SOLAR_SYSTEM", "TELESCOPE_MOTION_NS", "TELESCOPE_MOTION_WE", "TELESCOPE_PARK", "CCD_EXPOSURE",
41  "CCD_TEMPERATURE", "CCD_FRAME", "CCD_FRAME_TYPE", "CCD_BINNING", "CCD_INFO", "VIDEO_STREAM",
42  "FOCUS_SPEED", "FOCUS_MOTION", "FOCUS_TIMER", "FILTER_SLOT" };
43 
44 INDIListener * INDIListener::_INDIListener = NULL;
45 
46 INDIListener * INDIListener::Instance()
47 {
48  if (_INDIListener == NULL)
49  _INDIListener = new INDIListener();
50 
51  return _INDIListener;
52 }
53 
54 INDIListener::INDIListener()
55 {
56  batchMode = false;
57  ISOMode = true;
58  fv = NULL;
59 }
60 
61 bool INDIListener::isStandardProperty(const QString &name)
62 {
63  for (int i=0; i < NINDI_STD; i++)
64  if (!strcmp(name.toLatin1().constData(), indi_std[i]))
65  return true;
66 
67  return false;
68 }
69 
70 ISD::GDInterface * INDIListener::getDevice(const QString &name)
71 {
72  foreach(ISD::GDInterface *gi, devices)
73  if (!strcmp(gi->getDeviceName(), name.toLatin1().constData()))
74  return gi;
75 
76  return NULL;
77 }
78 
79 void INDIListener::addClient(ClientManager *cm)
80 {
81  //qDebug() << "add client for listener called " << endl;
82  clients.append(cm);
83 
84  connect(cm, SIGNAL(newINDIDevice(DeviceInfo*)), this, SLOT(processDevice(DeviceInfo*)));
85 
86  connect(cm, SIGNAL(INDIDeviceRemoved(DeviceInfo*)), this, SLOT(removeDevice(DeviceInfo*)));
87 
88  connect(cm, SIGNAL(newINDIProperty(INDI::Property*)), this, SLOT(registerProperty(INDI::Property*)));
89  //connect(cm, SIGNAL(removeINDIProperty(INDI::Property*)), this, SLOT(removeProperty(INDI::Property*)), Qt::BlockingQueuedConnection);
90  connect(cm, SIGNAL(removeINDIProperty(INDI::Property*)), this, SLOT(removeProperty(INDI::Property*)));
91 
92  connect(cm, SIGNAL(newINDISwitch(ISwitchVectorProperty*)), this, SLOT(processSwitch(ISwitchVectorProperty*)));
93  connect(cm, SIGNAL(newINDIText(ITextVectorProperty*)), this, SLOT(processText(ITextVectorProperty*)));
94  connect(cm, SIGNAL(newINDINumber(INumberVectorProperty*)), this, SLOT(processNumber(INumberVectorProperty*)));
95  connect(cm, SIGNAL(newINDILight(ILightVectorProperty*)), this, SLOT(processLight(ILightVectorProperty*)));
96  connect(cm, SIGNAL(newINDIBLOB(IBLOB*)), this, SLOT(processBLOB(IBLOB*)));
97 
98 }
99 
100 void INDIListener::removeClient(ClientManager *cm)
101 {
102  QList<ISD::GDInterface *>::iterator it = devices.begin();
103  clients.removeOne(cm);
104 
105  while (it != devices.end())
106  {
107  if ( (*it)->getDriverInfo()->getClientManager() == cm)
108  {
109  cm->disconnect(this);
110  it = devices.erase(it);
111  }
112  else
113  ++it;
114  }
115 }
116 
117 void INDIListener::processDevice(DeviceInfo *dv)
118 {
119  //qDebug() << "process Device called for " << dv->getBaseDevice()->getDeviceName() << endl;
120 
121  ISD::GDInterface *gd = new ISD::GenericDevice(dv);
122 
123  //qDebug() << "Unique label for dv " << dv->getName() << " is: " << dv->getUniqueLabel() << endl;
124 
125  devices.append(gd);
126 
127  emit newDevice(gd);
128 }
129 
130 void INDIListener::removeDevice(DeviceInfo *dv)
131 {
132  foreach(ISD::GDInterface *gd, devices)
133  {
134  if (dv->getDriverInfo()->getUniqueLabel() == gd->getDeviceName() || dv->getDriverInfo()->getDriverSource() == HOST_SOURCE)
135  {
136  emit deviceRemoved(gd);
137  devices.removeOne(gd);
138  delete(gd);
139 
140  if (dv->getDriverInfo()->getDriverSource() != HOST_SOURCE)
141  return;
142  }
143  }
144 
145 }
146 
147 void INDIListener::registerProperty(INDI::Property *prop)
148 {
149 
150  foreach(ISD::GDInterface *gd, devices)
151  {
152  if (!strcmp(gd->getDeviceName(), prop->getDeviceName() ))
153  {
154  if ( gd->getType() == KSTARS_UNKNOWN && (!strcmp(prop->getName(), "EQUATORIAL_EOD_COORD") || !strcmp(prop->getName(), "HORIZONTAL_COORD")) )
155  {
156  devices.removeOne(gd);
157  gd = new ISD::Telescope(gd);
158  devices.append(gd);
159  emit newTelescope(gd);
160  }
161  else if (gd->getType() == KSTARS_UNKNOWN && (!strcmp(prop->getName(), "CCD_EXPOSURE")))
162  {
163  devices.removeOne(gd);
164  gd = new ISD::CCD(gd);
165  devices.append(gd);
166  emit newCCD(gd);
167  }
168  else if (!strcmp(prop->getName(), "FILTER_SLOT"))
169  {
170  if (gd->getType() == KSTARS_UNKNOWN)
171  {
172  devices.removeOne(gd);
173  gd = new ISD::Filter(gd);
174  devices.append(gd);
175  }
176 
177  emit newFilter(gd);
178  }
179  else if (!strcmp(prop->getName(), "FOCUS_MOTION"))
180  {
181  if (gd->getType() == KSTARS_UNKNOWN)
182  {
183  devices.removeOne(gd);
184  gd = new ISD::Focuser(gd);
185  devices.append(gd);
186  }
187 
188  emit newFocuser(gd);
189  }
190 
191  if (!strcmp(prop->getName(), "TELESCOPE_TIMED_GUIDE_WE"))
192  {
193  ISD::ST4 *st4Driver = new ISD::ST4(gd->getBaseDevice(), gd->getDriverInfo()->getClientManager());
194  st4Devices.append(st4Driver);
195  emit newST4(st4Driver);
196  }
197 
198  gd->registerProperty(prop);
199  break;
200  }
201  }
202 }
203 
204 void INDIListener::removeProperty(INDI::Property *prop)
205 {
206 
207  if (prop == NULL)
208  return;
209 
210  foreach(ISD::GDInterface *gd, devices)
211  {
212  if (!strcmp(gd->getDeviceName(), prop->getDeviceName() ))
213  {
214  gd->removeProperty(prop);
215  return;
216  }
217  }
218 }
219 
220 void INDIListener::processSwitch(ISwitchVectorProperty * svp)
221 {
222 
223  foreach(ISD::GDInterface *gd, devices)
224  {
225  if (!strcmp(gd->getDeviceName(), svp->device))
226  {
227  gd->processSwitch(svp);
228  break;
229  }
230  }
231 
232 }
233 
234 void INDIListener::processNumber(INumberVectorProperty * nvp)
235 {
236  foreach(ISD::GDInterface *gd, devices)
237  {
238  if (!strcmp(gd->getDeviceName(), nvp->device))
239  {
240  gd->processNumber(nvp);
241  break;
242  }
243  }
244 }
245 
246 void INDIListener::processText(ITextVectorProperty * tvp)
247 {
248  foreach(ISD::GDInterface *gd, devices)
249  {
250  if (!strcmp(gd->getDeviceName(), tvp->device))
251  {
252  gd->processText(tvp);
253  break;
254  }
255  }
256 }
257 
258 void INDIListener::processLight(ILightVectorProperty * lvp)
259 {
260 
261  foreach(ISD::GDInterface *gd, devices)
262  {
263  if (!strcmp(gd->getDeviceName(), lvp->device))
264  {
265  gd->processLight(lvp);
266  break;
267  }
268  }
269 }
270 
271 void INDIListener::processBLOB(IBLOB* bp)
272 {
273  foreach(ISD::GDInterface *gd, devices)
274  {
275  if (!strcmp(gd->getDeviceName(), bp->bvp->device))
276  {
277  gd->processBLOB(bp);
278  break;
279  }
280  }
281 }
282 
283 #include "indilistener.moc"
indi_std
const char * indi_std[NINDI_STD]
Definition: indilistener.cpp:37
INDIListener::deviceRemoved
void deviceRemoved(ISD::GDInterface *)
INDIListener::newFilter
void newFilter(ISD::GDInterface *)
ISD::GDInterface::registerProperty
virtual void registerProperty(INDI::Property *prop)=0
indilistener.h
deviceinfo.h
INDIListener::Instance
static INDIListener * Instance()
Definition: indilistener.cpp:46
INDIListener::processSwitch
void processSwitch(ISwitchVectorProperty *svp)
Definition: indilistener.cpp:220
indifocuser.h
INDIListener::removeProperty
void removeProperty(INDI::Property *prop)
Definition: indilistener.cpp:204
ISD::GDInterface::getBaseDevice
virtual INDI::BaseDevice * getBaseDevice()=0
KSTARS_UNKNOWN
Definition: indicommon.h:66
ISD::GDInterface::getDeviceName
virtual const char * getDeviceName()=0
ISD::GDInterface::processLight
virtual void processLight(ILightVectorProperty *lvp)=0
ISD::GDInterface::processNumber
virtual void processNumber(INumberVectorProperty *nvp)=0
ISD::GDInterface::processText
virtual void processText(ITextVectorProperty *tvp)=0
clientmanager.h
ISD::Focuser
Definition: indifocuser.h:18
ISD::GDInterface::removeProperty
virtual void removeProperty(INDI::Property *prop)=0
INDIListener::removeDevice
void removeDevice(DeviceInfo *dv)
Definition: indilistener.cpp:130
DriverInfo::getClientManager
ClientManager * getClientManager()
Definition: driverinfo.h:61
ISD::Filter
Definition: indifilter.h:18
INDIListener::addClient
void addClient(ClientManager *cm)
Definition: indilistener.cpp:79
ISD::GenericDevice
Definition: indistd.h:102
DriverInfo::getDriverSource
DriverSource getDriverSource()
Definition: driverinfo.h:55
INDIListener::newFocuser
void newFocuser(ISD::GDInterface *)
driverinfo.h
HOST_SOURCE
Definition: indicommon.h:15
INDIListener::getDevice
ISD::GDInterface * getDevice(const QString &name)
Definition: indilistener.cpp:70
DriverInfo::getUniqueLabel
const QString & getUniqueLabel()
Definition: driverinfo.h:43
indifilter.h
INDIListener::newST4
void newST4(ISD::ST4 *)
DeviceInfo::getDriverInfo
DriverInfo * getDriverInfo()
Definition: deviceinfo.h:23
INDIListener::processBLOB
void processBLOB(IBLOB *bp)
Definition: indilistener.cpp:271
ISD::Telescope
Definition: inditelescope.h:19
inditelescope.h
INDIListener::isStandardProperty
bool isStandardProperty(const QString &name)
Definition: indilistener.cpp:61
indiccd.h
NINDI_STD
#define NINDI_STD
Definition: indilistener.cpp:34
Options.h
ISD::GDInterface::getType
virtual DeviceFamily getType()=0
INDIListener::newDevice
void newDevice(ISD::GDInterface *)
INDIListener::newTelescope
void newTelescope(ISD::GDInterface *)
ISD::GDInterface::processSwitch
virtual void processSwitch(ISwitchVectorProperty *svp)=0
ClientManager
Definition: clientmanager.h:22
INDIListener
Definition: indilistener.h:25
INDIListener::processText
void processText(ITextVectorProperty *tvp)
Definition: indilistener.cpp:246
INDIListener::processNumber
void processNumber(INumberVectorProperty *nvp)
Definition: indilistener.cpp:234
ISD::GDInterface::processBLOB
virtual void processBLOB(IBLOB *bp)=0
ISD::ST4
Definition: indistd.h:195
INDIListener::removeClient
void removeClient(ClientManager *cm)
Definition: indilistener.cpp:100
INDIListener::processLight
void processLight(ILightVectorProperty *lvp)
Definition: indilistener.cpp:258
fitsviewer.h
ISD::CCD
Definition: indiccd.h:73
DeviceInfo
Definition: deviceinfo.h:18
indicommon.h
INDIListener::newCCD
void newCCD(ISD::GDInterface *)
kstars.h
ISD::GDInterface
Definition: indistd.h:48
INDIListener::registerProperty
void registerProperty(INDI::Property *prop)
Definition: indilistener.cpp:147
INDIListener::processDevice
void processDevice(DeviceInfo *dv)
Definition: indilistener.cpp:117
QList
ISD::GDInterface::getDriverInfo
virtual DriverInfo * getDriverInfo()=0
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal