Instrument Neutral Distributed Interface INDI  2.0.2
pegasus_uch.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2021 Chrysikos Efstathios. All rights reserved.
3 
4  Pegasus USB Control Hub
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the Free
8  Software Foundation; either version 2 of the License, or (at your option)
9  any later version.
10 
11  This program is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 
21  The full GNU General Public License is included in this distribution in the
22  file called LICENSE.
23 *******************************************************************************/
24 
25 
26 #pragma once
27 
28 #include "defaultdevice.h"
29 #include <stdint.h>
30 #include <map>
31 
32 namespace Connection
33 {
34 class Serial;
35 }
36 
37 struct SwitchMap
38 {
41 };
42 
43 
44 
46 {
47  public:
48  PegasusUCH();
49  virtual bool initProperties() override;
50  virtual bool updateProperties() override;
51  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
52 
53 
54  protected:
55  const char *getDefaultName() override;
56  virtual bool saveConfigItems(FILE *fp) override;
57  // Event loop
58  virtual void TimerHit() override;
59 
60  private:
61  bool Handshake();
62 
63  // Device Control
64  bool reboot();
65 
66  // USB
67  bool setPowerLEDEnabled(bool enabled);
68  bool setUSBHubEnabled(bool enabled);
69  bool setUSBPort(uint8_t port, ISwitch usbPortS[2], ISwitchVectorProperty sp, ISState * states, char * names[], int n);
70  bool setUSBPortEnabled(uint8_t port, bool enabled);
71  void setFirmwareVersion();
72  void setBootstrapUSB();
73  void updateUSBPower();
74  void updateUpTime();
75 
76  bool sendCommand(const char *command, char *res);
77  void cleanupResponse(char *response);
78  std::vector<std::string> split(const std::string &input, const std::string &regex);
79 
80 
81  int PortFD { -1 };
82  bool initialized { false };
83 
84  Connection::Serial *serialConnection { nullptr };
85 
89 
91  ISwitch RebootS[1];
92  ISwitchVectorProperty RebootSP;
93 
94 
95  // Power LED
96  ISwitch PowerLEDS[2];
97  ISwitchVectorProperty PowerLEDSP;
98  enum
99  {
100  POWER_LED_ON,
101  POWER_LED_OFF,
102  };
103 
104 
105  // USB
106  enum { USB_OFF, USB_ON };
107 
108 
109  std::map<int, SwitchMap> usbPort =
110  {
111  { 0, { .S = USBPort1S, .SP = &USBPort1SP } },
112  { 1, { .S = USBPort2S, .SP = &USBPort2SP } },
113  { 2, { .S = USBPort3S, .SP = &USBPort3SP } },
114  { 3, { .S = USBPort4S, .SP = &USBPort4SP } },
115  { 4, { .S = USBPort5S, .SP = &USBPort5SP } },
116  { 5, { .S = USBPort6S, .SP = &USBPort6SP } }
117  };
118 
119 
120 
121  ISwitch USBPort1S[2];
122  ISwitchVectorProperty USBPort1SP;
123 
124  ISwitch USBPort2S[2];
125  ISwitchVectorProperty USBPort2SP;
126 
127  ISwitch USBPort3S[2];
128  ISwitchVectorProperty USBPort3SP;
129 
130  ISwitch USBPort4S[2];
131  ISwitchVectorProperty USBPort4SP;
132 
133  ISwitch USBPort5S[2];
134  ISwitchVectorProperty USBPort5SP;
135 
136  ISwitch USBPort6S[2];
137  ISwitchVectorProperty USBPort6SP;
138 
139 
140 
141  //Firmware
142  ITextVectorProperty InfoTP;
143  IText InfoT[3] {};
144 
145 
146  enum
147  {
148  INFO_VERSION,
149  INFO_UPTIME,
150  INFO_USBVOLTAGE
151 
152  };
153 
154 
155  static constexpr const uint8_t PEGASUS_TIMEOUT {3};
156  static constexpr const uint8_t PEGASUS_LEN {32};
157  static constexpr const char *USB_TAB {"USB"};
158  static constexpr const char *INFO_TAB {"INFO"};
159 };
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: pegasus_uch.cpp:53
const char * getDefaultName() override
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
ISState
Switch state.
Definition: indiapi.h:150
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:34
One switch descriptor.
One text descriptor.
ISwitch * S
Definition: pegasus_uch.h:39
ISwitchVectorProperty * SP
Definition: pegasus_uch.h:40
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246