Instrument Neutral Distributed Interface INDI
1.9.5
|
Go to the documentation of this file.
37 #define MAXINDIBUF 49152
40 #define snprintf _snprintf
42 #pragma warning(disable : 4996)
50 io.
write = [](
void *user,
const void * ptr,
size_t count) ->
size_t
53 return self->client_socket.write(
static_cast<const char *
>(ptr), count);
56 io.
vprintf = [](
void *user,
const char * format, va_list ap) ->
int
60 vsnprintf(message,
MAXRBUF, format, ap);
61 return self->client_socket.write(message, strlen(message));
71 connect(&client_socket, SIGNAL(readyRead()),
this, SLOT(listenINDI()));
72 connect(&client_socket, SIGNAL(error(QAbstractSocket::SocketError)),
this,
73 SLOT(processSocketError(QAbstractSocket::SocketError)));
81 void INDI::BaseClientQt::clear()
83 while (!cDevices.empty())
85 delete cDevices.back();
89 while (!blobModes.empty())
91 delete blobModes.back();
107 if (std::find(cDeviceNames.begin(), cDeviceNames.end(), deviceName) != cDeviceNames.end())
110 cDeviceNames.push_back(deviceName);
115 watchDevice(deviceName);
116 cWatchProperties[deviceName].insert(propertyName);
121 client_socket.connectToHost(cServer.c_str(), cPort);
123 if (client_socket.waitForConnected(timeout_sec * 1000) ==
false)
138 if (cDeviceNames.empty())
146 for (
const auto &oneDevice : cDeviceNames)
161 if (sConnected ==
false)
166 client_socket.close();
175 cDeviceNames.clear();
177 serverDisconnected(0);
184 setDriverConnection(
true, deviceName);
189 setDriverConnection(
false, deviceName);
192 void INDI::BaseClientQt::setDriverConnection(
bool status,
const char *deviceName)
199 IDLog(
"INDI::BaseClientQt: Error. Unable to find driver %s\n", deviceName);
205 if (drv_connection ==
nullptr)
212 if (drv_connection->
sp[0].s ==
ISS_ON)
220 sendNewSwitch(drv_connection);
225 if (drv_connection->
sp[1].s ==
ISS_ON)
233 sendNewSwitch(drv_connection);
239 for (
auto &dev : cDevices)
241 if (!strcmp(deviceName, dev->getDeviceName()))
253 void INDI::BaseClientQt::listenINDI()
262 if (sConnected ==
false)
265 while (client_socket.bytesAvailable() > 0)
276 fprintf(stderr,
"Bad XML from %s/%ud: %s\n%s\n", cServer.c_str(), cPort, errorMsg,
buffer);
281 XMLEle *root = nodes[inode];
287 if ((err_code = dispatchCommand(root, errorMsg)) < 0)
292 IDLog(
"Dispatch command error(%d): %s\n", err_code, errorMsg);
309 return messageCmd(root, errmsg);
310 else if (!strcmp(
tagXMLEle(root),
"delProperty"))
311 return delPropertyCmd(root, errmsg);
313 else if (!strcmp(
tagXMLEle(root),
"getProperties"))
320 strcpy(errmsg,
"No device available and none was created");
332 if (!strcmp(
tagXMLEle(root),
"defBLOBVector"))
334 else if (!strcmp(
tagXMLEle(root),
"setBLOBVector"))
342 if (cWatchProperties.size() > 0)
348 if (cWatchProperties.find(
device) == cWatchProperties.end() ||
354 if ((!strcmp(
tagXMLEle(root),
"defTextVector")) || (!strcmp(
tagXMLEle(root),
"defNumberVector")) ||
355 (!strcmp(
tagXMLEle(root),
"defSwitchVector")) || (!strcmp(
tagXMLEle(root),
"defLightVector")) ||
356 (!strcmp(
tagXMLEle(root),
"defBLOBVector")))
358 else if (!strcmp(
tagXMLEle(root),
"setTextVector") || !strcmp(
tagXMLEle(root),
"setNumberVector") ||
359 !strcmp(
tagXMLEle(root),
"setSwitchVector") || !strcmp(
tagXMLEle(root),
"setLightVector") ||
360 !strcmp(
tagXMLEle(root),
"setBLOBVector"))
377 dp = findDev(root, 0, errmsg);
389 if (rProp ==
nullptr)
391 snprintf(errmsg,
MAXRBUF,
"Cannot delete property %s as it is not defined yet. Check driver.",
valuXMLAtt(ap));
395 removeProperty(rProp);
407 std::vector<INDI::BaseDevice *>::iterator devicei;
409 for (devicei = cDevices.begin(); devicei != cDevices.end();)
411 if (!strcmp(devName, (*devicei)->getDeviceName()))
413 removeDevice(*devicei);
415 devicei = cDevices.erase(devicei);
422 snprintf(errmsg,
MAXRBUF,
"Device %s not found", devName);
428 std::vector<INDI::BaseDevice *>::const_iterator devicei;
430 for (devicei = cDevices.begin(); devicei != cDevices.end(); devicei++)
432 if (!strcmp(devName, (*devicei)->getDeviceName()))
436 snprintf(errmsg,
MAXRBUF,
"Device %s not found", devName);
452 strncpy(errmsg,
"Unable to find device attribute in XML element. Cannot add device.",
MAXRBUF);
461 cDevices.push_back(dp);
479 snprintf(errmsg,
MAXRBUF,
"No device attribute found in element %s",
tagXMLEle(root));
491 dp = findDev(dn, errmsg);
498 return (addDevice(root, errmsg));
500 snprintf(errmsg,
MAXRBUF,
"INDI: <%s> no such device %s",
tagXMLEle(root), dn);
519 IDLog(
"%s\n", message.c_str());
621 bp->name, bp->size, bp->bloblen, bp->blob, bp->format
630 blobName, blobSize, blobSize, blobBuffer, blobFormat
644 BLOBMode *bMode = findBLOBMode(std::string(dev), prop ? std::string(prop) : std::string());
646 if (bMode ==
nullptr)
648 BLOBMode *newMode =
new BLOBMode();
649 newMode->device = std::string(dev);
650 newMode->property = (prop ? std::string(prop) : std::string());
651 newMode->blobMode = blobH;
652 blobModes.push_back(newMode);
657 if (bMode->blobMode == blobH)
660 bMode->blobMode = blobH;
669 BLOBMode *bMode = findBLOBMode(dev, (prop ? std::string(prop) : std::string()));
672 bHandle = bMode->blobMode;
677 INDI::BaseClientQt::BLOBMode *INDI::BaseClientQt::findBLOBMode(
const std::string &
device,
const std::string &property)
679 for (
auto &blob : blobModes)
681 if (blob->device ==
device && blob->property == property)
688 void INDI::BaseClientQt::processSocketError(QAbstractSocket::SocketError socketError)
690 if (sConnected ==
false)
695 IDLog(
"Socket Error: %s\n", client_socket.errorString().toLatin1().constData());
696 fprintf(stderr,
"INDI server %s/%d disconnected.\n", cServer.c_str(), cPort);
698 client_socket.close();
700 serverDisconnected(-1);
707 if (
device->getDriverInterface() & driverInterface)
708 deviceList.push_back(
device);
711 return (deviceList.size() > 0);
719 #if defined(_MSC_VER)
void IUUserIOBLOBContextOne(const userio *io, void *user, const char *name, unsigned int size, unsigned int bloblen, const void *blob, const char *format)
INDI::PropertyView< IText > * getText(const char *name) const
LilXML * newLilXML()
Create a new lilxml parser.
void IUUserIOGetProperties(const userio *io, void *user, const char *dev, const char *name)
bool connectServer()
Connect to INDI server.
void disconnectDevice(const char *deviceName)
Disconnect INDI driver.
INDI::BaseDevice * findDev(const char *devName, char *errmsg)
Find and return a particular device.
INDI::BaseDevice * getDevice(const char *deviceName)
bool isServerConnected() const
void watchDevice(const char *deviceName)
Add a device to the watch list.
INDI::PropertyView< INumber > * getNumber(const char *name) const
const char * timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
BLOBHandling getBLOBMode(const char *dev, const char *prop=nullptr)
getBLOBMode Get Binary Large Object policy mode IF set previously by setBLOBMode
void watchProperty(const char *deviceName, const char *propertyName)
watchProperties Add a property to the watch list. When communicating with INDI server....
const char * getDeviceName() const
void setMediator(INDI::BaseMediator *mediator)
Set the driver's mediator to receive notification of news devices and updated property values.
int messageCmd(XMLEle *root, char *errmsg)
Class to provide basic client functionality based on Qt5 toolkit and is therefore suitable for cross-...
INDI::PropertyView< ISwitch > * getSwitch(const char *name) const
void IUUserIONewBLOBFinish(const userio *io, void *user)
void IUUserIONewNumber(const userio *io, void *user, const INumberVectorProperty *nvp)
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
void void void void void IDLog(const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(1
Function Drivers call to log a message locally.
Provides generic container for INDI properties.
const std::vector< INDI::BaseDevice * > & getDevices() const
Text vector property descriptor.
Property getProperty(const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
Return a property and its type given its name.
IText * IUFindText(const ITextVectorProperty *tvp, const char *name)
Find an IText member in a vector text property.
Number vector property descriptor.
BaseClientQt(QObject *parent=Q_NULLPTR)
void delLilXML(LilXML *lp)
Delete a lilxml parser.
void setDeviceName(const char *dev)
Set the device name.
void sendNewText(ITextVectorProperty *pp)
Send new Text command to server.
void IUUserIONewText(const userio *io, void *user, const ITextVectorProperty *tvp)
INDI::BaseDevice * addDevice(XMLEle *dep, char *errmsg)
Add a new device.
char * tagXMLEle(XMLEle *ep)
Return the tag of an XML element.
BLOBHandling
How drivers handle BLOBs incoming from snooping drivers.
void IUUserIONewSwitch(const userio *io, void *user, const ISwitchVectorProperty *svp)
void checkMessage(XMLEle *root)
void finishBlob()
Send closing tag for BLOB command to server.
int delPropertyCmd(XMLEle *root, char *errmsg)
Delete property command.
void sendNewSwitch(ISwitchVectorProperty *pp)
Send new Switch command to server.
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
void IUUserIOEnableBLOB(const userio *io, void *user, const char *dev, const char *name, BLOBHandling blobH)
int setValue(XMLEle *root, char *errmsg)
handle SetXXX commands from client
int removeProperty(const char *name, char *errmsg)
Remove a property.
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
XMLEle ** parseXMLChunk(LilXML *lp, char *buf, int size, char ynot[])
Process an XML chunk.
virtual void newUniversalMessage(std::string message)
newUniversalMessage Universal messages are sent from INDI server without a specific device....
char * valuXMLAtt(XMLAtt *ap)
Return the value of an XML attribute.
void sendOneBlob(IBLOB *bp)
Send ONE blob content to server. The BLOB data in raw binary format and will be converted to base64 a...
void setServer(const char *hostname, unsigned int port)
Set the server host name and port.
void prXMLEle(FILE *fp, XMLEle *ep, int level)
Print an XML element.
size_t(* write)(void *user, const void *ptr, size_t count)
const struct userio * userio_file()
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
void connectDevice(const char *deviceName)
Connect to INDI driver.
int buildProp(XMLEle *root, char *errmsg, bool isDynamic=false)
Build a property given the supplied XML element (defXXX)
bool disconnectServer()
Disconnect from INDI server.
void sendNewNumber(INumberVectorProperty *pp)
Send new Number command to server.
int deleteDevice(const char *devName, char *errmsg)
Remove device.
ISwitch * IUFindSwitch(const ISwitchVectorProperty *svp, const char *name)
Find an ISwitch member in a vector switch property.
int dispatchCommand(XMLEle *root, char *errmsg)
Dispatch command received from INDI server to respective devices handled by the client.
void startBlob(const char *devName, const char *propName, const char *timestamp)
Send opening tag for BLOB command to server.
const char * CONNECTION
Connect to and disconnect from device.
void IUUserIONewBLOBStart(const userio *io, void *user, const char *dev, const char *name, const char *timestamp)
@ INDI_PROPERTY_DUPLICATED
void delXMLEle(XMLEle *ep)
delXMLEle Delete XML element.
Class to provide basic INDI device functionality.
void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop=nullptr)
Set Binary Large Object policy mode.
One Blob (Binary Large Object) descriptor.
static void * listenHelper(void *context)
XMLAtt * findXMLAtt(XMLEle *ep, const char *name)
Find an XML attribute within an XML element.
int(* vprintf)(void *user, const char *format, va_list arg)
std::vector< uint8_t > buffer
Switch vector property descriptor.