50 Device1TP[0].
fill(
"MAC",
"MAC Address",
"");
51 Device1TP[1].
fill(
"ALIAS",
"Alias",
"");
52 Device1TP[2].
fill(
"IP",
"IP Address",
"");
57 Device2TP[0].
fill(
"MAC",
"MAC Address",
"");
58 Device2TP[1].
fill(
"ALIAS",
"Alias",
"");
59 Device2TP[2].
fill(
"IP",
"IP Address",
"");
64 Device3TP[0].
fill(
"MAC",
"MAC Address",
"");
65 Device3TP[1].
fill(
"ALIAS",
"Alias",
"");
66 Device3TP[2].
fill(
"IP",
"IP Address",
"");
71 Device4TP[0].
fill(
"MAC",
"MAC Address",
"");
72 Device4TP[1].
fill(
"ALIAS",
"Alias",
"");
73 Device4TP[2].
fill(
"IP",
"IP Address",
"");
165 LOG_INFO(
"Wake On Lan driver connected.");
179 LOG_INFO(
"Wake On Lan driver disconnected. Ping monitoring stopped.");
189 checkPingStatus(0, Device1TP, Send1SP);
190 checkPingStatus(1, Device2TP, Send2SP);
191 checkPingStatus(2, Device3TP, Send3SP);
192 checkPingStatus(3, Device4TP, Send4SP);
197bool WakeOnLAN::pingDevice(
const char *ip)
199 std::string
cmd =
"ping -c1 -W1 " + std::string(ip) +
" > /dev/null 2>&1";
200 return system(
cmd.c_str()) == 0;
207 const char *ip = devTP[2].
getText();
208 if (!ip || strlen(ip) == 0)
211 const char *alias = devTP[1].
getText();
212 const char *label = (alias && strlen(alias) > 0) ? alias : devTP.getLabel();
216 LOGF_INFO(
"%s (%s) is online.", label, ip);
221 LOGF_INFO(
"%s (%s) is not reachable.", label, ip);
233 Device1TP.
update(texts, names, n);
239 const char *ip1 = Device1TP[2].
getText();
240 if (ip1 && strlen(ip1) > 0)
250 Device2TP.
update(texts, names, n);
256 const char *ip2 = Device2TP[2].
getText();
257 if (ip2 && strlen(ip2) > 0)
267 Device3TP.
update(texts, names, n);
273 const char *ip3 = Device3TP[2].
getText();
274 if (ip3 && strlen(ip3) > 0)
284 Device4TP.
update(texts, names, n);
290 const char *ip4 = Device4TP[2].
getText();
291 if (ip4 && strlen(ip4) > 0)
309 if (!sendSP.isNameMatch(name))
311 if (devTP[0].
getText() ==
nullptr || strlen(devTP[0].
getText()) == 0)
313 LOGF_ERROR(
"MAC address %d not configured.", num);
316 else if (sendWakeOnLan(devTP[0].
getText()))
319 const char *ip = devTP[2].
getText();
332 if (handleSend(Device1TP, Send1SP, 1))
return true;
333 if (handleSend(Device2TP, Send2SP, 2))
return true;
334 if (handleSend(Device3TP, Send3SP, 3))
return true;
335 if (handleSend(Device4TP, Send4SP, 4))
return true;
354bool WakeOnLAN::sendWakeOnLan(
const char *macAddress)
356 if (!macAddress || strlen(macAddress) == 0)
362 std::string
cmd =
"wakeonlan " + std::string(macAddress);
363 int ret = system(
cmd.c_str());
366 LOGF_INFO(
"Wake on LAN packet sent to %s", macAddress);
371 LOG_ERROR(
"WoL: wakeonlan tool not found. Please install it on your system.");
374 LOG_ERROR(
"WoL: wakeonlan failed to send the packet.");
const char * getDeviceName() const
INDI::PropertyText getText(const char *name) const
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual void setConnected(bool status, IPState state=IPS_OK, const char *msg=nullptr)
Set connection switch status in the client.
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
bool load()
load Attempt to load property values from configuration file.
void save(FILE *f) const
save Save property to configuration file.
void setLabel(const char *label)
bool isNameMatch(const char *otherName) const
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
bool update(const char *const texts[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
INDI::PropertyViewText * getText() const
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 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.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
#define LOGF_INFO(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
void setState(IPState state)
std::unique_ptr< WakeOnLAN > wakeonlan(new WakeOnLAN())