package Hardware::UPS::Perl::Driver::Megatec; #============================================================================== # package description: #============================================================================== # This package supplies a set of methods dealing with an UPS using the # Megatec protocol. This might serve as a template for other UPS drivers. For # a detailed description see the pod documentation included at the end of this # file. # # List of public methods: # ----------------------- # new - initializing an UPS object # setDebugLevel - setting the debug level # getDebugLevel - getting the debug level # setLogger - setting the current logger # getLogger - getting the current logger # getErrorMessage - getting the error message # connect - connecting to UPS # connected - connection status to UPS # disconnect - disconnecting from UPS # sendCommand - sending a command to the UPS # flush - flushing any buffered input # readUPSInfo - reading the UPS info # getManufacturer - getting the manufacturer of the UPS # getModel - getting the UPS model # getVersion - getting the UPS firmware version # printUPSInfo - printing the informations about the UPS # readRatingInfo - reading the UPS rating info # getRatingVoltage - getting the rating voltage # getRatingCurrent - getting the rating current # getRatingBatteryVoltage - getting the rating battery voltage # getRatingFrequency - getting the rating frequency # readStatus - reading the UPS status # getInputVoltage - getting the input voltage # getInputFaultVoltage - getting the input fault voltage # getOutputVoltage - getting the output voltage # getUPSLoad - getting the UPS load # getInputFrequency - getting the input frequency # getBatteryVoltage - getting the battery voltage # getUPSTemperature - getting the UPS temperature # getPowerStatus - getting the power status # getBatteryStatus - getting the battery status # getBypassStatus - getting the bypass status # getFailedStatus - getting the failed status # getStandbyStatus - getting the standby status # getTestStatus - getting the test status # getShutdownStatus - getting the shutdown status # getBeeperStatus - getting the beeper status # resetMinMax - resetting minima and maxima # printMinMax - getting minima and maxima # printData - printing comparison between firmware and status # printStatus - printing status flags # toggleBeeper - toggles the beeper state # testUPS - testing the UPS # testUPSBatteryLow - testing the UPS until battery low occurs # testUPSPeriod - testing the UPS for a period of time in minutes # cancelTest - cancel testing of the UPS # shutdownUPS - shutdown of the UPS # shutdownRestore - shutdown and restore of the UPS # cancelShutdown - cancel shutdown of the UPS # #============================================================================== #============================================================================== # Copyright: #============================================================================== # Copyright (c) 2007 Christian Reile, . All # rights reserved. This program is free software; you can redistribute it # and/or modify it under the same terms as Perl itself. #============================================================================== #============================================================================== # Entries for Revision Control: #============================================================================== # Revision : $Revision: 1.13 $ # Author : $Author: creile $ # Last Modified On: $Date: 2007/04/17 19:43:42 $ # Status : $State: Exp $ #------------------------------------------------------------------------------ # Modifications : #------------------------------------------------------------------------------ # # $Log: Megatec.pm,v $ # Revision 1.13 2007/04/17 19:43:42 creile # documentation bugfixes. # # Revision 1.12 2007/04/14 09:38:14 creile # documentation update. # # Revision 1.11 2007/04/07 15:21:40 creile # Megatec protocol completed (test, shutdown and # shutdown/restore of UPS); # adaptations to "best practices" style; # update of documentation. # # Revision 1.10 2007/03/13 17:15:14 creile # usage of Perl pragma constant for most of the package # variables; # options as anonymous hashes; # format directives revised; # reconnect fixed. # # Revision 1.9 2007/03/03 21:26:10 creile # "return undef" replaced by "return"; # adaptations to new Constants.pm; # formatted output of UPS information, status and data revised # using new logging method write(); # method getMinMax() replaced by printMinMax(). # # Revision 1.8 2007/02/25 17:06:26 creile # connection as option now; # option handling redesigned. # # Revision 1.7 2007/02/05 20:58:43 creile # initialization of logger in method() added; # pod documentation revised. # # Revision 1.6 2007/02/04 18:57:51 creile # bug fix of pod documentation. # # Revision 1.5 2007/02/04 14:11:03 creile # package renamed to Hardware::UPS::Perl::Driver::Megatec; # output of methods printData(), printStatus() and printUPSInfo() # revised; # logging support added; # update of documentation. # # Revision 1.4 2007/01/28 21:08:24 creile # call of method flush() removed from method sendCommand() to avoid deep recursion error; # flush() is called now, if sendCommand() was unsuccessful. # # Revision 1.3 2007/01/28 05:32:12 creile # renamed to Hardware::UPS::Perl::Megatec; # Exporter package removed; # network support added; # new methods setHost(), getHost(), setTCPPort(), getTCPPort() # added; # unnecessary comments removed; # update of pod documentation. # # Revision 1.2 2007/01/21 15:04:06 creile # some beautifications. # # Revision 1.1 2007/01/20 08:11:12 creile # initial revision # # #============================================================================== #============================================================================== # module preamble: #============================================================================== use strict; BEGIN { use vars qw($VERSION @ISA); $VERSION = sprintf( "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/ ); @ISA = qw(); } #============================================================================== # end of module preamble #============================================================================== #============================================================================== # packages required: #------------------------------------------------------------------------------ # # Hardware::UPS::Perl::Connection - importing Hardware::UPS::Perl connection # Hardware::UPS::Perl::Constants - importing Hardware::UPS::Perl constants # Hardware::UPS::Perl::Logging - importing Hardware::UPS::Perl methods # dealing with logfiles # Hardware::UPS::Perl::Utils - importing Hardware::UPS::Perl utility # functions for packages # #============================================================================== use Hardware::UPS::Perl::Connection; use Hardware::UPS::Perl::Constants qw( UPSSCRIPT ); use Hardware::UPS::Perl::Logging; use Hardware::UPS::Perl::Utils qw( error ); #============================================================================== # defining user invisible package constants and variables: #------------------------------------------------------------------------------ # # F_CMD_REPLY_SIZE - the reply length for the F command # I_CMD_REPLY_SIZE - the reply length for the I command # M_CMD_REPLY_SIZE - the reply length for the M command # Q1_CMD_REPLY_SIZE - the reply length for the Q1 command # # INPUT_VOLTAGE_MINIMUM_INIT - the initial minimum input voltage # INPUT_VOLTAGE_MAXIMUM_INIT - the initial maximum input voltage # INPUT_FREQUENCY_MINIMUM_INIT - the initial minimum input frequency # INPUT_FREQUENCY_MAXIMUM_INIT - the initial maximum input frequency # # $PRINT_UPS_INFO - the string declaring the format of # writing the UPS info to the log file # $PRINT_DATA - the string declaring the format of # writing the UPS data to the log file # $PRINT_STATUS - the string declaring the format of # writing the UPS status to the log file # #============================================================================== use constant F_CMD_REPLY_SIZE => 21; use constant I_CMD_REPLY_SIZE => 38; use constant M_CMD_REPLY_SIZE => 1; use constant Q1_CMD_REPLY_SIZE => 46; use constant INPUT_VOLTAGE_MINIMUM_INIT => 240; use constant INPUT_VOLTAGE_MAXIMUM_INIT => 210; use constant INPUT_FREQUENCY_MINIMUM_INIT => 55; use constant INPUT_FREQUENCY_MAXIMUM_INIT => 45; my $PRINT_UPS_INFO = <