Instrument Neutral Distributed Interface INDI 2.2.5
startech_hub.h
Go to the documentation of this file.
1/*******************************************************************************
2 INDI StarTech Managed USB Hub Driver
3*******************************************************************************/
4
5#pragma once
6
7#include "defaultdevice.h"
9#include "indipropertytext.h"
10
11#include <array>
12#include <cstdint>
13#include <cstdio>
14#include <string>
15
16namespace Connection
17{
18class Serial;
19}
20
22{
23public:
25 virtual ~StarTechHub() = default;
26
27 bool initProperties() override;
28 bool updateProperties() override;
29
30protected:
31 const char *getDefaultName() override;
32 bool saveConfigItems(FILE *fp) override;
33 void TimerHit() override;
34
35 // Hook needed to react immediately to CONFIG_LOAD / CONFIG_DEFAULT
36 bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
37
38private:
39 // Connection / protocol
40 bool Handshake();
41 bool queryIdentity(std::string &out);
42 bool getPortMask(uint32_t &mask);
43 bool setPortMask(uint32_t mask);
44 bool sendCommand(const std::string &cmd, std::string &response);
45
46 bool setUSBPortEnabled(uint8_t port, bool enabled);
47 bool setAllPortsEnabled(bool enabled);
48 void updatePortsFromMask(uint32_t mask);
49
50 static constexpr const char CMD_GET_IDENTITY[] = "?Q";
51 static constexpr const char CMD_GET_MASK[] = "GP";
52 static constexpr const char CMD_SET_MASK[] = "SP";
53
54 // Protocol requires an 8-char password field. Factory default.
55 static constexpr const char DEFAULT_PASS8[] = "pass ";
56
57 static constexpr uint8_t USB_PORTS = 7;
58 static constexpr size_t ALIAS_MAX_LEN = 16;
59 static constexpr uint8_t STARTECH_TIMEOUT_SEC = 3;
60
61 // Switch item order: ON first, OFF second
62 enum { SW_ON = 0, SW_OFF = 1 };
63
64 // Properties
65 enum { INFO_IDENTITY, INFO_MASK, INFO_N };
66 INDI::PropertyText InfoTP {INFO_N};
67
68 enum { ALIAS_P1, ALIAS_P2, ALIAS_P3, ALIAS_P4, ALIAS_P5, ALIAS_P6, ALIAS_P7, ALIAS_N };
69 INDI::PropertyText PortAliasesTP {ALIAS_N};
70
71 std::array<INDI::PropertySwitch, USB_PORTS> USBPortSP {
75 };
76 INDI::PropertySwitch USBAllSP {2};
77
78 // Alias state
79 std::array<std::string, USB_PORTS> portAliases {};
80 std::array<std::string, USB_PORTS> committedAliases {};
81
82 void syncAliasesFromProperty(bool rewriteTruncated = true);
83 std::string sanitizeAlias(const std::string &in, bool &wasTruncated) const;
84 std::string defaultPortLabel(uint8_t port) const;
85
86 // Apply labels to USB properties and force clients to refresh labels
87 void applyPortLabelsAndRedefineUSBProperties();
88
89 // Serial
90 int PortFD {-1};
91 Connection::Serial *serialConnection {nullptr};
92
93 uint32_t currentMask {0xFFFFFFFF};
94};
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...
bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
const char * getDefaultName() override
virtual ~StarTechHub()=default
bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
ISState
Switch state.
Definition indiapi.h:148
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34
uint8_t cmd[4]
Definition pwc-ioctl.h:2