Instrument Neutral Distributed Interface INDI  2.0.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(),
51  groupSettingsName.c_str(), "Image group settings",
52  groupName.c_str(), IP_RW, 60, IPS_IDLE);
53 }
54 
55 int Group::binning() const
56 {
57  return GroupSettingsN[CCD_BINNING].value;
58 }
59 
60 int Group::filterSlot() const
61 {
62  return GroupSettingsN[FILTER_SLOT].value;
63 }
64 
65 double Group::exposure() const
66 {
67  return GroupSettingsN[CCD_EXPOSURE_VALUE].value;
68 }
69 
70 int Group::count() const
71 {
72  return GroupSettingsN[IMAGE_COUNT].value;
73 }
74 
75 
76 bool Group::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
77 {
78  INDI_UNUSED(dev);
79  if (groupSettingsName == name)
80  {
81  IUUpdateNumber(&GroupSettingsNP, values, names, n);
82  GroupSettingsNP.s = IPS_OK;
83  IDSetNumber(&GroupSettingsNP, nullptr);
84  return true;
85  }
86  return false;
87 }
88 
90 {
91  imager->defineProperty(&GroupSettingsNP);
92 }
93 
95 {
96  imager->deleteProperty(GroupSettingsNP.name);
97 }
std::shared_ptr< Imager > imager(new Imager())
void defineProperties()
Definition: group.cpp:89
int binning() const
Definition: group.cpp:55
int count() const
Definition: group.cpp:70
double exposure() const
Definition: group.cpp:65
Group(int id, Imager *imager)
Definition: group.cpp:33
void deleteProperties()
Definition: group.cpp:94
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: group.cpp:76
int filterSlot() const
Definition: group.cpp:60
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
static const std::string DEVICE_NAME
Definition: agent_imager.h:30
#define IMAGE_COUNT
Definition: group.cpp:28
#define CCD_BINNING
Definition: group.cpp:29
#define GROUP_PREFIX
Definition: group.cpp:25
#define FILTER_SLOT
Definition: group.cpp:30
#define CCD_EXPOSURE_VALUE
Definition: group.cpp:31
@ IP_RW
Definition: indiapi.h:186
@ IPS_IDLE
Definition: indiapi.h:161
@ IPS_OK
Definition: indiapi.h:162
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: indidevapi.c:272
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: indidevapi.c:180
#define INDI_UNUSED(x)
Definition: indidevapi.h:131
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
Definition: indidriver.c:1211
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
Definition: indidriver.c:1362
char name[MAXINDINAME]
Definition: indiapi.h:323