Instrument Neutral Distributed Interface INDI 2.2.5
wake_on_lan.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2014 Jasem Mutlaq. All rights reserved.
3 Driver for Wake-on-LAN power control
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
22*******************************************************************************/
23
24#pragma once
25
26#include "defaultdevice.h"
27
29{
30 public:
31 WakeOnLAN();
32 virtual ~WakeOnLAN() = default;
33
34 const char *getDefaultName() override;
35 virtual bool initProperties() override;
36 virtual void ISGetProperties(const char *dev) override;
37 virtual bool updateProperties() override;
38
39 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
40 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
41 virtual bool saveConfigItems(FILE *fp) override;
42
43 protected:
44 bool Connect() override;
45 bool Disconnect() override;
46 void TimerHit() override;
47
48 private:
49 bool sendWakeOnLan(const char *macAddress);
50 bool pingDevice(const char *ip);
51 void checkPingStatus(int idx, INDI::PropertyText &devTP, INDI::PropertySwitch &sendSP);
52
53 bool m_stopPing { false };
54
55 // MAC Address properties for 4 devices (MAC + Alias + IP)
56 INDI::PropertyText Device1TP {3};
57 INDI::PropertyText Device2TP {3};
58 INDI::PropertyText Device3TP {3};
59 INDI::PropertyText Device4TP {3};
60
61 // Send buttons for each MAC address
62 INDI::PropertySwitch Send1SP {1};
63 INDI::PropertySwitch Send2SP {1};
64 INDI::PropertySwitch Send3SP {1};
65 INDI::PropertySwitch Send4SP {1};
66};
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual ~WakeOnLAN()=default
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
const char * getDefaultName() override
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
bool Disconnect() override
Disconnect from device.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
ISState
Switch state.
Definition indiapi.h:148