Split lpt functions into separate files
This commit is contained in:
parent
bc7929b67b
commit
447d6e59e0
@ -3,7 +3,7 @@ include_HEADERS = $(top_srcdir)/yasnd.h
|
||||
yasnd_LDADD = ${libconfuse_LIBS}
|
||||
yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la
|
||||
sbin_PROGRAMS = yasnd
|
||||
yasnd_SOURCES = yasnd.c yasnd-ipc.c
|
||||
yasnd_SOURCES = yasnd.c yasnd-ipc.c yasnd-lpt.c
|
||||
yasnd_CPPFLAGS = -I$(top_srcdir)
|
||||
|
||||
distclean-local:
|
||||
|
76
daemon/yasnd-lpt.c
Normal file
76
daemon/yasnd-lpt.c
Normal file
@ -0,0 +1,76 @@
|
||||
#include <sys/io.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool lpt_enable=false; // control usage of LPT port to reset target devices
|
||||
int lpt_port=0x378; // LPT port in hex(0x378 is usually LPT1)
|
||||
|
||||
/*
|
||||
Function, that turn off all LPT port pins.
|
||||
This is needed to unlock LPT control circuit, when
|
||||
management computer is just booted
|
||||
*/
|
||||
void lpt_init()
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: Unlocking the circuit fails due to LPT port access error");
|
||||
// disable LPT port usage
|
||||
lpt_enable=false;
|
||||
return;
|
||||
}
|
||||
// Unlock circuit
|
||||
outb (0, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn on first LPT port pin and turn off others.
|
||||
This is needed to lock LPT control circuit, when
|
||||
management computer is rebooted
|
||||
*/
|
||||
void lpt_lock_cond(bool ignore_options)
|
||||
{
|
||||
if (lpt_enable || ignore_options)
|
||||
{
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: Locking the circuit fails due to LPT port access error");
|
||||
// disable LPT port usage
|
||||
lpt_enable=false;
|
||||
return;
|
||||
}
|
||||
// Lock circuit
|
||||
outb (1, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn on only one LPT port pin, defined by it argument, wait a second,
|
||||
and turn off all pins. That is enough to reset specified host.
|
||||
*/
|
||||
void reset_pin(int pin_num)
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
if (pin_num==0)
|
||||
return; // there is no LPT control for target host
|
||||
if (pin_num<2 || pin_num>8)
|
||||
{
|
||||
log_event("Error: incorrent LPT pin number");
|
||||
return;
|
||||
}
|
||||
int pins = 1<<(pin_num-1);
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: LPT port access error");
|
||||
return;
|
||||
}
|
||||
// Reset host
|
||||
outb (pins, lpt_port);
|
||||
sleep(1);
|
||||
outb (0, lpt_port);
|
||||
}
|
||||
}
|
14
daemon/yasnd-lpt.h
Normal file
14
daemon/yasnd-lpt.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef YASND_LPT_H
|
||||
#define YASND_LPT_H
|
||||
|
||||
// External variables
|
||||
extern bool lpt_enable; // control usage of LPT port to reset target devices
|
||||
extern int lpt_port; // LPT port in hex(0x378 is usually LPT1)
|
||||
|
||||
// External functions
|
||||
extern void lpt_init();
|
||||
extern void lpt_lock_cond(bool ignore_options);
|
||||
extern void lpt_lock();
|
||||
extern void reset_pin(int pin_num);
|
||||
|
||||
#endif
|
@ -1,5 +1,4 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/io.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <syslog.h>
|
||||
@ -7,6 +6,7 @@
|
||||
#include <confuse.h>
|
||||
|
||||
#include "yasnd.h"
|
||||
#include "yasnd-lpt.h"
|
||||
|
||||
cfg_t *cfg; // pointer to configuration structure
|
||||
char pidfile[]="/var/run/yasnd.pid"; // pidfile path
|
||||
@ -18,8 +18,6 @@ char* phone_device=NULL; // phone device for gammu, for example: "/dev/ttyACM0"
|
||||
char* phone_model=NULL; // gammu phone model, for example: "at"
|
||||
char* phone_connection=NULL; // gammu phone connection type, for example: "at"
|
||||
char* recipient_number=NULL; // recipient of sms alerts
|
||||
bool lpt_enable=false; // control usage of LPT port to reset target devices
|
||||
int lpt_port=0x378; // LPT port in hex(0x378 is usually LPT1)
|
||||
bool loop_locked=false; // flag for locking main loop while config re-reading
|
||||
int failures_first=0; // count of failures while hosts checking, that triggers SMS sending
|
||||
int failures_second=0; // count of failures while hosts checking, that triggers host's reset
|
||||
@ -48,47 +46,6 @@ void* allocate_memory(int bytes)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn off all LPT port pins.
|
||||
This is needed to unlock LPT control circuit, when
|
||||
management computer is just booted
|
||||
*/
|
||||
void lpt_init()
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: Unlocking the circuit fails due to LPT port access error");
|
||||
// disable LPT port usage
|
||||
lpt_enable=false;
|
||||
return;
|
||||
}
|
||||
// Unlock circuit
|
||||
outb (0, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn on first LPT port pin and turn off others.
|
||||
This is needed to lock LPT control circuit, when
|
||||
management computer is rebooted
|
||||
*/
|
||||
void lpt_lock_cond(bool ignore_options)
|
||||
{
|
||||
if (lpt_enable || ignore_options)
|
||||
{
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: Locking the circuit fails due to LPT port access error");
|
||||
// disable LPT port usage
|
||||
lpt_enable=false;
|
||||
return;
|
||||
}
|
||||
// Lock circuit
|
||||
outb (1, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
// Previous function, but without ignoring lpt_enable option
|
||||
void lpt_lock()
|
||||
@ -236,34 +193,6 @@ void check_host(int num,host_decl* host)
|
||||
host->helper_pid=pid;
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn on only one LPT port pin, defined by it argument, wait a second,
|
||||
and turn off all pins. That is enough to reset specified host.
|
||||
*/
|
||||
void reset_pin(int pin_num)
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
if (pin_num==0)
|
||||
return; // there is no LPT control for target host
|
||||
if (pin_num<2 || pin_num>8)
|
||||
{
|
||||
log_event("Error: incorrent LPT pin number");
|
||||
return;
|
||||
}
|
||||
int pins = 1<<(pin_num-1);
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: LPT port access error");
|
||||
return;
|
||||
}
|
||||
// Reset host
|
||||
outb (pins, lpt_port);
|
||||
sleep(1);
|
||||
outb (0, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
int loop_function()
|
||||
{
|
||||
// set default signal handlers
|
||||
|
Loading…
Reference in New Issue
Block a user