Instrument Neutral Distributed Interface INDI  1.9.2
group.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2013-2016 CloudMakers, s. r. o. All rights reserved.
3  Copyright(c) 2017-2018 Marco Gulino <marco.gulino@gmai.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  *******************************************************************************/
19 
20 #include "group.h"
21 #include "agent_imager.h"
22 #include <iomanip>
23 #include <sstream>
24 
25 #define GROUP_PREFIX "GROUP_"
26 #define GROUP_PREFIX_LEN 6
27 
28 #define IMAGE_COUNT 0
29 #define CCD_BINNING 1
30 #define FILTER_SLOT 2
31 #define CCD_EXPOSURE_VALUE 3
32 
34 {
35  id++;
36  std::stringstream groupNameStream;
37  groupNameStream << "Image group " << id;
38  groupName = groupNameStream.str();
39 
40  std::stringstream groupSettingsNameStream;
41  groupSettingsNameStream << GROUP_PREFIX << std::setw(2) << std::setfill('0') << id;
42  groupSettingsName = groupSettingsNameStream.str();
43 
44  GroupSettingsN.resize(4);
45 
46  IUFillNumber(&GroupSettingsN[IMAGE_COUNT], "IMAGE_COUNT", "Image count", "%3.0f", 1, 100, 1, 1);
47  IUFillNumber(&GroupSettingsN[CCD_BINNING], "CCD_BINNING", "Binning", "%1.0f", 1, 4, 1, 1);
48  IUFillNumber(&GroupSettingsN[FILTER_SLOT], "FILTER_SLOT", "Filter", "%2.f", 0, 12, 1, 0);
49  IUFillNumber(&GroupSettingsN[CCD_EXPOSURE_VALUE], "CCD_EXPOSURE_VALUE", "Duration (s)", "%5.2f", 0, 36000, 0, 1.0);
50  IUFillNumberVector(&GroupSettingsNP, GroupSettingsN.data(), GroupSettingsN.size(), Imager::DEVICE_NAME.c_str(), groupSettingsName.c_str(), "Image group settings",
51  groupName.c_str(), IP_RW, 60, IPS_IDLE);
52 }
53 
54 int Group::binning() const {
55  return GroupSettingsN[CCD_BINNING].value;
56 }
57 
58 int Group::filterSlot() const {
59  return GroupSettingsN[FILTER_SLOT].value;
60 }
61 
62 double Group::exposure() const {
63  return GroupSettingsN[CCD_EXPOSURE_VALUE].value;
64 }
65 
66 int Group::count() const {
67  return GroupSettingsN[IMAGE_COUNT].value;
68 }
69 
70 
71 bool Group::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
72 {
73  INDI_UNUSED(dev);
74  if (groupSettingsName == name)
75  {
76  IUUpdateNumber(&GroupSettingsNP, values, names, n);
77  GroupSettingsNP.s = IPS_OK;
78  IDSetNumber(&GroupSettingsNP, nullptr);
79  return true;
80  }
81  return false;
82 }
83 
85 {
86  imager->defineProperty(&GroupSettingsNP);
87 }
88 
90 {
91  imager->deleteProperty(GroupSettingsNP.name);
92 }
Group::defineProperties
void defineProperties()
Definition: group.cpp:84
Group::filterSlot
int filterSlot() const
Definition: group.cpp:58
Imager::DEVICE_NAME
static const std::string DEVICE_NAME
Definition: agent_imager.h:30
IPS_OK
@ IPS_OK
Definition: indiapi.h:161
_INumberVectorProperty::s
IPState s
Definition: indiapi.h:332
FILTER_SLOT
#define FILTER_SLOT
Definition: group.cpp:30
IUFillNumber
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition: indidriver.c:348
INDI::DefaultDevice::defineProperty
void defineProperty(INumberVectorProperty *property)
Definition: defaultdevice.cpp:997
group.h
imager
std::shared_ptr< Imager > imager(new Imager())
INDI_UNUSED
#define INDI_UNUSED(x)
Definition: indidevapi.h:799
GROUP_PREFIX
#define GROUP_PREFIX
Definition: group.cpp:25
Imager
Definition: agent_imager.h:27
Group::ISNewNumber
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: group.cpp:71
CCD_BINNING
#define CCD_BINNING
Definition: group.cpp:29
agent_imager.h
IUFillNumberVector
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition: indidriver.c:455
Group::exposure
double exposure() const
Definition: group.cpp:62
IPS_IDLE
@ IPS_IDLE
Definition: indiapi.h:160
_INumberVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:322
Group::count
int count() const
Definition: group.cpp:66
Group::binning
int binning() const
Definition: group.cpp:54
IMAGE_COUNT
#define IMAGE_COUNT
Definition: group.cpp:28
Group::Group
Group(int id, Imager *imager)
Definition: group.cpp:33
IUUpdateNumber
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
Definition: indidriver.c:225
IP_RW
@ IP_RW
Definition: indiapi.h:185
INDI::DefaultDevice::deleteProperty
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
Definition: defaultdevice.cpp:965
IDSetNumber
void void void IDSetNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing number vector property.
CCD_EXPOSURE_VALUE
#define CCD_EXPOSURE_VALUE
Definition: group.cpp:31
Group::deleteProperties
void deleteProperties()
Definition: group.cpp:89